add loginWithPassword
This commit is contained in:
parent
9f56a86116
commit
3a965937ab
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -2,6 +2,7 @@ package com.imooc.controller;
|
||||
|
||||
import com.imooc.base.BaseInfoProperties;
|
||||
import com.imooc.bo.RegistLoginBO;
|
||||
import com.imooc.bo.LoginWithPasswordBO;
|
||||
import com.imooc.grace.result.GraceJSONResult;
|
||||
import com.imooc.grace.result.ResponseStatusEnum;
|
||||
import com.imooc.pojo.Users;
|
||||
@ -70,6 +71,7 @@ public class PassportController extends BaseInfoProperties {
|
||||
user = userService.createUser(registLoginBO.getMobile());
|
||||
}
|
||||
String uToken = UUID.randomUUID().toString();
|
||||
log.info(uToken);
|
||||
redis.set(REDIS_USER_TOKEN+":"+user.getId(),uToken);
|
||||
|
||||
//清除验证码
|
||||
@ -84,6 +86,30 @@ public class PassportController extends BaseInfoProperties {
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("loginWithPassword")
|
||||
public Object loginWithPassword(@Valid @RequestBody LoginWithPasswordBO loginWithPasswordBO){
|
||||
String phone = loginWithPasswordBO.getMobile();
|
||||
String password = loginWithPasswordBO.getPassword();
|
||||
log.info(phone);
|
||||
log.info(password);
|
||||
Users user = userService.queryMobileIsExist(loginWithPasswordBO.getMobile());
|
||||
if (user==null){
|
||||
return GraceJSONResult.errorCustom(ResponseStatusEnum.USER_NOT_EXIST_ERROR);
|
||||
}
|
||||
String uToken = UUID.randomUUID().toString();
|
||||
log.info(uToken);
|
||||
redis.set(REDIS_USER_TOKEN+":"+user.getId(),uToken);
|
||||
|
||||
//返回给前端
|
||||
UsersVO usersVO = new UsersVO();
|
||||
BeanUtils.copyProperties(user, usersVO);
|
||||
usersVO.setUserToken(uToken);
|
||||
|
||||
return GraceJSONResult.ok(usersVO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("logout")
|
||||
public Object logout(@RequestParam String userId){
|
||||
|
||||
|
@ -21,5 +21,7 @@
|
||||
<result column="can_imooc_num_be_updated" property="canImoocNumBeUpdated" jdbcType="INTEGER" />
|
||||
<result column="created_time" property="createdTime" jdbcType="TIMESTAMP" />
|
||||
<result column="updated_time" property="updatedTime" jdbcType="TIMESTAMP" />
|
||||
<result column="password" property="password" jdbcType="VARCHAR" />
|
||||
|
||||
</resultMap>
|
||||
</mapper>
|
@ -0,0 +1,30 @@
|
||||
package com.imooc.bo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* 密码登陆中, 对前端数据映射的实体类.
|
||||
*
|
||||
* @author lzc
|
||||
* @version 1.0
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LoginWithPasswordBO {
|
||||
|
||||
@NotBlank(message = "账号不能为空!")
|
||||
@Length(min = 5, max = 16, message = "账号格式不正确!")
|
||||
private String mobile;
|
||||
|
||||
@NotBlank(message = "密码不能为空!")
|
||||
@Length(min = 5, max = 16, message = "密码格式不正确!")
|
||||
private String password;
|
||||
|
||||
}
|
@ -13,11 +13,14 @@ public class Users {
|
||||
*/
|
||||
private String mobile;
|
||||
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 昵称,媒体号
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
|
||||
/**
|
||||
* 慕课号,类似头条号,抖音号,公众号,唯一标识,需要限制修改次数,比如终生1次,每年1次,每半年1次等,可以用于付费修改。
|
||||
*/
|
||||
@ -371,4 +374,12 @@ public class Users {
|
||||
public void setUpdatedTime(Date updatedTime) {
|
||||
this.updatedTime = updatedTime;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
}
|
@ -24,6 +24,10 @@
|
||||
<artifactId>book-mapper</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-crypto</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -18,6 +18,9 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@ -30,6 +33,7 @@ public class UserServiceImpl implements UserService {
|
||||
@Autowired
|
||||
private UsersMapper usersMapper;
|
||||
|
||||
|
||||
@Autowired
|
||||
private Sid sid;
|
||||
private static final String USER_FACE1 = "http://122.152.205.72:88/group1/M00/00/05/CpoxxF6ZUySASMbOAABBAXhjY0Y649.png";
|
||||
@ -50,22 +54,21 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
Users user = new Users();
|
||||
user.setId(userId);
|
||||
|
||||
user.setPassword(mobile);
|
||||
user.setMobile(mobile);
|
||||
user.setNickname("用户:" + DesensitizationUtil.commonDisplay(mobile));
|
||||
user.setImoocNum("用户:" + DesensitizationUtil.commonDisplay(mobile));
|
||||
user.setFace(USER_FACE1);
|
||||
|
||||
user.setBirthday(DateUtil.stringToDate("1900-01-01"));
|
||||
user.setBirthday(DateUtil.stringToDate("1999-01-01"));
|
||||
user.setSex(Sex.secret.type);
|
||||
|
||||
user.setBgImg("http://82.156.121.2:29000/bucket/IMG20241212102441.jpg"); // 测试用地址
|
||||
user.setCountry("中国");
|
||||
user.setProvince("");
|
||||
user.setCity("");
|
||||
user.setDistrict("");
|
||||
user.setDescription("这家伙很懒,什么都没留下~");
|
||||
user.setCanImoocNumBeUpdated(YesOrNo.YES.type);
|
||||
|
||||
user.setCreatedTime(new Date());
|
||||
user.setUpdatedTime(new Date());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user