mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-17 16:36:03 +08:00
[功能]:1、跳转url 放到配置文件里面 2、优化登录管理界面 3、添加qq登录解绑和重新绑定功能 4、个人中心增加 qq绑定信息 展示view
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package com.ruoyi.iot.controller;
|
||||
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.iot.service.IUserSocialProfileService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 第三方登录平台控制Controller
|
||||
*
|
||||
* @author json
|
||||
* @date 2022-04-24
|
||||
*/
|
||||
@Api(tags = "用户社交账户api")
|
||||
@RestController
|
||||
@RequestMapping("/iot/social/")
|
||||
public class UserSocialController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IUserSocialProfileService iUserSocialProfileService;
|
||||
|
||||
|
||||
/**
|
||||
* 绑定
|
||||
*
|
||||
* @param bindId 绑定id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/bindId/{bindId}")
|
||||
@ApiOperation("绑定api")
|
||||
@ApiImplicitParam(name = "bindId", value = "绑定bindId", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
|
||||
public AjaxResult bindUser(@PathVariable String bindId) {
|
||||
return iUserSocialProfileService.bindUser(bindId, getUserId());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 绑定
|
||||
*
|
||||
* @param platform 绑定类型
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/bind/{platform}")
|
||||
@ApiOperation("绑定跳转api")
|
||||
@ApiImplicitParam(name = "platform", value = "绑定platform", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
|
||||
public AjaxResult bind(@PathVariable String platform) {
|
||||
return iUserSocialProfileService.bindSocialAccount(platform);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑
|
||||
*
|
||||
* @param socialUserId 用户社交平台Id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/unbind/{socialUserId}")
|
||||
@ApiOperation("解绑api")
|
||||
@ApiImplicitParam(name = "socialUserId", value = "绑定socialId", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||
public AjaxResult unbind(@PathVariable Long socialUserId) {
|
||||
return iUserSocialProfileService.unbindSocialAccount(socialUserId, getUserId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.ruoyi.iot.domain;
|
||||
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
public class UserSocialProfile {
|
||||
/**
|
||||
* 第三方系统用户表主键
|
||||
*/
|
||||
private Long socialUserId;
|
||||
|
||||
/**
|
||||
* 第三方用户来源
|
||||
*/
|
||||
@Excel(name = "第三方用户来源")
|
||||
private String source;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@Excel(name = "用户名")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
@Excel(name = "用户昵称")
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 用户头像
|
||||
*/
|
||||
@Excel(name = "用户头像")
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 绑定状态(0:未绑定,1:绑定)
|
||||
*/
|
||||
@Excel(name = "绑定状态(0:未绑定,1:绑定)")
|
||||
private String status;
|
||||
|
||||
public Long getSocialUserId() {
|
||||
return socialUserId;
|
||||
}
|
||||
|
||||
public void setSocialUserId(Long socialUserId) {
|
||||
this.socialUserId = socialUserId;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("socialUserId", getSocialUserId())
|
||||
.append("source", getSource())
|
||||
.append("status", getStatus())
|
||||
.append("username", getUsername())
|
||||
.append("nickname", getNickname())
|
||||
.append("avatar", getAvatar())
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.iot.domain.UserSocialProfile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IUserSocialProfileService {
|
||||
/**
|
||||
* 找到用户绑定的社交账户
|
||||
*
|
||||
* @param sysUserId 用户主键
|
||||
* @return
|
||||
*/
|
||||
List<UserSocialProfile> selectUserSocialProfile(Long sysUserId);
|
||||
|
||||
/**
|
||||
* 绑定用户
|
||||
*
|
||||
* @param bindId 绑定的Id
|
||||
* @param sysUserId 用户主键
|
||||
* @return
|
||||
*/
|
||||
AjaxResult bindUser(String bindId, Long sysUserId);
|
||||
|
||||
/**
|
||||
* 点击绑定跳转api
|
||||
*
|
||||
* @param platform 平台
|
||||
* @return
|
||||
*/
|
||||
AjaxResult bindSocialAccount(String platform);
|
||||
|
||||
/**
|
||||
* 解除绑定
|
||||
*
|
||||
* @param socialUserId 要解除的社交账户主键
|
||||
* @param sysUserId 用户主键
|
||||
* @return
|
||||
*/
|
||||
AjaxResult unbindSocialAccount(Long socialUserId, Long sysUserId);
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import com.ruoyi.common.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.enums.SocialPlatformType;
|
||||
import com.ruoyi.iot.domain.SocialUser;
|
||||
import com.ruoyi.iot.domain.UserSocialProfile;
|
||||
import com.ruoyi.iot.model.login.BindIdValue;
|
||||
import com.ruoyi.iot.service.ISocialPlatformService;
|
||||
import com.ruoyi.iot.service.ISocialUserService;
|
||||
import com.ruoyi.iot.service.IUserSocialProfileService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.ruoyi.iot.service.impl.SocialLoginServiceImpl.BIND_REDIS_KEY;
|
||||
|
||||
@Service
|
||||
public class UserSocialProfileServiceImpl implements IUserSocialProfileService {
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
@Autowired
|
||||
private ISocialUserService iSocialUserService;
|
||||
@Autowired
|
||||
private ISocialPlatformService iSocialPlatformService;
|
||||
|
||||
@Override
|
||||
public List<UserSocialProfile> selectUserSocialProfile(Long sysUserId) {
|
||||
SocialUser selectSocialUser = new SocialUser();
|
||||
selectSocialUser.setSysUserId(sysUserId);
|
||||
List<SocialUser> socialUserList = iSocialUserService.selectSocialUserList(selectSocialUser);
|
||||
List<UserSocialProfile> userSocialProfileList = new ArrayList<>();
|
||||
for (SocialUser socialUser : socialUserList) {
|
||||
//如果是删除的标记
|
||||
if (socialUser.getDelFlag().equals("1")) {
|
||||
continue;
|
||||
}
|
||||
UserSocialProfile userSocialProfile = new UserSocialProfile();
|
||||
userSocialProfile.setSocialUserId(socialUser.getSocialUserId());
|
||||
userSocialProfile.setAvatar(socialUser.getAvatar());
|
||||
userSocialProfile.setSource(socialUser.getSource());
|
||||
userSocialProfile.setUsername(socialUser.getUsername());
|
||||
userSocialProfile.setNickname(socialUser.getNickname());
|
||||
userSocialProfile.setStatus(socialUser.getStatus());
|
||||
userSocialProfileList.add(userSocialProfile);
|
||||
}
|
||||
return userSocialProfileList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AjaxResult bindUser(String bindId, Long sysUserId) {
|
||||
BindIdValue bindValue = redisCache.getCacheObject(BIND_REDIS_KEY + bindId);
|
||||
if (bindValue == null) {
|
||||
//不作提示
|
||||
return AjaxResult.error(HttpStatus.NO_MESSAGE_ALERT, "未知异常");
|
||||
}
|
||||
SocialUser socialUser = findSocialUser(bindValue.getUuid(), bindValue.getSource());
|
||||
SocialUser updateSocialUser = new SocialUser();
|
||||
updateSocialUser.setSocialUserId(socialUser.getSocialUserId());
|
||||
updateSocialUser.setSysUserId(sysUserId);
|
||||
iSocialUserService.updateSocialUser(updateSocialUser);
|
||||
redisCache.deleteObject(BIND_REDIS_KEY + bindId);
|
||||
return AjaxResult.success("绑定成功!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AjaxResult bindSocialAccount(String platform) {
|
||||
try {
|
||||
SocialPlatformType.valueOf(platform);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("错误平台类型");
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AjaxResult unbindSocialAccount(Long socialUserId, Long sysUserId) {
|
||||
SocialUser socialUser = iSocialUserService.selectSocialUserBySocialUserId(socialUserId);
|
||||
if (socialUser == null) {
|
||||
return AjaxResult.error("绑定账户不存在!");
|
||||
} else if (!socialUser.getSysUserId().equals(socialUserId)) {
|
||||
return AjaxResult.error("用户账户和绑定账户不匹配!");
|
||||
} else {
|
||||
SocialUser updateSocialUser = new SocialUser();
|
||||
updateSocialUser.setSocialUserId(socialUserId);
|
||||
updateSocialUser.setSysUserId(-1L);
|
||||
iSocialUserService.updateSocialUser(updateSocialUser);
|
||||
return AjaxResult.success("解除绑定成功!");
|
||||
}
|
||||
}
|
||||
|
||||
public SocialUser findSocialUser(String uuid, String source) {
|
||||
SocialUser socialUser = new SocialUser();
|
||||
socialUser.setSource(source);
|
||||
socialUser.setUuid(uuid);
|
||||
List<SocialUser> socialUserList = iSocialUserService.selectSocialUserList(socialUser);
|
||||
return socialUserList == null || socialUserList.isEmpty() ? null : socialUserList.get(0);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user