Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
e96b8d87
Commit
e96b8d87
authored
Jun 11, 2019
by
fengshuonan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新oauth2的头像
parent
24c71d02
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
71 additions
and
13 deletions
+71
-13
guns-base-third-login/src/main/java/cn/stylefeng/guns/oauth/modular/controller/OAuthController.java
+22
-1
guns-base-third-login/src/main/java/cn/stylefeng/guns/oauth/modular/factory/OAuthUserInfoFactory.java
+2
-1
guns-base-third-login/src/main/java/cn/stylefeng/guns/oauth/modular/service/OauthUserInfoService.java
+8
-1
guns-base-third-login/src/main/java/cn/stylefeng/guns/oauth/modular/service/impl/OauthUserInfoServiceImpl.java
+15
-8
guns-sys/src/main/java/cn/stylefeng/guns/sys/core/constant/Const.java
+6
-0
guns-sys/src/main/java/cn/stylefeng/guns/sys/core/shiro/ShiroKit.java
+12
-1
guns-sys/src/main/java/cn/stylefeng/guns/sys/core/util/DefaultImages.java
+6
-1
No files found.
guns-base-third-login/src/main/java/cn/stylefeng/guns/oauth/modular/controller/OAuthController.java
View file @
e96b8d87
package
cn
.
stylefeng
.
guns
.
oauth
.
modular
.
controller
;
package
cn
.
stylefeng
.
guns
.
oauth
.
modular
.
controller
;
import
cn.stylefeng.guns.oauth.modular.service.LoginService
;
import
cn.stylefeng.guns.oauth.modular.service.LoginService
;
import
cn.stylefeng.guns.oauth.modular.service.OauthUserInfoService
;
import
cn.stylefeng.guns.sys.core.shiro.ShiroKit
;
import
cn.stylefeng.roses.core.base.controller.BaseController
;
import
cn.stylefeng.roses.core.base.controller.BaseController
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhyd.oauth.model.AuthResponse
;
import
me.zhyd.oauth.model.AuthResponse
;
...
@@ -32,9 +34,11 @@ public class OAuthController extends BaseController {
...
@@ -32,9 +34,11 @@ public class OAuthController extends BaseController {
@Autowired
@Autowired
private
LoginService
loginService
;
private
LoginService
loginService
;
@Autowired
private
OauthUserInfoService
oauthUserInfoService
;
/**
/**
* 第三方登录跳转
* 第三方登录跳转
* njui7crdxe
*
*
* @author fengshuonan
* @author fengshuonan
* @Date 2019/6/9 16:44
* @Date 2019/6/9 16:44
...
@@ -67,4 +71,21 @@ public class OAuthController extends BaseController {
...
@@ -67,4 +71,21 @@ public class OAuthController extends BaseController {
return
"redirect:/"
;
return
"redirect:/"
;
}
}
/**
* 第三方登录的头像
*
* @author fengshuonan
* @Date 2019/6/9 16:44
*/
@RequestMapping
(
"/avatar"
)
public
String
avatar
()
{
Long
userId
=
ShiroKit
.
getUserNotNull
().
getId
();
//获取第三方登录用户的头像
String
avatarUrl
=
oauthUserInfoService
.
getAvatarUrl
(
userId
);
return
REDIRECT
+
avatarUrl
;
}
}
}
guns-base-third-login/src/main/java/cn/stylefeng/guns/oauth/modular/factory/OAuthUserInfoFactory.java
View file @
e96b8d87
package
cn
.
stylefeng
.
guns
.
oauth
.
modular
.
factory
;
package
cn
.
stylefeng
.
guns
.
oauth
.
modular
.
factory
;
import
cn.stylefeng.guns.oauth.modular.entity.OauthUserInfo
;
import
cn.stylefeng.guns.oauth.modular.entity.OauthUserInfo
;
import
cn.stylefeng.guns.sys.core.constant.Const
;
import
cn.stylefeng.guns.sys.core.constant.state.ManagerStatus
;
import
cn.stylefeng.guns.sys.core.constant.state.ManagerStatus
;
import
cn.stylefeng.guns.sys.core.shiro.ShiroKit
;
import
cn.stylefeng.guns.sys.core.shiro.ShiroKit
;
import
cn.stylefeng.guns.sys.modular.system.entity.User
;
import
cn.stylefeng.guns.sys.modular.system.entity.User
;
...
@@ -56,7 +57,7 @@ public class OAuthUserInfoFactory {
...
@@ -56,7 +57,7 @@ public class OAuthUserInfoFactory {
systemUser
.
setSalt
(
salt
);
systemUser
.
setSalt
(
salt
);
//利用openId设置账号
//利用openId设置账号
systemUser
.
setAccount
(
"oauth2
_"
+
authUser
.
getSource
().
name
()
+
"_"
+
authUser
.
getUsername
());
systemUser
.
setAccount
(
Const
.
OAUTH2_ACCOUNT_PREFIX
+
"
_"
+
authUser
.
getSource
().
name
()
+
"_"
+
authUser
.
getUsername
());
systemUser
.
setName
(
authUser
.
getNickname
());
systemUser
.
setName
(
authUser
.
getNickname
());
systemUser
.
setBirthday
(
new
Date
());
systemUser
.
setBirthday
(
new
Date
());
systemUser
.
setSex
(
AuthUserGender
.
MALE
.
equals
(
authUser
.
getGender
())
?
"M"
:
"F"
);
systemUser
.
setSex
(
AuthUserGender
.
MALE
.
equals
(
authUser
.
getGender
())
?
"M"
:
"F"
);
...
...
guns-base-third-login/src/main/java/cn/stylefeng/guns/oauth/modular/service/OauthUserInfoService.java
View file @
e96b8d87
...
@@ -64,6 +64,13 @@ public interface OauthUserInfoService extends IService<OauthUserInfo> {
...
@@ -64,6 +64,13 @@ public interface OauthUserInfoService extends IService<OauthUserInfo> {
* @author stylefeng
* @author stylefeng
* @Date 2019-06-09
* @Date 2019-06-09
*/
*/
LayuiPageInfo
findPageBySpec
(
OauthUserInfoParam
param
);
LayuiPageInfo
findPageBySpec
(
OauthUserInfoParam
param
);
/**
* 获取用户头像地址
*
* @author fengshuonan
* @Date 2019-06-11 13:25
*/
String
getAvatarUrl
(
Long
userId
);
}
}
guns-base-third-login/src/main/java/cn/stylefeng/guns/oauth/modular/service/impl/OauthUserInfoServiceImpl.java
View file @
e96b8d87
...
@@ -6,8 +6,9 @@ import cn.stylefeng.guns.oauth.modular.entity.OauthUserInfo;
...
@@ -6,8 +6,9 @@ import cn.stylefeng.guns.oauth.modular.entity.OauthUserInfo;
import
cn.stylefeng.guns.oauth.modular.mapper.OauthUserInfoMapper
;
import
cn.stylefeng.guns.oauth.modular.mapper.OauthUserInfoMapper
;
import
cn.stylefeng.guns.oauth.modular.model.params.OauthUserInfoParam
;
import
cn.stylefeng.guns.oauth.modular.model.params.OauthUserInfoParam
;
import
cn.stylefeng.guns.oauth.modular.model.result.OauthUserInfoResult
;
import
cn.stylefeng.guns.oauth.modular.model.result.OauthUserInfoResult
;
import
cn.stylefeng.guns.oauth.modular.service.OauthUserInfoService
;
import
cn.stylefeng.guns.oauth.modular.service.OauthUserInfoService
;
import
cn.stylefeng.roses.core.util.ToolUtil
;
import
cn.stylefeng.roses.core.util.ToolUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
...
@@ -28,18 +29,18 @@ import java.util.List;
...
@@ -28,18 +29,18 @@ import java.util.List;
public
class
OauthUserInfoServiceImpl
extends
ServiceImpl
<
OauthUserInfoMapper
,
OauthUserInfo
>
implements
OauthUserInfoService
{
public
class
OauthUserInfoServiceImpl
extends
ServiceImpl
<
OauthUserInfoMapper
,
OauthUserInfo
>
implements
OauthUserInfoService
{
@Override
@Override
public
void
add
(
OauthUserInfoParam
param
){
public
void
add
(
OauthUserInfoParam
param
)
{
OauthUserInfo
entity
=
getEntity
(
param
);
OauthUserInfo
entity
=
getEntity
(
param
);
this
.
save
(
entity
);
this
.
save
(
entity
);
}
}
@Override
@Override
public
void
delete
(
OauthUserInfoParam
param
){
public
void
delete
(
OauthUserInfoParam
param
)
{
this
.
removeById
(
getKey
(
param
));
this
.
removeById
(
getKey
(
param
));
}
}
@Override
@Override
public
void
update
(
OauthUserInfoParam
param
){
public
void
update
(
OauthUserInfoParam
param
)
{
OauthUserInfo
oldEntity
=
getOldEntity
(
param
);
OauthUserInfo
oldEntity
=
getOldEntity
(
param
);
OauthUserInfo
newEntity
=
getEntity
(
param
);
OauthUserInfo
newEntity
=
getEntity
(
param
);
ToolUtil
.
copyProperties
(
newEntity
,
oldEntity
);
ToolUtil
.
copyProperties
(
newEntity
,
oldEntity
);
...
@@ -47,23 +48,29 @@ public class OauthUserInfoServiceImpl extends ServiceImpl<OauthUserInfoMapper, O
...
@@ -47,23 +48,29 @@ public class OauthUserInfoServiceImpl extends ServiceImpl<OauthUserInfoMapper, O
}
}
@Override
@Override
public
OauthUserInfoResult
findBySpec
(
OauthUserInfoParam
param
){
public
OauthUserInfoResult
findBySpec
(
OauthUserInfoParam
param
)
{
return
null
;
return
null
;
}
}
@Override
@Override
public
List
<
OauthUserInfoResult
>
findListBySpec
(
OauthUserInfoParam
param
){
public
List
<
OauthUserInfoResult
>
findListBySpec
(
OauthUserInfoParam
param
)
{
return
null
;
return
null
;
}
}
@Override
@Override
public
LayuiPageInfo
findPageBySpec
(
OauthUserInfoParam
param
){
public
LayuiPageInfo
findPageBySpec
(
OauthUserInfoParam
param
)
{
Page
pageContext
=
getPageContext
();
Page
pageContext
=
getPageContext
();
IPage
page
=
this
.
baseMapper
.
customPageList
(
pageContext
,
param
);
IPage
page
=
this
.
baseMapper
.
customPageList
(
pageContext
,
param
);
return
LayuiPageFactory
.
createPageInfo
(
page
);
return
LayuiPageFactory
.
createPageInfo
(
page
);
}
}
private
Serializable
getKey
(
OauthUserInfoParam
param
){
@Override
public
String
getAvatarUrl
(
Long
userId
)
{
OauthUserInfo
oauthUserInfo
=
this
.
getOne
(
new
QueryWrapper
<
OauthUserInfo
>().
eq
(
"user_id"
,
userId
));
return
oauthUserInfo
.
getAvatar
();
}
private
Serializable
getKey
(
OauthUserInfoParam
param
)
{
return
param
.
getOauthId
();
return
param
.
getOauthId
();
}
}
...
...
guns-sys/src/main/java/cn/stylefeng/guns/sys/core/constant/Const.java
View file @
e96b8d87
...
@@ -67,4 +67,10 @@ public interface Const {
...
@@ -67,4 +67,10 @@ public interface Const {
*/
*/
List
<
String
>
NONE_PERMISSION_RES
=
CollectionUtil
.
newLinkedList
(
"/assets/**"
,
"/gunsApi/**"
,
"/login"
,
"/global/sessionError"
,
"/kaptcha"
,
"/error"
,
"/global/error"
,
"/oauth/**"
);
List
<
String
>
NONE_PERMISSION_RES
=
CollectionUtil
.
newLinkedList
(
"/assets/**"
,
"/gunsApi/**"
,
"/login"
,
"/global/sessionError"
,
"/kaptcha"
,
"/error"
,
"/global/error"
,
"/oauth/**"
);
/**
* OAuth2登录用户的账号标识
*/
String
OAUTH2_ACCOUNT_PREFIX
=
"oauth2"
;
}
}
guns-sys/src/main/java/cn/stylefeng/guns/sys/core/shiro/ShiroKit.java
View file @
e96b8d87
...
@@ -16,10 +16,10 @@
...
@@ -16,10 +16,10 @@
package
cn
.
stylefeng
.
guns
.
sys
.
core
.
shiro
;
package
cn
.
stylefeng
.
guns
.
sys
.
core
.
shiro
;
import
cn.stylefeng.guns.base.shiro.ShiroUser
;
import
cn.stylefeng.guns.base.shiro.ShiroUser
;
import
cn.stylefeng.guns.sys.core.constant.Const
;
import
cn.stylefeng.guns.sys.core.constant.factory.ConstantFactory
;
import
cn.stylefeng.guns.sys.core.constant.factory.ConstantFactory
;
import
cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum
;
import
cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum
;
import
cn.stylefeng.guns.sys.modular.system.entity.User
;
import
cn.stylefeng.guns.sys.modular.system.entity.User
;
import
cn.stylefeng.guns.sys.core.constant.Const
;
import
cn.stylefeng.roses.core.util.ToolUtil
;
import
cn.stylefeng.roses.core.util.ToolUtil
;
import
cn.stylefeng.roses.kernel.model.exception.ServiceException
;
import
cn.stylefeng.roses.kernel.model.exception.ServiceException
;
import
org.apache.shiro.SecurityUtils
;
import
org.apache.shiro.SecurityUtils
;
...
@@ -317,4 +317,15 @@ public class ShiroKit {
...
@@ -317,4 +317,15 @@ public class ShiroKit {
return
shiroUser
;
return
shiroUser
;
}
}
/**
* 判断用户是否是从oauth2登录过来的
*/
public
static
boolean
oauth2Flag
()
{
String
account
=
ShiroKit
.
getUserNotNull
().
getAccount
();
if
(
account
.
startsWith
(
Const
.
OAUTH2_ACCOUNT_PREFIX
))
{
return
true
;
}
else
{
return
false
;
}
}
}
}
guns-sys/src/main/java/cn/stylefeng/guns/sys/core/util/DefaultImages.java
View file @
e96b8d87
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
package
cn
.
stylefeng
.
guns
.
sys
.
core
.
util
;
package
cn
.
stylefeng
.
guns
.
sys
.
core
.
util
;
import
cn.stylefeng.guns.sys.core.listener.ConfigListener
;
import
cn.stylefeng.guns.sys.core.listener.ConfigListener
;
import
cn.stylefeng.guns.sys.core.shiro.ShiroKit
;
/**
/**
* 获取默认图片地址
* 获取默认图片地址
...
@@ -42,7 +43,11 @@ public class DefaultImages {
...
@@ -42,7 +43,11 @@ public class DefaultImages {
* @Date 2018/10/30 5:51 PM
* @Date 2018/10/30 5:51 PM
*/
*/
public
static
String
defaultAvatarUrl
()
{
public
static
String
defaultAvatarUrl
()
{
return
ConfigListener
.
getConf
().
get
(
"contextPath"
)
+
"/system/previewAvatar"
;
if
(
ShiroKit
.
oauth2Flag
())
{
return
ConfigListener
.
getConf
().
get
(
"contextPath"
)
+
"/oauth/avatar"
;
}
else
{
return
ConfigListener
.
getConf
().
get
(
"contextPath"
)
+
"/system/previewAvatar"
;
}
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment