新增锁定屏幕功能

This commit is contained in:
RuoYi
2026-03-21 23:29:22 +08:00
parent b43048a589
commit 88c2e4979a
12 changed files with 510 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.auth.form.LoginBody;
import com.ruoyi.auth.form.RegisterBody;
import com.ruoyi.auth.form.UnLockBody;
import com.ruoyi.auth.service.SysLoginService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.JwtUtils;
@@ -75,4 +76,14 @@ public class TokenController
sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
return R.ok();
}
/**
* 解锁屏幕
*/
@PostMapping("/unlockscreen")
public R<?> unlockScreen(@RequestBody UnLockBody unLockBody)
{
sysLoginService.unlock(unLockBody.getPassword());
return R.ok();
}
}

View File

@@ -0,0 +1,24 @@
package com.ruoyi.auth.form;
/**
* 系统解锁对象
*
* @author ruoyi
*/
public class UnLockBody
{
/**
* 用户密码
*/
private String password;
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
}

View File

@@ -113,11 +113,40 @@ public class SysLoginService
remoteUserService.recordUserLogin(sysUser, SecurityConstants.INNER);
}
/**
* 退出
*/
public void logout(String loginName)
{
recordLogService.recordLogininfor(loginName, Constants.LOGOUT, "退出成功");
}
/**
* 解锁
*/
public void unlock(String password)
{
String username = SecurityUtils.getUsername();
// 或密码为空 错误
if (StringUtils.isEmpty(password))
{
throw new ServiceException("密码不能为空");
}
// 查询用户信息
R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
if (R.FAIL == userResult.getCode())
{
throw new ServiceException(userResult.getMsg());
}
SysUser user = userResult.getData().getSysUser();
if (!SecurityUtils.matchesPassword(password, user.getPassword()))
{
throw new ServiceException("密码错误,请重新输入");
}
}
/**
* 注册
*/