Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzuaa
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzuaa
提交
8c7bb1c0
提交
8c7bb1c0
编写于
6月 12, 2020
作者:
laizhilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
qq授权登录:准备工作及代码
上级
7ba5ba76
变更
14
展开全部
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
1002 行增加
和
261 行删除
+1002
-261
login.less
app_web/src/components/login/login.less
+88
-94
login.vue
app_web/src/components/login/login.vue
+63
-50
qqLoginRedirect.less
app_web/src/components/login/qqLoginRedirect.less
+89
-0
qqLoginRedirect.vue
app_web/src/components/login/qqLoginRedirect.vue
+358
-0
register.less
app_web/src/components/login/register.less
+73
-94
register.vue
app_web/src/components/login/register.vue
+22
-9
index.d.ts
app_web/src/index.d.ts
+2
-1
index.ts
app_web/src/router/index.ts
+4
-0
template.html
app_web/src/template.html
+4
-0
DevBootSecurityConfig.java
...rc/main/java/cn/ibizlab/config/DevBootSecurityConfig.java
+1
-0
application-dev.yml
ibzuaa-boot/src/main/resources/application-dev.yml
+10
-0
UserRegisterService.java
...zlab/core/uaa/extensions/service/UserRegisterService.java
+77
-0
UserRegisterResource.java
.../cn/ibizlab/api/rest/extensions/UserRegisterResource.java
+54
-13
HttpUtils.java
...-util/src/main/java/cn/ibizlab/util/helper/HttpUtils.java
+157
-0
未找到文件。
app_web/src/components/login/login.less
浏览文件 @
8c7bb1c0
.login{
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
min-height: 100%;
background: #108cee;
> img{
width: 100vw;
height: 100vh;
.login {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
min-height: 100%;
background: #108cee;
> img {
width: 100vw;
height: 100vh;
}
&-con {
position: absolute;
left: 0;
right: 0;
top: 150px;
margin: auto;
width: 450px;
.ivu-card-head {
padding: 30px 6px;
border-bottom: 0px;
> p {
line-height: 24px;
height: 24px;
margin-bottom: -2px;
font-size: 24px;
color: #666666;
font-weight: 700;
}
}
&-header {
font-size: 16px;
font-weight: 300;
text-align: center;
padding: 30px 0;
}
&-con{
position: absolute;
left: 0;
right: 0;
top: 150px;
margin: auto;
width: 450px;
.ivu-card-head {
padding: 30px 6px;
border-bottom: 0px;
>p{
line-height: 20px;
font-size: 24px;
color: #666666;
font-weight: 700;
}
}
&-header{
font-size: 16px;
font-weight: 300;
text-align: center;
padding: 30px 0;
}
.form-con{
padding: 0px 20px 0px 20px;
>i-button{
width: 170px;
height: 40px;
}
}
.login-tip{
font-size: 10px;
text-align: center;
color: red;
height: 30px;
}
.form-con {
padding: 0px 20px 0px 20px;
> i-button {
width: 170px;
height: 40px;
}
}
}
}
.login_btn{
width: 175px;
height: 40px;
font-size: 18px;
font-family: MicrosoftYaHei;
.login_btn
{
width: 175px;
height: 40px;
font-size: 18px;
font-family: MicrosoftYaHei;
}
.login_register {
width: 175px;
height: 40px;
font-size: 18px;
font-family: MicrosoftYaHei;
float: right;
width: 175px;
height: 40px;
font-size: 18px;
font-family: MicrosoftYaHei;
float: right;
}
.form_tipinfo {
font-family: MicrosoftYaHei-Bold;
font-size: 14px;
font-weight: bold;
font-stretch: normal;
line-height: 24px;
letter-spacing: 0px;
color: #666666;
}
form_tipinfo_more {
font-family: MicrosoftYaHei;
font-size: 14px;
font-weight: normal;
letter-spacing: 0px;
color: #666666;
font-family: MicrosoftYaHei-Bold;
font-size: 14px;
font-weight: bold;
font-stretch: normal;
line-height: 24px;
letter-spacing: 0px;
color: #666666;
}
.log_footer {
display: block;
padding: 0 16px;
margin: 48px 0 24px;
text-align: center;
color: #212529;
display: block;
padding: 0 16px;
margin: 48px 0 24px;
text-align: center;
color: #212529;
}
.log_footer a {
color: white;
text-decoration: none;
color: white;
text-decoration: none;
}
.sign-btn {
display: inline-block;
cursor: pointer;
margin-left: 10px;
display: inline-block;
cursor: pointer;
}
.wx-svg-container,
.qq-svg-container {
display: inline-block;
width: 40px;
height: 40px;
line-height: 40px;
text-align: center;
padding-top: 1px;
border-radius: 4px;
margin-bottom: -20px;
margin-top: 10px;
}
\ No newline at end of file
display: inline-block;
width: 40px;
height: 40px;
line-height: 40px;
text-align: center;
padding-top: 1px;
border-radius: 4px;
margin: 10px 4px -20px 6px;
}
app_web/src/components/login/login.vue
浏览文件 @
8c7bb1c0
...
...
@@ -56,10 +56,6 @@
</form-item>
</i-form>
<p
class=
'login-tip'
>
{{
this
.
loginTip
}}
<!--
{{
this
.
$t
(
'components.login.tip'
)
}}
-->
</p>
</div>
</card>
<div
class=
"log_footer"
>
...
...
@@ -74,7 +70,6 @@
<
script
lang=
"ts"
>
import
{
Vue
,
Component
,
Watch
}
from
'vue-property-decorator'
;
import
{
Environment
}
from
'@/environments/environment'
;
//import Divider from "ibiz-vue-lib/lib/ibiz-vue-lib.common";
@
Component
({
components
:
{}
...
...
@@ -89,15 +84,6 @@
*/
public
form
:
any
=
{
loginname
:
'ibzadmin'
,
password
:
'123456'
};
/**
* 登录提示语
*/
public
loginTip
:
any
=
""
;
/**
* 按钮可点击
*/
public
canClick
:
any
=
true
;
/**
* 应用名称
...
...
@@ -141,7 +127,7 @@
}
public
mounted
()
{
this
.
getCookie
();
this
.
getCookie
(
"loginname"
);
}
/**
...
...
@@ -177,26 +163,23 @@
const
data
=
response
.
data
;
if
(
data
&&
data
.
token
)
{
localStorage
.
setItem
(
'token'
,
data
.
token
);
this
.
setCookie
(
'ibzuaa-token'
,
data
.
token
,
0
);
}
if
(
data
&&
data
.
user
)
{
localStorage
.
setItem
(
'user'
,
JSON
.
stringify
(
data
.
user
));
}
// 设置cookie,保存账号密码7天
this
.
setCookie
(
loginname
,
7
);
this
.
setCookie
(
"loginname"
,
loginname
,
7
);
// 跳转首页
const
url
:
any
=
this
.
$route
.
query
.
redirect
?
this
.
$route
.
query
.
redirect
:
'*'
;
this
.
$router
.
push
({
path
:
url
});
}
}).
catch
((
error
:
any
)
=>
{
// const loginfailed: any = this.$t('components.login.loginfailed');
// this.$Notice.error({ title: (this.$t('components.login.error') as any), desc: loginfailed });
// 登录提示
const
data
=
error
.
data
;
if
(
data
&&
data
.
message
)
{
this
.
loginTip
=
data
.
message
;
if
(
data
&&
data
.
detail
)
{
this
.
$Message
.
error
({
content
:
"登录失败,"
+
data
.
message
,
content
:
"登录失败,"
+
data
.
detail
,
duration
:
5
,
closable
:
true
});
...
...
@@ -220,34 +203,28 @@
}
/**
* 设置cookie,保存账号密码
* @param loginname
* @param password
*/
public
setCookie
(
loginname
:
any
,
exdays
:
any
)
{
// 获取时间
let
exdate
=
new
Date
();
// 保存的天数
exdate
.
setTime
(
exdate
.
getTime
()
+
24
*
60
*
60
*
1000
*
exdays
);
// 字符串拼接cookie
window
.
document
.
cookie
=
"loginname"
+
"="
+
loginname
+
";path=/;expires="
+
exdate
.
toUTCString
();
public
setCookie
(
name
:
any
,
value
:
any
,
day
:
any
)
{
if
(
day
!==
0
)
{
//当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除
var
curDate
=
new
Date
();
var
curTamp
=
curDate
.
getTime
();
var
curWeeHours
=
new
Date
(
curDate
.
toLocaleDateString
()).
getTime
()
-
1
;
var
passedTamp
=
curTamp
-
curWeeHours
;
var
leftTamp
=
24
*
60
*
60
*
1000
-
passedTamp
;
var
leftTime
=
new
Date
();
leftTime
.
setTime
(
leftTamp
+
curTamp
);
document
.
cookie
=
name
+
"="
+
escape
(
value
)
+
";expires="
+
leftTime
.
toUTCString
();
}
else
{
document
.
cookie
=
name
+
"="
+
escape
(
value
);
}
}
/**
* 获取cookie
*/
public
getCookie
()
{
if
(
document
.
cookie
.
length
>
0
)
{
var
arr
=
document
.
cookie
.
split
(
'; '
);
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
var
arr2
=
arr
[
i
].
split
(
'='
);
//判断查找相对应的值
if
(
arr2
[
0
]
==
'loginname'
)
{
this
.
form
.
loginname
=
arr2
[
1
];
}
}
}
public
getCookie
(
name
:
any
):
any
{
var
arr
;
var
reg
=
new
RegExp
(
"(^| )"
+
name
+
"=([^;]*)(;|$)"
);
if
(
arr
=
document
.
cookie
.
match
(
reg
))
return
unescape
(
arr
[
2
]);
else
return
null
;
}
/**
...
...
@@ -255,7 +232,22 @@
* @param thirdpart
*/
public
tencentHandleClick
(
thirdpart
:
any
)
{
this
.
$Message
.
warning
(
"qq授权登录暂未支持"
)
// window.QC.Login.showPopup({
// appId:"101884990",
// redirectURI:"http%3a%2f%2f127.0.0.1%3a8080%2f%23%2flogin" //登录成功后会自动跳往该地址
// });
var
_this
=
this
;
// // 网站应用appid
const
client_id
=
'101885024'
;
// 回调地址,即授权登录成功后跳转的地址(需要UrlEncode转码)
const
redirect_uri
=
'http%3a%2f%2f127.0.0.1%3a8080%2f%23%2flogin'
;
// 随机生成一段字符串,防止CSRF攻击的
const
state
=
Math
.
random
().
toString
(
36
).
substr
(
2
);
// this.$store.dispatch(state);
// // qq授权登录地址
const
url
=
'https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id='
+
client_id
+
'&redirect_uri='
+
redirect_uri
+
"&scope=get_user_info"
+
"&state="
+
state
;
// // 打开qq授权登录窗口,授权登录成功后会重定向到回调地址
this
.
openWindow
(
url
,
thirdpart
,
540
,
540
);
}
/**
...
...
@@ -263,9 +255,30 @@
* @param thirddpart
*/
public
wechatHandleClick
(
thirddpart
:
any
)
{
this
.
$Message
.
warning
(
"微信授权登录暂未支持"
)
this
.
$Message
.
warning
(
"微信授权登录暂未支持"
);
}
/**
* 打开一个新窗口
* @param url 链接地址
* @param title 窗口标题
* @param w 窗口宽度
* @param h 窗口高度
*/
public
openWindow
(
url
:
any
,
title
:
any
,
w
:
any
,
h
:
any
):
void
{
const
dualScreenLeft
=
window
.
screenLeft
;
const
dualScreenTop
=
window
.
screenTop
;
const
width
=
window
.
innerWidth
?
window
.
innerWidth
:
document
.
documentElement
.
clientWidth
?
document
.
documentElement
.
clientWidth
:
screen
.
width
;
const
height
=
window
.
innerHeight
?
window
.
innerHeight
:
document
.
documentElement
.
clientHeight
?
document
.
documentElement
.
clientHeight
:
screen
.
height
;
const
left
=
((
width
/
2
)
-
(
w
/
2
))
+
dualScreenLeft
;
const
top
=
((
height
/
2
)
-
(
h
/
2
))
+
dualScreenTop
;
const
newWindow
=
window
.
open
(
url
,
title
,
'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width='
+
w
+
', height='
+
h
+
', top='
+
top
+
', left='
+
left
);
if
(
window
.
focus
&&
newWindow
)
{
newWindow
.
focus
();
}
}
}
</
script
>
...
...
app_web/src/components/login/qqLoginRedirect.less
0 → 100644
浏览文件 @
8c7bb1c0
.login {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
min-height: 100%;
background: #108cee;
> img {
width: 100vw;
height: 100vh;
}
&-con {
position: absolute;
left: 0;
right: 0;
top: 150px;
margin: auto;
width: 450px;
.ivu-card-head {
padding: 30px 6px;
border-bottom: 0px;
> p {
line-height: 24px;
height: 24px;
margin-bottom: -2px;
font-size: 24px;
color: #666666;
font-weight: 700;
}
}
&-header {
font-size: 16px;
font-weight: 300;
text-align: center;
padding: 30px 0;
}
.form-con {
padding: 0px 20px 0px 20px;
> i-button {
width: 170px;
height: 40px;
}
}
}
}
.log_footer {
display: block;
padding: 0 16px;
margin: 48px 0 24px;
text-align: center;
color: #212529;
}
.log_footer a {
color: white;
text-decoration: none;
}
.goLogin {
float: right;
font-size: 16px;
margin-right: 30px;
text-decoration: underline;
}
.confirm_register {
height: 40px;
font-size: 18px;
font-family: MicrosoftYaHei;
}
.disabled {
background-color: #ddd;
border-color: #ddd;
color: #57a3f3;
cursor: not-allowed; // 鼠标变化
}
\ No newline at end of file
app_web/src/components/login/qqLoginRedirect.vue
0 → 100644
浏览文件 @
8c7bb1c0
此差异已折叠。
点击以展开。
app_web/src/components/login/register.less
浏览文件 @
8c7bb1c0
.login{
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
min-height: 100%;
background: #108cee;
> img{
width: 100vw;
height: 100vh;
.login {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
min-height: 100%;
background: #108cee;
> img {
width: 100vw;
height: 100vh;
}
&-con {
position: absolute;
left: 0;
right: 0;
top: 150px;
margin: auto;
width: 450px;
.ivu-card-head {
padding: 30px 6px;
border-bottom: 0px;
> p {
line-height: 24px;
height: 24px;
margin-bottom: -2px;
font-size: 24px;
color: #666666;
font-weight: 700;
}
}
&-con{
position: absolute;
left: 0;
right: 0;
top: 150px;
margin: auto;
width: 400px;
.ivu-card-head {
padding: 14px 6px;
>p{
line-height: 20px;
font-size: 14px;
color: #17233d;
font-weight: 700;
}
}
&-header{
font-size: 16px;
font-weight: 300;
text-align: center;
padding: 30px 0;
}
.form-con{
padding: 10px 0 0;
>i-button{
width: 170px;
height: 40px;
}
}
.login-tip{
font-size: 10px;
text-align: center;
color: red;
}
&-header {
font-size: 16px;
font-weight: 300;
text-align: center;
padding: 30px 0;
}
}
.goLogin{
float: right;
font-size:12px;
margin-right: 14px;
text-decoration: underline;
}
.form-con {
padding: 0px 20px 0px 20px;
.login_btn{
width: 175px;
height: 32px;
font-size: 14px;
font-family: MicrosoftYaHei;
}
.login_register {
width: 175px;
height: 32px;
font-size: 14px;
font-family: MicrosoftYaHei;
float: right;
> i-button {
width: 170px;
height: 40px;
}
}
}
}
.disabled{
background-color: #ddd;
border-color: #ddd;
color:#57a3f3;
cursor: not-allowed; // 鼠标变化
.log_footer {
display: block;
padding: 0 16px;
margin: 48px 0 24px;
text-align: center;
color: #212529;
}
.form_tipinfo {
font-family: MicrosoftYaHei-Bold;
font-size: 14px;
font-weight: bold;
font-stretch: normal;
line-height: 24px;
letter-spacing: 0px;
color: #666666;
.log_footer a {
color: white;
text-decoration: none;
}
form_tipinfo_more {
font-family: MicrosoftYaHei;
font-size: 14px;
font-weight: normal;
letter-spacing: 0px;
color: #666666;
.goLogin {
float: right;
font-size: 16px;
margin-right: 30px;
text-decoration: underline;
}
.log_footer {
display: block;
padding: 0 16px;
margin: 48px 0 24px;
text-align: center;
color: #212529;
.confirm_register {
height: 40px;
font-size: 18px;
font-family: MicrosoftYaHei;
}
.log_footer a {
color: white;
text-decoration: none;
.disabled {
background-color: #ddd;
border-color: #ddd;
color: #57a3f3;
cursor: not-allowed; // 鼠标变化
}
\ No newline at end of file
app_web/src/components/login/register.vue
浏览文件 @
8c7bb1c0
...
...
@@ -11,6 +11,7 @@
<i-form
ref=
'loginForm'
:rules=
"rules"
:model=
"form"
>
<form-item
prop=
'loginname'
>
<i-input
size=
'large'
prefix=
'ios-contact'
v-model
.
trim=
"form.loginname"
placeholder=
"用户名"
...
...
@@ -19,6 +20,7 @@
</form-item>
<form-item
prop=
'personname'
>
<i-input
size=
'large'
prefix=
'ios-person'
v-model
.
trim=
"form.personname"
placeholder=
"用户姓名"
...
...
@@ -27,6 +29,7 @@
</form-item>
<form-item
prop=
'password'
>
<i-input
size=
'large'
prefix=
'ios-key'
v-model
.
trim=
"form.password"
type=
'password'
...
...
@@ -36,6 +39,7 @@
</form-item>
<form-item
prop=
'confrimpassword'
>
<i-input
size=
'large'
prefix=
'ios-checkbox'
v-model
.
trim=
"form.confrimpassword"
type=
'password'
...
...
@@ -47,6 +51,7 @@
<i-button
@
click=
"handleRegister"
type=
'success'
class=
"confirm_register"
:class=
"
{disabled: !this.canClick}"
long>
{{
this
.
confirmRegBtnContent
}}
</i-button>
...
...
@@ -56,9 +61,8 @@
</div>
</card>
<div
class=
"log_footer"
>
<div
class=
"copyright"
>
Copyright © 2018
<a
href=
"http://www.ibizsys.net/ibizsys/channelview?channelId=ibizsys.about"
target=
"_blank"
>
埃毕致(上海)云计算科技
</a>
版权所有
<div
class=
"copyright"
>
<a
href=
"https://www.ibizlab.cn/"
target=
"_blank"
>
{{
appTitle
}}
is based on ibizlab .
</a>
</div>
</div>
</div>
...
...
@@ -140,6 +144,9 @@
}
};
// 注册方式
public
registerType
:
any
=
"commom"
;
/**
* 生命周期Create
*
...
...
@@ -174,6 +181,10 @@
* 注册处理
*/
public
handleRegister
():
void
{
if
(
this
.
canClick
!=
true
)
{
return
;
}
const
form
:
any
=
this
.
$refs
.
loginForm
;
let
validatestate
:
boolean
=
true
;
form
.
validate
((
valid
:
boolean
)
=>
{
...
...
@@ -182,15 +193,17 @@
if
(
!
validatestate
)
{
return
;
}
this
.
form
.
registerType
=
"commom"
;
const
post
:
Promise
<
any
>
=
this
.
$http
.
post
(
'/uaa/register'
,
this
.
form
,
true
);
var
param
:
any
=
this
.
form
;
param
.
registerType
=
this
.
registerType
;
const
post
:
Promise
<
any
>
=
this
.
$http
.
post
(
'/uaa/register'
,
param
,
true
);
post
.
then
((
response
:
any
)
=>
{
if
(
response
&&
response
.
status
===
200
)
{
const
data
=
response
.
data
;
if
(
data
&&
data
.
ibzuser
)
{
this
.
$Message
.
success
({
content
:
"注册成功,用户名:"
+
data
.
ibzuser
.
loginname
+
",密码:"
+
data
.
ibzuser
.
password
,
duration
:
5
,
duration
:
3
,
closable
:
true
});
}
else
{
...
...
@@ -257,16 +270,16 @@
}
}).
catch
((
error
:
any
)
=>
{
const
data
=
error
.
data
;
if
(
data
&&
data
.
message
)
{
if
(
data
&&
data
.
detail
)
{
this
.
$Message
.
error
({
content
:
"登录失败,"
+
data
.
detail
,
duration
:
5
,
duration
:
3
,
closable
:
true
});
}
else
{
this
.
$Message
.
error
({
content
:
"登录失败"
,
duration
:
5
,
duration
:
3
,
closable
:
true
});
}
...
...
app_web/src/index.d.ts
浏览文件 @
8c7bb1c0
...
...
@@ -8,6 +8,7 @@ declare global {
uiServiceRegister
:
UIServiceRegister
,
utilServiceRegister
:
UtilServiceRegister
,
entityServiceRegister
:
EntityServiceRegister
,
counterServiceRegister
:
CounterServiceRegister
counterServiceRegister
:
CounterServiceRegister
,
QC
:
any
}
}
\ No newline at end of file
app_web/src/router/index.ts
浏览文件 @
8c7bb1c0
...
...
@@ -3,6 +3,10 @@ export const globalRoutes:Array<any> = [
{
path
:
'/register'
,
component
:
()
=>
import
(
'@components/login/register.vue'
)
},
{
path
:
'/qqLoginRedirect'
,
component
:
()
=>
import
(
'@components/login/qqLoginRedirect.vue'
)
}
];
//用户自定义首页路由
...
...
app_web/src/template.html
浏览文件 @
8c7bb1c0
...
...
@@ -6,6 +6,10 @@
<meta
name=
"viewport"
content=
"width=device-width,initial-scale=1.0"
>
<link
rel=
"icon"
href=
"<%= BASE_URL %>favicon.ico"
>
<title><
%=
htmlWebpackPlugin
.
options
.
title
%
></title>
<script
type=
"text/javascript"
src=
"http://qzonestyle.gtimg.cn/qzone/openapi/qc_loader.js"
data-callback=
"true"
data-appid=
"101885024"
data-redirecturi=
"http%3a%2f%2f127.0.0.1%3a8080%2f%23%2flogin"
charset=
"utf-8"
>
</script>
</head>
<body>
<noscript>
...
...
ibzuaa-boot/src/main/java/cn/ibizlab/config/DevBootSecurityConfig.java
浏览文件 @
8c7bb1c0
...
...
@@ -106,6 +106,7 @@ public class DevBootSecurityConfig extends WebSecurityConfigurerAdapter {
.
antMatchers
(
"/syspssystems/save"
).
permitAll
()
.
antMatchers
(
"/uaa/login"
).
permitAll
()
.
antMatchers
(
"/uaa/register"
).
permitAll
()
.
antMatchers
(
"/uaa/queryUserByOpenId"
).
permitAll
()
.
anyRequest
().
authenticated
()
// 防止iframe 造成跨域
.
and
().
headers
().
frameOptions
().
disable
();
...
...
ibzuaa-boot/src/main/resources/application-dev.yml
浏览文件 @
8c7bb1c0
server
:
port
:
8080
qqconnection
:
app_ID
:
101880571
app_KEY
:
d52af9b56e62d771ddde749a6ee0a4f9
redirect_URI
:
http://127.0.0.1:8111/#/qqLoginRedirect
scope
:
get_user_info,add_topic,add_one_blog,add_album,upload_pic,list_album,add_share,check_page_fans,add_t,add_pic_t,del_t,get_repost_list,get_info,get_other_info,get_fanslist,get_idollist,add_idol,del_ido,get_tenpay_addr
baseURL
:
https://graph.qq.com/
getUserInfoURL
:
https://graph.qq.com/user/get_user_info
accessTokenURL
:
https://graph.qq.com/oauth2.0/token
authorizeURL
:
https://graph.qq.com/oauth2.0/authorize
getOpenIDURL
:
https://graph.qq.com/oauth2.0/me
\ No newline at end of file
ibzuaa-core/src/main/java/cn/ibizlab/core/uaa/extensions/service/UserRegisterService.java
浏览文件 @
8c7bb1c0
package
cn
.
ibizlab
.
core
.
uaa
.
extensions
.
service
;
import
cn.ibizlab.util.domain.IBZUSER
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.helper.HttpUtils
;
import
cn.ibizlab.util.service.IBZUSERService
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
/**
* 实体[IBZUSER] 用户注册接口实现
*/
...
...
@@ -16,6 +23,10 @@ public class UserRegisterService{
@Autowired
private
IBZUSERService
ibzuserService
;
@Value
(
"${qqconnection.app_ID}"
)
private
String
app_ID
;
@Value
(
"${qqconnection.getUserInfoURL}"
)
private
String
getUserInfoURL
;
/**
* 普通注册
...
...
@@ -31,4 +42,70 @@ public class UserRegisterService{
return
ibzuser
;
}
/**
* qq授权注册并登录
* @param ibzuser 注册用户
* @param qqAuthorizationInfo qq授权信息
*/
public
IBZUSER
qqRegisterAndLogin
(
IBZUSER
ibzuser
,
JSONObject
qqAuthorizationInfo
)
{
// 1.根据qqAuthorizationInfo获取AccessToken
String
code
=
qqAuthorizationInfo
.
getString
(
"code"
);
String
state
=
qqAuthorizationInfo
.
getString
(
"state"
);
String
redirect_uri
=
""
;
String
appid
=
""
;
String
appkey
=
""
;
String
url
=
"https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id="
+
appid
+
"&client_secret="
+
appkey
+
"&code="
+
code
+
"&redirect_uri="
+
redirect_uri
;
// 2.根据AccessToken获取OpenID值
// 3.根据OpenID获取该QQ用户的相关信息
// 4.创建ibzuser,成功则登录
boolean
flag
=
ibzuserService
.
save
(
ibzuser
);
if
(!
flag
)
{
return
null
;
}
return
ibzuser
;
}
/**
* qq授权注册
* @param ibzuser
* @param openId 用户身份的唯一标识
* @param accessToken 当前用户在此网站/应用的登录状态与授权信息
*/
public
IBZUSER
qqRegister
(
IBZUSER
ibzuser
,
String
openId
,
String
accessToken
)
{
// 根据OpenID获取该QQ用户的相关信息
try
{
// 请求参数进行URL编码
String
openIdEncode
=
URLEncoder
.
encode
(
openId
,
"UTF-8"
);
String
accessTokenEncode
=
URLEncoder
.
encode
(
accessToken
,
"UTF-8"
);
String
url
=
getUserInfoURL
;
JSONObject
getParamMap
=
new
JSONObject
();
getParamMap
.
put
(
"access_token"
,
accessToken
);
getParamMap
.
put
(
"oauth_consumer_key"
,
app_ID
);
getParamMap
.
put
(
"openid"
,
openId
);
getParamMap
.
put
(
"format"
,
"json"
);
// 将参数进行urlencode编码并发送get请求
String
responseStr
=
HttpUtils
.
get
(
url
,
null
,
getParamMap
);
JSONObject
responseObj
=
JSONObject
.
parseObject
(
responseStr
);
// 获取qq用户信息成功
if
(
responseObj
.
getInteger
(
"ret"
)==
0
)
{
ibzuser
.
setUsername
(
responseObj
.
getString
(
"nickname"
));
}
else
{
throw
new
BadRequestAlertException
(
responseObj
.
getString
(
"msg"
),
""
,
""
);
}
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
BadRequestAlertException
(
"获取QQ用户相关信息失败!"
,
"UserRegisterService-qqRegister"
,
""
);
}
// 保存qq授权用户的唯一标识
ibzuser
.
setAvatar
(
openId
);
// 创建ibzuser,注册
boolean
flag
=
ibzuserService
.
save
(
ibzuser
);
if
(
flag
)
{
return
ibzuser
;
}
return
null
;
}
}
\ No newline at end of file
ibzuaa-provider/ibzuaa-provider-api/src/main/java/cn/ibizlab/api/rest/extensions/UserRegisterResource.java
浏览文件 @
8c7bb1c0
...
...
@@ -6,6 +6,7 @@ import cn.ibizlab.util.domain.IBZUSER;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -26,31 +27,33 @@ public class UserRegisterResource {
@Autowired
private
ISysPSSystemService
iSysPSSystemService
;
@Value
(
"${qqconnection.redirect_URI}"
)
private
String
redirect_URI
;
@PostMapping
(
value
=
"/uaa/register"
)
public
ResponseEntity
<
JSONObject
>
register
(
@RequestBody
JSONObject
param
)
{
JSONObject
object
=
new
JSONObject
();
// 空校验
String
loginname
=
param
.
getString
(
"loginname"
);
if
(
StringUtils
.
isEmpty
(
loginname
))
throw
new
BadRequestAlertException
(
"用户名为空"
,
"register"
,
""
);
String
personname
=
param
.
getString
(
"personname"
);
if
(
StringUtils
.
isEmpty
(
personname
))
throw
new
BadRequestAlertException
(
"用户姓名为空"
,
"register"
,
""
);
String
password
=
param
.
getString
(
"password"
);
if
(
StringUtils
.
isEmpty
(
password
))
throw
new
BadRequestAlertException
(
"密码为空"
,
"register"
,
""
);
String
registerType
=
param
.
getString
(
"registerType"
);
if
(
StringUtils
.
isEmpty
(
loginname
))
throw
new
BadRequestAlertException
(
"用户名为空"
,
"register"
,
""
);
if
(
StringUtils
.
isEmpty
(
personname
))
throw
new
BadRequestAlertException
(
"用户姓名为空"
,
"register"
,
""
);
if
(
StringUtils
.
isEmpty
(
password
))
throw
new
BadRequestAlertException
(
"密码为空"
,
"register"
,
""
);
if
(
StringUtils
.
isEmpty
(
registerType
))
throw
new
BadRequestAlertException
(
"注册方式为空"
,
"register"
,
""
);
throw
new
BadRequestAlertException
(
"注册方式为空"
,
"register"
,
""
);
// 检查用户名是否已被注册
String
sql
=
"select loginname from ibzuser where loginname=#{et.loginname}"
;
Map
<
String
,
Object
>
sqlParam
=
new
HashMap
<>();
sqlParam
.
put
(
"loginname"
,
loginname
);
Map
<
String
,
Object
>
sqlParam
=
new
HashMap
<>();
sqlParam
.
put
(
"loginname"
,
loginname
);
List
<
JSONObject
>
select
=
iSysPSSystemService
.
select
(
sql
,
sqlParam
);
if
(
select
.
size
()
>
0
)
throw
new
BadRequestAlertException
(
"该用户名已被注册"
,
"register"
,
""
);
throw
new
BadRequestAlertException
(
"该用户名已被注册"
,
"register"
,
""
);
// 注册
IBZUSER
ibzuser
=
new
IBZUSER
();
...
...
@@ -63,12 +66,50 @@ public class UserRegisterResource {
ibzuser
.
setUserid
(
"commom-"
+
uuid
);
userRegisterService
.
commomRegister
(
ibzuser
);
break
;
case
"qq"
:
// qq授权注册
ibzuser
.
setUserid
(
"qq-"
+
uuid
);
String
openId
=
param
.
getString
(
"openId"
);
String
accessToken
=
param
.
getString
(
"accessToken"
);
userRegisterService
.
qqRegister
(
ibzuser
,
openId
,
accessToken
);
// JSONObject qqAuthorizationInfo = (JSONObject) param.get("qqAuthorizationInfo");
// userRegisterService.qqRegisterAndLogin(ibzuser, qqAuthorizationInfo);
break
;
default
:
ibzuser
.
setUserid
(
"commom-"
+
uuid
);
userRegisterService
.
commomRegister
(
ibzuser
);
break
;
}
object
.
put
(
"ibzuser"
,
ibzuser
);
return
ResponseEntity
.
ok
().
body
(
object
);
object
.
put
(
"ibzuser"
,
ibzuser
);
return
ResponseEntity
.
ok
().
body
(
object
);
}
/**
* 根据openId查用户
* @param param
* @return
*/
@PostMapping
(
value
=
"/uaa/queryUserByOpenId"
)
public
ResponseEntity
<
JSONObject
>
queryUserByOpenId
(
@RequestBody
JSONObject
param
)
{
JSONObject
object
=
new
JSONObject
();
// 空校验
String
openId
=
param
.
getString
(
"openId"
);
if
(
StringUtils
.
isEmpty
(
openId
))
throw
new
BadRequestAlertException
(
"openId为空"
,
"queryUserByOpenId"
,
""
);
// 根据openid查用户
String
sql
=
"select * from ibzuser where avatar=#{et.avatar}"
;
Map
<
String
,
Object
>
sqlParam
=
new
HashMap
<>();
sqlParam
.
put
(
"avatar"
,
openId
);
List
<
JSONObject
>
select
=
iSysPSSystemService
.
select
(
sql
,
sqlParam
);
if
(
select
.
size
()
>
0
)
{
// 将查询到的ibzuser对象返回
IBZUSER
ibzuser
=
select
.
get
(
0
).
toJavaObject
(
IBZUSER
.
class
);
object
.
put
(
"ibzuser"
,
ibzuser
);
}
return
ResponseEntity
.
ok
().
body
(
object
);
}
}
ibzuaa-util/src/main/java/cn/ibizlab/util/helper/HttpUtils.java
0 → 100644
浏览文件 @
8c7bb1c0
package
cn
.
ibizlab
.
util
.
helper
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.core.io.Resource
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.StringHttpMessageConverter
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.nio.charset.Charset
;
/**
* 请求工具类
*/
public
class
HttpUtils
{
private
final
static
String
DEFAULT_ENCODING
=
"UTF-8"
;
/**
* Post请求
*
* @return
*/
public
static
String
post
(
String
url
)
{
return
post
(
url
,
null
,
null
);
}
/**
*Post请求
* @param
* @return
*/
public
static
String
post
(
String
url
,
JSONObject
headerMap
,
JSONObject
paramMap
)
{
return
doRestRequest
(
url
,
HttpMethod
.
POST
,
headerMap
,
paramMap
);
}
/**
*put请求
* @param
* @return
*/
public
static
String
put
(
String
url
,
JSONObject
headerMap
,
JSONObject
paramMap
)
{
return
doRestRequest
(
url
,
HttpMethod
.
PUT
,
headerMap
,
paramMap
);
}
/**
* GET请求
*
* @param
* @return
*/
public
static
String
get
(
String
url
)
throws
UnsupportedEncodingException
{
return
get
(
url
,
null
,
null
);
}
/**
* GET请求
*
* @param
* @param
* @return
*/
public
static
String
get
(
String
url
,
JSONObject
headerMap
,
JSONObject
paramMap
)
throws
UnsupportedEncodingException
{
if
(
paramMap
!=
null
){
boolean
flag
=
true
;
for
(
String
key
:
paramMap
.
keySet
()){
if
(
flag
){
url
+=
"?"
;
}
else
{
url
+=
"&"
;
}
flag
=
false
;
url
=
url
+
key
+
"="
+
URLEncoder
.
encode
(
paramMap
.
getString
(
key
),
DEFAULT_ENCODING
);
}
}
return
doRestRequest
(
url
,
HttpMethod
.
GET
,
headerMap
,
paramMap
);
}
/**
* DELETE请求
*
* @param
* @return
*/
public
static
String
delete
(
String
url
)
{
return
delete
(
url
,
null
,
null
);
}
/**
* DELETE请求
*
* @param
* @param
* @return
*/
public
static
String
delete
(
String
url
,
JSONObject
headerMap
,
JSONObject
paramMap
)
{
return
doRestRequest
(
url
,
HttpMethod
.
DELETE
,
headerMap
,
paramMap
);
}
public
static
String
doRestRequest
(
String
url
,
HttpMethod
method
,
JSONObject
headerMap
,
JSONObject
paramMap
){
RestTemplate
restTemplate
=
getRestTemplate
();
HttpHeaders
headers
=
new
HttpHeaders
();
if
(
headerMap
!=
null
){
for
(
String
key
:
headerMap
.
keySet
()){
headers
.
add
(
key
,
headerMap
.
getString
(
key
));
}
}
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<
String
,
String
>();
HttpEntity
<
String
>
entity
;
if
(
paramMap
!=
null
){
entity
=
new
HttpEntity
<>(
paramMap
.
toString
(),
headers
);
}
else
{
entity
=
new
HttpEntity
<>(
null
,
headers
);
}
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
exchange
(
url
,
method
,
entity
,
String
.
class
);
return
responseEntity
.
getBody
();
}
public
static
InputStream
requestInputStream
(
String
url
,
JSONObject
headerMap
,
JSONObject
paramMap
)
throws
IOException
{
RestTemplate
restTemplate
=
getRestTemplate
();
HttpHeaders
headers
=
new
HttpHeaders
();
if
(
headerMap
!=
null
){
for
(
String
key
:
headerMap
.
keySet
()){
headers
.
add
(
key
,
headerMap
.
getString
(
key
));
}
}
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<
String
,
String
>();
HttpEntity
<
String
>
entity
;
if
(
paramMap
!=
null
){
entity
=
new
HttpEntity
<>(
paramMap
.
toString
(),
headers
);
}
else
{
entity
=
new
HttpEntity
<>(
null
,
headers
);
}
ResponseEntity
<
Resource
>
responseEntity
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
entity
,
Resource
.
class
);
return
responseEntity
.
getBody
().
getInputStream
();
}
public
static
RestTemplate
getRestTemplate
(){
RestTemplate
restTemplate
=
new
RestTemplate
();
for
(
HttpMessageConverter
<?>
httpMessageConverter
:
restTemplate
.
getMessageConverters
())
{
if
(
httpMessageConverter
instanceof
StringHttpMessageConverter
)
{
((
StringHttpMessageConverter
)
httpMessageConverter
).
setDefaultCharset
(
Charset
.
forName
(
"UTF-8"
));
break
;
}
}
return
restTemplate
;
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录