清除用户登录的错误次数
This commit is contained in:
parent
2b7ac9ab98
commit
5c24ff0148
|
|
@ -2,6 +2,8 @@ package com.ruoyi.web.controller.system;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
|
@ -66,6 +68,8 @@ public class SysUserController extends BaseController
|
|||
{
|
||||
startPage();
|
||||
List<SysUser> list = userService.selectUserList(user);
|
||||
list.forEach(sysUser -> sysUser.setErrorLoginTimes(
|
||||
passwordService.getErrorLoginTimes(sysUser.getLoginName())));
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
|
@ -243,6 +247,34 @@ public class SysUserController extends BaseController
|
|||
return toAjax(userService.deleteUserByIds(ids));
|
||||
}
|
||||
|
||||
@RequiresPermissions("system:user:clear")
|
||||
@Log(title = "用户管理", businessType = BusinessType.CLEAN)
|
||||
@PostMapping("/clearErrorLoginTimes")
|
||||
@ResponseBody
|
||||
public AjaxResult clearErrorLoginTimes(String ids)
|
||||
{
|
||||
try
|
||||
{
|
||||
int result = 0;
|
||||
Long[] userIds = Convert.toLongArray(ids);
|
||||
for (Long userId : userIds)
|
||||
{
|
||||
SysUser sysUser = userService.selectUserById(userId);
|
||||
if(null == sysUser)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
passwordService.clearLoginRecordCache(sysUser.getLoginName());
|
||||
result++;
|
||||
}
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验用户名
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@
|
|||
<script th:inline="javascript">
|
||||
var editFlag = [[${@permission.hasPermi('system:user:edit')}]];
|
||||
var removeFlag = [[${@permission.hasPermi('system:user:remove')}]];
|
||||
var clearFlag = [[${@permission.hasPermi('system:user:clear')}]];
|
||||
var resetPwdFlag = [[${@permission.hasPermi('system:user:resetPwd')}]];
|
||||
var prefix = ctx + "system/user";
|
||||
|
||||
|
|
@ -154,6 +155,10 @@
|
|||
field: 'phonenumber',
|
||||
title: '手机'
|
||||
},
|
||||
{
|
||||
field: 'errorLoginTimes',
|
||||
title: '登录失败次数'
|
||||
},
|
||||
{
|
||||
visible: editFlag == 'hidden' ? false : true,
|
||||
title: '用户状态',
|
||||
|
|
@ -177,6 +182,9 @@
|
|||
var more = [];
|
||||
more.push("<a class='btn btn-default btn-xs " + resetPwdFlag + "' href='javascript:void(0)' onclick='resetPwd(" + row.userId + ")'><i class='fa fa-key'></i>重置密码</a> ");
|
||||
more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='authRole(" + row.userId + ")'><i class='fa fa-check-square-o'></i>分配角色</a>");
|
||||
if(null != row.errorLoginTimes && row.errorLoginTimes > 0) {
|
||||
more.push("<a class='btn btn-default btn-xs " + clearFlag + "' href='javascript:void(0)' onclick='clearErrorLoginTimes(" + row.userId + ")'><i class='fa fa-remove'></i>清除失败登录</a>");
|
||||
}
|
||||
actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
|
||||
return actions.join('');
|
||||
}
|
||||
|
|
@ -258,6 +266,13 @@
|
|||
$.operate.post(prefix + "/changeStatus", { "userId": userId, "status": 0 });
|
||||
})
|
||||
}
|
||||
|
||||
/* 清除失败登录次数 */
|
||||
function clearErrorLoginTimes(userId) {
|
||||
$.modal.confirm("确认要清除用户失败登录次数吗?", function() {
|
||||
$.operate.post(prefix + "/clearErrorLoginTimes", { "ids": userId });
|
||||
})
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
<!-- 导入区域 -->
|
||||
|
|
|
|||
|
|
@ -100,6 +100,8 @@ public class SysUser extends BaseEntity
|
|||
/** 岗位组 */
|
||||
private Long[] postIds;
|
||||
|
||||
private Integer errorLoginTimes;
|
||||
|
||||
public SysUser()
|
||||
{
|
||||
|
||||
|
|
@ -351,6 +353,16 @@ public class SysUser extends BaseEntity
|
|||
this.postIds = postIds;
|
||||
}
|
||||
|
||||
public Integer getErrorLoginTimes()
|
||||
{
|
||||
return errorLoginTimes;
|
||||
}
|
||||
|
||||
public void setErrorLoginTimes(Integer errorLoginTimes)
|
||||
{
|
||||
this.errorLoginTimes = errorLoginTimes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
|
|
@ -376,6 +388,7 @@ public class SysUser extends BaseEntity
|
|||
.append("remark", getRemark())
|
||||
.append("dept", getDept())
|
||||
.append("roles", getRoles())
|
||||
.append("errorLoginTimes", getErrorLoginTimes())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,15 @@ public class SysPasswordService
|
|||
return user.getPassword().equals(encryptPassword(user.getLoginName(), newPassword, user.getSalt()));
|
||||
}
|
||||
|
||||
public int getErrorLoginTimes(String username)
|
||||
{
|
||||
AtomicInteger atomicInteger = loginRecordCache.get(username);
|
||||
if (null == atomicInteger) {
|
||||
return 0;
|
||||
}
|
||||
return atomicInteger.get();
|
||||
}
|
||||
|
||||
public void clearLoginRecordCache(String loginName)
|
||||
{
|
||||
loginRecordCache.remove(loginName);
|
||||
|
|
|
|||
Loading…
Reference in New Issue