Search in sources :

Example 1 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult 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 2 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult 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 3 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult 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 4 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project Rental-Information-Platform by who1sBruce.

the class ApiHouseController method findVillageList.

/**
 * @Description: 获取小區信息
 * @date: 0714
 * @Return: AjaxResult
 */
@GetMapping("/findVillageList")
@ResponseBody
public AjaxResult findVillageList(HouseVillage houseVillage) {
    startPage();
    String msg = "小區列表";
    List<HouseVillage> list = houseVillageService.selectHouseVillageList(houseVillage);
    AjaxResult ajaxResult = new AjaxResult(AjaxResult.Type.SUCCESS, msg, list);
    return ajaxResult;
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) HouseVillage(com.ruoyi.system.domain.HouseVillage)

Example 5 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project Rental-Information-Platform by who1sBruce.

the class ApiHouseController method findHouseList.

/**
 * @Description: 获取房源信息
 * @date: 0714
 * @Return: AjaxResult
 */
@GetMapping("/findHouseList")
@ResponseBody
public AjaxResult findHouseList(HouseRoom houseRoom) {
    startPage();
    String msg = "房源列表";
    List<HouseRoom> list = houseRoomService.selectHouseRoomList(houseRoom);
    AjaxResult ajaxResult = new AjaxResult(AjaxResult.Type.SUCCESS, msg, list);
    return ajaxResult;
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) HouseRoom(com.ruoyi.system.domain.HouseRoom)

Aggregations

AjaxResult (com.ruoyi.common.core.domain.AjaxResult)55 GetMapping (org.springframework.web.bind.annotation.GetMapping)25 PostMapping (org.springframework.web.bind.annotation.PostMapping)16 SysUser (com.ruoyi.common.core.domain.entity.SysUser)12 LoginUser (com.ruoyi.common.core.domain.model.LoginUser)10 Log (com.ruoyi.common.annotation.Log)8 StringUtils (com.ruoyi.common.utils.StringUtils)7 List (java.util.List)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 RestController (org.springframework.web.bind.annotation.RestController)7 MultipartFile (org.springframework.web.multipart.MultipartFile)7 SysUser (com.ruoyi.system.domain.SysUser)6 UserConstants (com.ruoyi.common.constant.UserConstants)5 BaseController (com.ruoyi.common.core.controller.BaseController)5 SysRole (com.ruoyi.common.core.domain.entity.SysRole)5 TableDataInfo (com.ruoyi.common.core.page.TableDataInfo)5 BusinessType (com.ruoyi.common.enums.BusinessType)5 SecurityUtils (com.ruoyi.common.utils.SecurityUtils)5