|
|
@@ -6,8 +6,10 @@ import java.util.Set;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import com.ygtx.common.annotation.Anonymous;
|
|
|
import com.ygtx.common.constant.Constants;
|
|
|
import com.ygtx.common.core.domain.AjaxResult;
|
|
|
import com.ygtx.common.core.domain.entity.SysMenu;
|
|
|
@@ -23,6 +25,7 @@ import com.ygtx.framework.web.service.SysPermissionService;
|
|
|
import com.ygtx.framework.web.service.TokenService;
|
|
|
import com.ygtx.system.service.ISysConfigService;
|
|
|
import com.ygtx.system.service.ISysMenuService;
|
|
|
+import com.ygtx.system.service.ISysUserService;
|
|
|
|
|
|
/**
|
|
|
* 登录验证
|
|
|
@@ -46,6 +49,9 @@ public class SysLoginController
|
|
|
|
|
|
@Autowired
|
|
|
private ISysConfigService configService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService userService;
|
|
|
|
|
|
/**
|
|
|
* 登录方法
|
|
|
@@ -57,6 +63,24 @@ public class SysLoginController
|
|
|
public AjaxResult login(@RequestBody LoginBody loginBody)
|
|
|
{
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
+
|
|
|
+ // 检查是否为初始密码
|
|
|
+ String initPassword = configService.selectConfigByKey("sys.user.initPassword");
|
|
|
+ if (initPassword != null && initPassword.equals(loginBody.getPassword())) {
|
|
|
+ // 验证用户名和密码是否正确
|
|
|
+ try {
|
|
|
+ String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
|
|
|
+ loginBody.getUuid());
|
|
|
+ // 如果能成功登录,说明是初始密码
|
|
|
+ ajax.put("isInitPassword", true);
|
|
|
+ ajax.put("message", "您使用的是初始密码,请修改密码后再登录");
|
|
|
+ return ajax;
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 用户名或密码错误
|
|
|
+ ajax.put("isInitPassword", false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 生成令牌
|
|
|
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
|
|
|
loginBody.getUuid());
|
|
|
@@ -64,6 +88,39 @@ public class SysLoginController
|
|
|
return ajax;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始密码修改
|
|
|
+ */
|
|
|
+ @Anonymous
|
|
|
+ @PutMapping("/initPassword")
|
|
|
+ public AjaxResult initPassword(@RequestBody LoginBody loginBody)
|
|
|
+ {
|
|
|
+ // 验证用户名和密码是否正确
|
|
|
+ try {
|
|
|
+ loginService.loginPreCheck(loginBody.getUsername(), loginBody.getPassword());
|
|
|
+
|
|
|
+ String initPassword = configService.selectConfigByKey("sys.user.initPassword");
|
|
|
+ if (initPassword.equals(loginBody.getPassword())) {
|
|
|
+ return AjaxResult.error("新密码不可与初始密码相同");
|
|
|
+ }
|
|
|
+ // 更新用户密码
|
|
|
+ SysUser user = userService.selectUserByUserName(loginBody.getUsername());
|
|
|
+ if (user != null) {
|
|
|
+ if (!SecurityUtils.matchesPassword(initPassword, user.getPassword())) {
|
|
|
+ return AjaxResult.error("用户密码已被修改");
|
|
|
+ }
|
|
|
+ user.setPassword(SecurityUtils.encryptPassword(loginBody.getPassword()));
|
|
|
+ user.setPwdUpdateDate(new Date());
|
|
|
+ userService.resetUserPwd(user.getUserId(), user.getPassword());
|
|
|
+ return AjaxResult.success("密码修改成功");
|
|
|
+ } else {
|
|
|
+ return AjaxResult.error("用户不存在");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return AjaxResult.error("密码修改失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取用户信息
|
|
|
*
|
|
|
@@ -128,4 +185,4 @@ public class SysLoginController
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
-}
|
|
|
+}
|