YanZhuProject/yanzhu-manage/src/main/java/com/yanzhu/wechat/controller/WxLoginController.java

101 lines
3.0 KiB
Java
Raw Normal View History

2024-02-28 23:39:36 +08:00
package com.yanzhu.wechat.controller;
2024-03-13 21:17:09 +08:00
import com.yanzhu.common.annotation.Anonymous;
import com.yanzhu.common.annotation.Log;
2024-02-28 23:39:36 +08:00
import com.yanzhu.common.annotation.RateLimiter;
import com.yanzhu.common.constant.Constants;
import com.yanzhu.common.core.controller.BaseController;
import com.yanzhu.common.core.domain.AjaxResult;
import com.yanzhu.common.core.domain.model.LoginBody;
import com.yanzhu.common.core.redis.RedisCache;
2024-03-13 21:17:09 +08:00
import com.yanzhu.common.enums.BusinessType;
2024-02-28 23:39:36 +08:00
import com.yanzhu.common.enums.LimitType;
2024-03-13 21:17:09 +08:00
import com.yanzhu.common.enums.OperatorType;
2024-02-28 23:39:36 +08:00
import com.yanzhu.framework.web.service.SysLoginService;
import com.yanzhu.framework.web.service.TokenService;
2024-03-04 23:46:34 +08:00
import com.yanzhu.system.domain.vo.UpdatePwdVo;
import com.yanzhu.system.service.ISysUserService;
2024-02-28 23:39:36 +08:00
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
2024-03-04 23:46:34 +08:00
import org.springframework.web.bind.annotation.*;
2024-03-13 21:17:09 +08:00
import javax.servlet.http.HttpServletRequest;
2024-03-04 23:46:34 +08:00
import javax.validation.Valid;
import java.util.Map;
2024-02-28 23:39:36 +08:00
/**
* @version : V1.0
* @ClassName: LoginController
* @Description:
* @Auther: JiangYuQi
* @Date: 2020/7/7 18:03
*/
@RestController
2024-03-04 23:46:34 +08:00
@RequestMapping("/wxApi")
2024-02-28 23:39:36 +08:00
public class WxLoginController extends BaseController {
@Autowired
private RedisCache redisCache;
@Autowired
private SysLoginService loginService;
@Autowired
private TokenService tokenService;
2024-03-04 23:46:34 +08:00
@Autowired
private ISysUserService sysUserService;
2024-02-28 23:39:36 +08:00
/**
*
*
* @param loginBody
* @return
*/
@ApiOperation(value = "账号密码登录")
@RateLimiter(count = 10, limitType = LimitType.IP)
2024-03-13 21:17:09 +08:00
@Anonymous
2024-02-28 23:39:36 +08:00
@PostMapping("/login")
public AjaxResult login(@RequestBody LoginBody loginBody)
{
AjaxResult ajax = AjaxResult.success();
// 生成令牌
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),loginBody.getUuid());
2024-03-13 21:17:09 +08:00
// 移动端这里刷新token有效期为长期
tokenService.refreshMobileToken(token);
2024-02-28 23:39:36 +08:00
ajax.put(Constants.TOKEN, token);
return ajax;
}
2024-03-04 23:46:34 +08:00
/**
*
*
* @return
*/
@ApiOperation(value = "修改密码")
@RateLimiter(count = 10, limitType = LimitType.IP)
2024-03-13 21:17:09 +08:00
@Log(title = "用户修改密码", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE)
2024-03-04 23:46:34 +08:00
@PostMapping("/updatePwd")
public AjaxResult updatePwd(@RequestBody @Valid UpdatePwdVo updatePwdVo)
{
sysUserService.updatePwd(updatePwdVo);
return success();
}
2024-03-13 21:17:09 +08:00
/**
* 退
*
* @return
*/
@ApiOperation(value = "退出登录")
@RateLimiter(count = 10, limitType = LimitType.IP)
@Log(title = "用户退出登录", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE)
@PostMapping("/loginOut")
public AjaxResult loginOut(HttpServletRequest request)
{
tokenService.delLoginUser(request);
return success();
}
2024-02-28 23:39:36 +08:00
}