1.添加游客登录接口

main
hechanggeng 11 months ago
parent 042d02ecb4
commit 5116db0240

@ -77,6 +77,10 @@
<artifactId>common-random</artifactId> <artifactId>common-random</artifactId>
<version>1.0.21</version> <version>1.0.21</version>
</dependency> </dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>app</finalName> <finalName>app</finalName>

@ -13,7 +13,7 @@ public class InterceptorConfig extends WebMvcConfigurationSupport {
@Autowired @Autowired
private JwtInterceptor jwtInterceptor; private JwtInterceptor jwtInterceptor;
protected void addInterceptors(InterceptorRegistry registry) { protected void addInterceptors(InterceptorRegistry registry) {
String[] excludePathPatterns = { "/user/login/**","/user/appLogin/**","/user/sendsms/**","/doc.html/**","/swagger-resources/**","/webjars/**","/v2/**"}; String[] excludePathPatterns = { "/user/login/**","/user/appLogin/**","/user/sendsms/**","/user/touristLogin","/doc.html/**","/swagger-resources/**","/webjars/**","/v2/**"};
registry.addInterceptor(jwtInterceptor). registry.addInterceptor(jwtInterceptor).
addPathPatterns("/**"). addPathPatterns("/**").

@ -91,7 +91,14 @@ public class UserController {
} }
UserVO userVO=userService.loginOrRegister(mobile); UserVO userVO=userService.loginOrRegister(mobile);
return ResultVO.success(userVO); return ResultVO.success(userVO);
} }
@ApiOperation(value="3.游客模式返回token",notes="token中的subject和roles均为tourist")
@RequestMapping(value = "/touristLogin",method = RequestMethod.GET)
public ResultVO<UserVO> touristLogin(){
UserVO userVO=userService.touristLogin();
return ResultVO.success(userVO);
}
/** /**
* *

@ -1,8 +1,14 @@
package com.luoo.user.pojo; package com.luoo.user.pojo;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.io.Serializable; import java.io.Serializable;
/** /**
* *
@ -11,13 +17,12 @@ import java.io.Serializable;
*/ */
@Entity @Entity
@Table(name="tb_user") @Table(name="tb_user")
@EntityListeners(AuditingEntityListener.class)
public class User implements Serializable{ public class User implements Serializable{
private static final long serialVersionUID = 1L;
@Id @Id
private String id;//ID private String id;//ID
private String mobile;//手机号码 private String mobile;//手机号码
private String loginname;//用户名 private String loginname;//用户名
private String password;//密码 private String password;//密码
@ -26,7 +31,9 @@ public class User implements Serializable{
private java.util.Date birthday;//出生年月日 private java.util.Date birthday;//出生年月日
private String avatar;//头像 private String avatar;//头像
private String email;//E-Mail private String email;//E-Mail
@CreatedDate
private java.util.Date regdate;//注册日期 private java.util.Date regdate;//注册日期
@LastModifiedDate
private java.util.Date updatedate;//修改日期 private java.util.Date updatedate;//修改日期
private java.util.Date lastdate;//最后登陆日期 private java.util.Date lastdate;//最后登陆日期
private Long online;//在线时长(分钟) private Long online;//在线时长(分钟)

@ -274,4 +274,15 @@ public class UserService {
User user = userDao.findByMobile(mobile); User user = userDao.findByMobile(mobile);
return user; return user;
} }
public UserVO touristLogin() {
UserVO userVO=new UserVO();
userVO.setId(String.valueOf(idWorker.nextId()));
userVO.setNickname(RandomSource.personInfoSource().randomChineseNickName(8));
userVO.setAvatar("default");
String token = jwtUtil.createJWT(userVO.getId(),"tourist","tourist");
userVO.setToken(token);
return userVO;
}
} }

Loading…
Cancel
Save