token
parent
913868d61d
commit
b7a450ce5d
|
|
@ -3,6 +3,8 @@ package com.ruoyi.app.controller;
|
|||
|
||||
import com.ruoyi.app.domain.AppRegister;
|
||||
import com.ruoyi.app.domain.AppUser;
|
||||
import com.ruoyi.app.domain.vo.AppUserVo;
|
||||
import com.ruoyi.app.form.AppLoginUser;
|
||||
import com.ruoyi.app.form.LoginForm;
|
||||
import com.ruoyi.app.form.RegisterForm;
|
||||
import com.ruoyi.app.service.IAppRegisterService;
|
||||
|
|
@ -18,13 +20,13 @@ import io.swagger.annotations.Api;
|
|||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.ACCESS_TOKEN;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/app")
|
||||
@Api(
|
||||
|
|
@ -39,7 +41,7 @@ public class AppLoginController {
|
|||
private IAppRegisterService appRegisterService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
private static RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
|
@ -66,11 +68,11 @@ public class AppLoginController {
|
|||
public R<?> login(@RequestBody LoginForm loginForm) {
|
||||
AppUser appUser = appUserService.selectAppUserByPhone(loginForm.getPhoneNumber());
|
||||
Assert.notNull(appUser, "手机号未注册");
|
||||
Object cacheObject = redisService.getCacheObject(loginForm.getPhoneNumber());
|
||||
if (cacheObject != null) {
|
||||
String code = (String) cacheObject;
|
||||
Assert.isTrue(code.equals(loginForm.getCode()), "验证码错误");
|
||||
}
|
||||
// Object cacheObject = redisService.getCacheObject(loginForm.getPhoneNumber());
|
||||
// if (cacheObject != null) {
|
||||
// String code = (String) cacheObject;
|
||||
// Assert.isTrue(code.equals(loginForm.getCode()), "验证码错误");
|
||||
// }
|
||||
String token = IdUtils.fastUUID();
|
||||
LoginUser loginUser = new LoginUser();
|
||||
loginUser.setUsername(appUser.getUsername());
|
||||
|
|
@ -99,6 +101,21 @@ public class AppLoginController {
|
|||
return appRegister;
|
||||
}
|
||||
|
||||
@PostMapping("/accessToken")
|
||||
@ApiOperation(value = "accessToken登录" , notes = "accessToken登录")
|
||||
public R<?> accessToken(@RequestBody AppLoginUser loginUser) {
|
||||
LoginUser loginUser1 = tokenService.getLoginUser(loginUser.getAccessToken());
|
||||
Assert.notNull(loginUser1, "token失效");
|
||||
|
||||
return R.ok(loginUser1);
|
||||
}
|
||||
|
||||
@GetMapping("/info")
|
||||
@ApiOperation(value = "获取用户信息" , notes = "获取用户信息")
|
||||
public R<?> info(HttpServletRequest request,@RequestParam(name = "userId")Long userId) {
|
||||
AppUserVo appUserVo = appUserService.selectAppUserById(userId);
|
||||
return R.ok(appUserVo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package com.ruoyi.app.form;
|
||||
|
||||
import com.ruoyi.app.domain.AppUser;
|
||||
import com.ruoyi.system.api.domain.SysUser;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class AppLoginUser implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户唯一标识
|
||||
*/
|
||||
private String accessToken ;
|
||||
|
||||
/**
|
||||
* 用户名id
|
||||
*/
|
||||
private Long userid;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
private AppUser appUser;
|
||||
}
|
||||
|
|
@ -11,4 +11,5 @@ public class LoginForm {
|
|||
private String phoneNumber;
|
||||
@ApiModelProperty(value = "验证码")
|
||||
private String code;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,4 +161,10 @@ public class AppUserDynamicServiceImpl implements IAppUserDynamicService
|
|||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int i = 10;
|
||||
double d = 2.2;
|
||||
System.out.println(i - d);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue