Search in sources :

Example 11 with LoginUser

use of com.ruoyi.common.core.domain.model.LoginUser in project wumei-smart by kerwincui.

the class JwtAuthenticationTokenFilter method doFilterInternal.

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
    LoginUser loginUser = tokenService.getLoginUser(request);
    if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication())) {
        tokenService.verifyToken(loginUser);
        UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
        authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
        SecurityContextHolder.getContext().setAuthentication(authenticationToken);
    }
    chain.doFilter(request, response);
}
Also used : UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) WebAuthenticationDetailsSource(org.springframework.security.web.authentication.WebAuthenticationDetailsSource)

Example 12 with LoginUser

use of com.ruoyi.common.core.domain.model.LoginUser in project wumei-smart by kerwincui.

the class LogoutSuccessHandlerImpl method onLogoutSuccess.

/**
 * 退出处理
 *
 * @return
 */
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
    LoginUser loginUser = tokenService.getLoginUser(request);
    if (StringUtils.isNotNull(loginUser)) {
        String userName = loginUser.getUsername();
        // 删除用户缓存记录
        tokenService.delLoginUser(loginUser.getToken());
        // 记录用户退出日志
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "退出成功"));
    }
    ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(HttpStatus.SUCCESS, "退出成功")));
}
Also used : LoginUser(com.ruoyi.common.core.domain.model.LoginUser)

Example 13 with LoginUser

use of com.ruoyi.common.core.domain.model.LoginUser in project wumei-smart by kerwincui.

the class TokenService method getLoginUserByToken.

/**
 * 获取用户身份信息
 *
 * @return 用户信息
 */
public LoginUser getLoginUserByToken(String token) {
    if (StringUtils.isNotEmpty(token)) {
        try {
            Claims claims = parseToken(token);
            // 解析对应的权限以及用户信息
            String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
            String userKey = getTokenKey(uuid);
            LoginUser user = redisCache.getCacheObject(userKey);
            return user;
        } catch (Exception e) {
        }
    }
    return null;
}
Also used : Claims(io.jsonwebtoken.Claims) LoginUser(com.ruoyi.common.core.domain.model.LoginUser)

Example 14 with LoginUser

use of com.ruoyi.common.core.domain.model.LoginUser in project wumei-smart by kerwincui.

the class SysProfileController method updatePwd.

/**
 * 重置密码
 */
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping("/updatePwd")
public AjaxResult updatePwd(String oldPassword, String newPassword) {
    LoginUser loginUser = getLoginUser();
    String userName = loginUser.getUsername();
    String password = loginUser.getPassword();
    if (!SecurityUtils.matchesPassword(oldPassword, password)) {
        return AjaxResult.error("修改密码失败,旧密码错误");
    }
    if (SecurityUtils.matchesPassword(newPassword, password)) {
        return AjaxResult.error("新密码不能与旧密码相同");
    }
    if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)) > 0) {
        // 更新缓存用户密码
        loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword));
        tokenService.setLoginUser(loginUser);
        return AjaxResult.success();
    }
    return AjaxResult.error("修改密码异常,请联系管理员");
}
Also used : LoginUser(com.ruoyi.common.core.domain.model.LoginUser) Log(com.ruoyi.common.annotation.Log)

Example 15 with LoginUser

use of com.ruoyi.common.core.domain.model.LoginUser in project wumei-smart by kerwincui.

the class SysProfileController method updateProfile.

/**
 * 修改用户
 */
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult updateProfile(@RequestBody SysUser user) {
    LoginUser loginUser = getLoginUser();
    SysUser sysUser = loginUser.getUser();
    user.setUserName(sysUser.getUserName());
    if (StringUtils.isNotEmpty(user.getPhonenumber()) && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
        return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
    }
    if (StringUtils.isNotEmpty(user.getEmail()) && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
        return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
    }
    user.setUserId(sysUser.getUserId());
    user.setPassword(null);
    if (userService.updateUserProfile(user) > 0) {
        // 更新缓存用户信息
        sysUser.setNickName(user.getNickName());
        sysUser.setPhonenumber(user.getPhonenumber());
        sysUser.setEmail(user.getEmail());
        sysUser.setSex(user.getSex());
        tokenService.setLoginUser(loginUser);
        return AjaxResult.success();
    }
    return AjaxResult.error("修改个人信息异常,请联系管理员");
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) Log(com.ruoyi.common.annotation.Log)

Aggregations

LoginUser (com.ruoyi.common.core.domain.model.LoginUser)65 Log (com.ruoyi.common.annotation.Log)16 SysUser (com.ruoyi.common.core.domain.entity.SysUser)13 GetMapping (org.springframework.web.bind.annotation.GetMapping)10 AjaxResult (com.ruoyi.common.core.domain.AjaxResult)9 UserType (com.ruoyi.common.enums.UserType)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 ServiceException (com.ruoyi.common.exception.ServiceException)7 ArrayList (java.util.ArrayList)7 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)7 PutMapping (org.springframework.web.bind.annotation.PutMapping)7 UserPasswordNotMatchException (com.ruoyi.common.exception.user.UserPasswordNotMatchException)5 DataColumn (com.ruoyi.common.annotation.DataColumn)4 RoleDTO (com.ruoyi.common.core.domain.dto.RoleDTO)4 SysMenu (com.ruoyi.common.core.domain.entity.SysMenu)4 CaptchaException (com.ruoyi.common.exception.user.CaptchaException)4 CaptchaExpireException (com.ruoyi.common.exception.user.CaptchaExpireException)4 Claims (io.jsonwebtoken.Claims)4 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)4 Authentication (org.springframework.security.core.Authentication)4