101 lines
3.0 KiB
Java
101 lines
3.0 KiB
Java
package com.yanzhu.wechat.controller;
|
|
|
|
import com.yanzhu.common.annotation.Anonymous;
|
|
import com.yanzhu.common.annotation.Log;
|
|
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;
|
|
import com.yanzhu.common.enums.BusinessType;
|
|
import com.yanzhu.common.enums.LimitType;
|
|
import com.yanzhu.common.enums.OperatorType;
|
|
import com.yanzhu.framework.web.service.SysLoginService;
|
|
import com.yanzhu.framework.web.service.TokenService;
|
|
import com.yanzhu.system.domain.vo.UpdatePwdVo;
|
|
import com.yanzhu.system.service.ISysUserService;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.validation.Valid;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @version : V1.0
|
|
* @ClassName: LoginController
|
|
* @Description: 用户登录
|
|
* @Auther: JiangYuQi
|
|
* @Date: 2020/7/7 18:03
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/wxApi")
|
|
public class WxLoginController extends BaseController {
|
|
|
|
@Autowired
|
|
private RedisCache redisCache;
|
|
|
|
@Autowired
|
|
private SysLoginService loginService;
|
|
|
|
@Autowired
|
|
private TokenService tokenService;
|
|
|
|
@Autowired
|
|
private ISysUserService sysUserService;
|
|
|
|
/**
|
|
* 登录方法
|
|
*
|
|
* @param loginBody 登录信息
|
|
* @return 结果
|
|
*/
|
|
@ApiOperation(value = "账号密码登录")
|
|
@RateLimiter(count = 10, limitType = LimitType.IP)
|
|
@Anonymous
|
|
@PostMapping("/login")
|
|
public AjaxResult login(@RequestBody LoginBody loginBody)
|
|
{
|
|
AjaxResult ajax = AjaxResult.success();
|
|
// 生成令牌
|
|
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),loginBody.getUuid());
|
|
// 移动端这里刷新token有效期为长期
|
|
tokenService.refreshMobileToken(token);
|
|
ajax.put(Constants.TOKEN, token);
|
|
return ajax;
|
|
}
|
|
|
|
/**
|
|
* 用户修改密码
|
|
*
|
|
* @return 结果
|
|
*/
|
|
@ApiOperation(value = "修改密码")
|
|
@RateLimiter(count = 10, limitType = LimitType.IP)
|
|
@Log(title = "用户修改密码", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE)
|
|
@PostMapping("/updatePwd")
|
|
public AjaxResult updatePwd(@RequestBody @Valid UpdatePwdVo updatePwdVo)
|
|
{
|
|
sysUserService.updatePwd(updatePwdVo);
|
|
return success();
|
|
}
|
|
|
|
/**
|
|
* 用户退出登录
|
|
*
|
|
* @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();
|
|
}
|
|
|
|
}
|