Search in sources :

Example 1 with SysUser

use of com.ruoyi.system.domain.SysUser in project Rental-Information-Platform by who1sBruce.

the class ApiTeamController method genInviterCode.

/**
 * @Description: 递归返回唯一的邀请码
 * @author: zy
 * @date: 0330
 * @Return: code
 */
private String genInviterCode() {
    String code = CodeUtil.getCodeByUUId();
    code = code.substring(4);
    SysUser sysUser = userService.selectUserByPcode(code);
    if (StringUtils.isNotNull(sysUser)) {
        // 生成以后去校验是否存在,如果不存在则返回,如果存在则重新生成
        genInviterCode();
    }
    return code;
}
Also used : SysUser(com.ruoyi.system.domain.SysUser)

Example 2 with SysUser

use of com.ruoyi.system.domain.SysUser in project Rental-Information-Platform by who1sBruce.

the class WebIndexController method ajaxThridLogin.

/**
 * 密码登录 Json参数
 */
@PostMapping("/thirdLogin")
@ResponseBody
public AjaxResult ajaxThridLogin(HttpServletRequest request, @RequestBody SysUser user) {
    String msg = "用户不存在/密码错误";
    // 判断是不是手机号码
    if (!user.getLoginName().matches(UserConstants.MOBILE_PHONE_NUMBER_PATTERN) || StringUtils.isEmpty(user.getPassword())) {
        return error(msg);
    }
    UsernamePasswordToken token = new UsernamePasswordToken(user.getLoginName(), user.getPassword());
    Subject subject = SecurityUtils.getSubject();
    try {
        subject.login(token);
        SysUser sysUser = ShiroUtils.getSysUser();
        // 获取token
        String jwtToken = JwtUtils.createToken(sysUser.getLoginName(), sysUser.getPassword());
        sysUser.setJwtToken(jwtToken);
        AjaxResult ajaxResult = new AjaxResult(AjaxResult.Type.SUCCESS, "登录成功", sysUser);
        return ajaxResult;
    } catch (AuthenticationException e) {
        if (com.ruoyi.common.utils.StringUtils.isNotEmpty(e.getMessage())) {
            msg = e.getMessage();
        }
        return error(msg);
    }
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) SysUser(com.ruoyi.system.domain.SysUser) AuthenticationException(org.apache.shiro.authc.AuthenticationException) Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Example 3 with SysUser

use of com.ruoyi.system.domain.SysUser in project Rental-Information-Platform by who1sBruce.

the class WebProfileController method update.

/**
 * 修改用户
 */
@PostMapping("/update")
@ResponseBody
public AjaxResult update(SysUser user) {
    SysUser currentUser = userService.selectUserByLoginName(user.getLoginName());
    if (StringUtils.isNotNull(currentUser)) {
        currentUser.setUserName(user.getUserName());
        currentUser.setEmail(user.getEmail());
        currentUser.setSex(user.getSex());
        if (StringUtils.isEmpty(currentUser.getCode())) {
            currentUser.setCode(user.getCode());
        }
        currentUser.setAddress(user.getAddress());
        if (userService.updateUserInfo(currentUser) > 0) {
            AjaxResult ajaxResult = new AjaxResult(AjaxResult.Type.SUCCESS, "登录成功", currentUser);
            return ajaxResult;
        }
    }
    return error();
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) SysUser(com.ruoyi.system.domain.SysUser)

Example 4 with SysUser

use of com.ruoyi.system.domain.SysUser in project Rental-Information-Platform by who1sBruce.

the class WebProfileController method resetPwd.

@PostMapping("/resetPwd")
@ResponseBody
public AjaxResult resetPwd(String loginName, String oldPassword, String newPassword) {
    SysUser user = userService.selectUserByLoginName(loginName);
    if (StringUtils.isNotEmpty(newPassword) && passwordService.matches(user, oldPassword)) {
        user.setSalt(ShiroUtils.randomSalt());
        user.setPassword(passwordService.encryptPassword(user.getLoginName(), newPassword, user.getSalt()));
        if (userService.resetUserPwd(user) > 0) {
            // 获取token
            String jwtToken = JwtUtils.createToken(user.getLoginName(), user.getPassword());
            user.setJwtToken(jwtToken);
            AjaxResult ajaxResult = new AjaxResult(AjaxResult.Type.SUCCESS, "修改密码成功", user);
            return ajaxResult;
        }
        return error();
    } else {
        return error("修改密码失败,旧密码错误");
    }
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) SysUser(com.ruoyi.system.domain.SysUser)

Example 5 with SysUser

use of com.ruoyi.system.domain.SysUser in project Rental-Information-Platform by who1sBruce.

the class WebIndexController method thirdRegister.

/**
 * 手机注册/登录
 */
@PostMapping("/thirdRegister")
@ResponseBody
public AjaxResult thirdRegister(HttpServletRequest request, @RequestBody SysUser user) {
    String msg = "登录成功";
    if (StringUtils.isEmpty(user.getLoginName()) || StringUtils.isEmpty(user.getCaptcha())) {
        msg = "用户名/验证码不能为空";
        return error(msg);
    }
    // 首先验证验证码是否正确
    if (redisUtil.get(user.getLoginName()) == null || !redisUtil.get(user.getLoginName()).equals(user.getCaptcha())) {
        msg = "验证码过期/错误";
        return error(msg);
    }
    // 验证码正确则判断是否为新用户
    SysUser sysUser = userService.selectUserByLoginName(user.getLoginName());
    // 不是新用户,创建用户
    if (sysUser == null) {
        sysUser = new SysUser();
        sysUser.setPcode(user.getPcode());
        sysUser.setLoginName(user.getLoginName());
        sysUser.setUserName(user.getLoginName());
        sysUser.setPassword(user.getLoginName());
        sysUser.setPhonenumber(user.getLoginName());
        sysUser.setSalt(ShiroUtils.randomSalt());
        sysUser.setPassword(passwordService.encryptPassword(sysUser.getLoginName(), sysUser.getPassword(), sysUser.getSalt()));
        webIndexService.registerSave(sysUser);
    }
    // 获取token
    String jwtToken = JwtUtils.createToken(sysUser.getLoginName(), sysUser.getPassword());
    sysUser.setJwtToken(jwtToken);
    AjaxResult ajaxResult = new AjaxResult(AjaxResult.Type.SUCCESS, msg, sysUser);
    return ajaxResult;
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) SysUser(com.ruoyi.system.domain.SysUser)

Aggregations

SysUser (com.ruoyi.system.domain.SysUser)7 AjaxResult (com.ruoyi.common.core.domain.AjaxResult)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 Subject (org.apache.shiro.subject.Subject)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1