|
|
|
@ -11,7 +11,14 @@ import com.ruoyi.common.core.domain.AjaxResult; |
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser; |
|
|
|
import com.ruoyi.common.core.domain.model.LoginUser; |
|
|
|
import com.ruoyi.common.core.redis.RedisCache; |
|
|
|
import com.ruoyi.common.utils.SecurityUtils; |
|
|
|
import com.ruoyi.common.utils.StringUtils; |
|
|
|
import com.ruoyi.framework.web.service.SysLoginService; |
|
|
|
import com.ruoyi.framework.web.service.TokenService; |
|
|
|
import com.ruoyi.system.service.ISysDeptService; |
|
|
|
import com.ruoyi.system.service.ISysPostService; |
|
|
|
import com.ruoyi.system.service.ISysRoleService; |
|
|
|
import com.ruoyi.system.service.ISysUserService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import cn.dev33.satoken.stp.StpUtil; |
|
|
|
@ -30,6 +37,9 @@ public class LoginController extends BaseController { |
|
|
|
ZhyUserMapper zhyUserMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ISysUserService userService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TokenService tokenService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
@ -38,108 +48,89 @@ public class LoginController extends BaseController { |
|
|
|
@Autowired |
|
|
|
private RedisCache redisCache; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ISysRoleService roleService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ISysDeptService deptService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ISysPostService postService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SysLoginService loginService; |
|
|
|
@PostMapping("/doLogin") |
|
|
|
public AjaxResult doLogin(@RequestBody ZhyUserEntity userEntity) { |
|
|
|
//存放返回结果
|
|
|
|
ZhyUserEntity zhyUserEntity = null; |
|
|
|
LoginUser loginUser = new LoginUser(); |
|
|
|
SysUser user = new SysUser(); |
|
|
|
|
|
|
|
//判断登录方式,用户名
|
|
|
|
if (!userEntity.getUserName().equals("")) { |
|
|
|
zhyUserEntity = zhyUserMapper.selectUserByNumber(userEntity); |
|
|
|
} |
|
|
|
if (zhyUserEntity == null) { |
|
|
|
return AjaxResult.error("账号不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
if (!zhyUserEntity.getPassWord().equals(userEntity.getPassWord())) { |
|
|
|
return AjaxResult.error("账号或密码错误"); |
|
|
|
} |
|
|
|
zhyUserEntity.setPassWord(null); // 清除密码字段,避免安全风险
|
|
|
|
|
|
|
|
System.out.println("-----------------aaaaaaaaaaaaaaaaaa"); |
|
|
|
System.out.println(zhyUserEntity.getId()); |
|
|
|
|
|
|
|
user.setUserName(userEntity.getUserName()); |
|
|
|
user.setUserId(zhyUserEntity.getId()); |
|
|
|
loginUser.setUser(user); |
|
|
|
|
|
|
|
loginUser.setUserId(zhyUserEntity.getId()); |
|
|
|
loginUser.setLoginTime(new Date().getTime()); |
|
|
|
|
|
|
|
String a = tokenService.createToken(loginUser); //a是token
|
|
|
|
//通过token获取uuid
|
|
|
|
|
|
|
|
zhyUserEntity.setToken(a); |
|
|
|
|
|
|
|
ZhyLoginInfo ll = new ZhyLoginInfo(); |
|
|
|
ll.setLoginTime(new Date()); |
|
|
|
ll.setUid(zhyUserEntity.getId()); |
|
|
|
int aa = zhyUserMapper.insertLogin(ll); |
|
|
|
|
|
|
|
return AjaxResult.success("成功登录", zhyUserEntity); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/doLogin1") |
|
|
|
public AjaxResult doLogin1(@RequestBody ZhyUserEntity userEntity) { |
|
|
|
//存放返回结果
|
|
|
|
ZhyUserEntity zhyUserEntity = null; |
|
|
|
LoginUser loginUser = new LoginUser(); |
|
|
|
SysUser user = new SysUser(); |
|
|
|
|
|
|
|
//判断登录方式,用户名
|
|
|
|
if (!userEntity.getUserName().equals("")) { |
|
|
|
zhyUserEntity = zhyUserMapper.selectUserByNumber(userEntity); |
|
|
|
if (userEntity.getUserName().equals("")) { |
|
|
|
return AjaxResult.error("输入为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if (zhyUserEntity == null) { |
|
|
|
SysUser sysUser = userService.selectUserByUserName(userEntity.getUserName()); |
|
|
|
if (sysUser == null){ |
|
|
|
return AjaxResult.error("账号不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
if (!zhyUserEntity.getPassWord().equals(userEntity.getPassWord())) { |
|
|
|
ZhyUserEntity zhyUserEntity = new ZhyUserEntity(); |
|
|
|
zhyUserEntity.setPassWord(sysUser.getPassword()); |
|
|
|
|
|
|
|
|
|
|
|
// 校验密码:使用 matches 而不是 equals
|
|
|
|
if (!SecurityUtils.matchesPassword(userEntity.getPassWord(), sysUser.getPassword())) { |
|
|
|
return AjaxResult.error("账号或密码错误"); |
|
|
|
} |
|
|
|
zhyUserEntity.setPassWord(null); // 清除密码字段,避免安全风险
|
|
|
|
|
|
|
|
System.out.println("-----------------aaaaaaaaaaaaaaaaaa"); |
|
|
|
System.out.println(zhyUserEntity.getId()); |
|
|
|
|
|
|
|
user.setUserName(userEntity.getUserName()); |
|
|
|
user.setUserId(zhyUserEntity.getId()); |
|
|
|
user.setUserName(sysUser.getUserName()); |
|
|
|
user.setUserId(sysUser.getUserId()); |
|
|
|
loginUser.setUser(user); |
|
|
|
|
|
|
|
loginUser.setUserId(zhyUserEntity.getId()); |
|
|
|
loginUser.setUserId(sysUser.getUserId()); |
|
|
|
loginUser.setLoginTime(new Date().getTime()); |
|
|
|
|
|
|
|
String a = tokenService.createToken(loginUser); //a是token
|
|
|
|
//通过token获取uuid
|
|
|
|
|
|
|
|
zhyUserEntity.setToken(a); |
|
|
|
|
|
|
|
ZhyLoginInfo ll = new ZhyLoginInfo(); |
|
|
|
ll.setLoginTime(new Date()); |
|
|
|
ll.setUid(zhyUserEntity.getId()); |
|
|
|
int aa = zhyUserMapper.insertLogin(ll); |
|
|
|
|
|
|
|
return AjaxResult.success("成功登录", zhyUserEntity); |
|
|
|
} |
|
|
|
@PostMapping("/doRegister") |
|
|
|
public SaResult doRegister(@RequestBody ZhyUserEntity userEntity) { |
|
|
|
ZhyUserEntity name = null; |
|
|
|
name = zhyUserMapper.selectUserByUser(userEntity); |
|
|
|
if (name != null) { |
|
|
|
return SaResult.error("用户已存在"); |
|
|
|
} else { |
|
|
|
userEntity.setCreateTime(new Date()); |
|
|
|
// userEntity.setIdType(userEntity.);
|
|
|
|
System.out.println(userEntity.getIdType()); |
|
|
|
System.out.println(userEntity.getSpecialized()); |
|
|
|
zhyUserMapper.insertUser(userEntity); |
|
|
|
StpUtil.login(userEntity.getId());//登录
|
|
|
|
return SaResult.ok("成功注册"); |
|
|
|
|
|
|
|
SysUser user = new SysUser(); |
|
|
|
user.setPassword(userEntity.getPassWord()); |
|
|
|
user.setUserName(userEntity.getUserName()); |
|
|
|
// user.setDeptId();
|
|
|
|
// deptService.checkDeptDataScope(user.getDeptId());
|
|
|
|
// roleService.checkRoleDataScope(user.getRoleIds());
|
|
|
|
if (!userService.checkUserNameUnique(user)) |
|
|
|
{ |
|
|
|
return SaResult.error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); |
|
|
|
} |
|
|
|
|
|
|
|
user.setCreateBy("admin"); |
|
|
|
user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
|
|
|
userService.insertUser(user); |
|
|
|
return SaResult.ok("成功注册"); |
|
|
|
|
|
|
|
|
|
|
|
// ZhyUserEntity name = null;
|
|
|
|
// name = zhyUserMapper.selectUserByUser(userEntity);
|
|
|
|
// if (name != null) {
|
|
|
|
// return SaResult.error("用户已存在");
|
|
|
|
// } else {
|
|
|
|
// userEntity.setCreateTime(new Date());
|
|
|
|
//// userEntity.setIdType(userEntity.);
|
|
|
|
// System.out.println(userEntity.getIdType());
|
|
|
|
// System.out.println(userEntity.getSpecialized());
|
|
|
|
// zhyUserMapper.insertUser(userEntity);
|
|
|
|
// StpUtil.login(userEntity.getId());//登录
|
|
|
|
// return SaResult.ok("成功注册");
|
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|