fix(system): 修复超级管理员标识设置和微信登录openid处理
- 在超级管理员用户创建时正确设置isSuperAdmin和isAdmin标识 - 修正超级管理员isAdmin属性设置顺序 - 微信登录接口中将openid和unionid设置到userParam,保证后续用户查找和注册使用 - 对已有用户补充openid和unionid信息,避免老用户缺少openid导致问题 - 更新用户信息后保存,确保数据一致性
This commit is contained in:
@@ -134,11 +134,23 @@ public class WxLoginController extends BaseController {
|
||||
if (openid == null) {
|
||||
return fail("获取openid失败", null);
|
||||
}
|
||||
// 关键:把 openid/unionid 设置到 userParam,否则后续查库/注册都拿不到 openid
|
||||
userParam.setOpenid(openid);
|
||||
if (StrUtil.isNotBlank(unionid)) {
|
||||
userParam.setUnionid(unionid);
|
||||
}
|
||||
// 2.通过openid查询用户是否已存在
|
||||
User user = userService.getByOauthId(userParam);
|
||||
// 3.存在则签发token并返回登录成功,不存在则注册新用户
|
||||
if (user == null) {
|
||||
user = addUser(userParam);
|
||||
} else if (StrUtil.isBlank(user.getOpenid())) {
|
||||
// 老用户(比如手机号注册)没有 openid,补上
|
||||
user.setOpenid(openid);
|
||||
if (StrUtil.isNotBlank(unionid)) {
|
||||
user.setUnionid(unionid);
|
||||
}
|
||||
userService.updateById(user);
|
||||
}
|
||||
// 4.签发token
|
||||
loginRecordService.saveAsync(user.getUsername(), LoginRecord.TYPE_LOGIN, null, user.getTenantId(), request);
|
||||
|
||||
@@ -108,9 +108,10 @@ public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> impleme
|
||||
superAdmin.setUsername("superAdmin");
|
||||
superAdmin.setNickname(company.getShortName());
|
||||
superAdmin.setPhone(company.getPhone());
|
||||
superAdmin.setIsSuperAdmin(true);
|
||||
superAdmin.setIsAdmin(true);
|
||||
superAdmin.setEmail(company.getEmail());
|
||||
superAdmin.setTemplateId(company.getTemplateId());
|
||||
superAdmin.setIsAdmin(true);
|
||||
superAdmin.setRealName(company.getBusinessEntity());
|
||||
superAdmin.setPassword(userService.encodePassword("$2a$10$iMsEmh.rPlzwy/SVe6KW3.62vlwqMJpibhCF9jYN.fMqxdqymzMzu"));
|
||||
if (company.getPassword() != null) {
|
||||
|
||||
Reference in New Issue
Block a user