Commit e96b8d87 by fengshuonan

更新oauth2的头像

parent 24c71d02
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;
}
} }
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");
......
...@@ -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);
} }
...@@ -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();
} }
......
...@@ -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";
} }
...@@ -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;
}
}
} }
...@@ -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";
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment