release-新增userInfo表可根据userName和password登录

release-2024-08-08
pikaqiudeshujia 7 months ago
parent a0732031b1
commit 458d4c9f30

@ -2,10 +2,7 @@ package com.luoo.user.controller;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
@ -65,6 +62,9 @@ public class LoginController extends BaseController {
@Autowired
private WeChatAouth2Service weChatAouth2Service;
@Autowired
private JwtUtil jwtUtil;
/**
*
*
@ -360,4 +360,29 @@ public class LoginController extends BaseController {
public Result<Void> logout(@RequestHeader(value = "Authorization", required = true) String authorization){
return Result.success();
}
/**
* /
*
* @param userName
* @param password
* @return
*/
@ApiOperation(value = "通过用户名/密码登录")
@PostMapping("/login/{userName}/{password}")
public Result loginByUserName(@PathVariable String userName, @PathVariable String password) {
UserInfo userInfo = userInfoService.findByUserNameAndPassword(userName, password);
if (userInfo !=null) {
//生成token
String token = jwtUtil.createJWT(userInfo.getId(),userInfo.getUserName(),"artist","");
Map<String, Object> map = new HashMap<>();
map.put("token",token);
map.put("roles","artist");
map.put("name",userInfo.getUserName());
return Result.success(map);
} else {
return Result.failed(StatusCode.USER_NAME_OR_PASSWORD_FAILED);
}
}
}

@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
@ -21,7 +22,7 @@ public class ArtistRegisterDto implements Serializable {
private String nickName;
@ApiModelProperty(name = "艺人类型")
@NotBlank(message = "艺人类型必填")
@NotNull(message = "艺人类型必填")
private Integer type;
@ApiModelProperty(name = "艺人背景图片")
@ -48,7 +49,7 @@ public class ArtistRegisterDto implements Serializable {
private String responsibleName;
@ApiModelProperty(name = "性别")
@NotBlank(message = "负责人性别必填")
@NotNull(message = "负责人性别必填")
private Integer sex;
@ApiModelProperty(name = "负责人手机")

@ -11,6 +11,7 @@ import constants.Constants;
import enums.UserStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import util.IdWorker;
@ -44,6 +45,9 @@ public class ArtistService {
@Autowired
private IdWorker idWorker;
@Autowired
private BCryptPasswordEncoder encoder;
/**
*
*
@ -52,7 +56,7 @@ public class ArtistService {
public void artistRegister(ArtistRegisterDto artistRegisterDto) {
UserInfo userInfoByUserName = userInfoDao.findUserInfoByUserName(artistRegisterDto.getUserName());
if(userInfoByUserName == null) {
if(userInfoByUserName != null) {
throw new RuntimeException("该用户名已存在,请重新输入!");
}
@ -66,7 +70,7 @@ public class ArtistService {
.thumbnail(Constants.DEFAULT_USER_THUMBNAIL)
.signature(Constants.DEFAULT_USER_SIGNATURE)
.userName(artistRegisterDto.getUserName())
.password(artistRegisterDto.getPassword())
.password(encoder.encode(artistRegisterDto.getPassword()))
.build();
userInfoDao.save(userInfo);
@ -83,6 +87,7 @@ public class ArtistService {
// 新增音乐人负责人信息
ArtistResponsible artistResponsible = ArtistResponsible.builder()
.id(String.valueOf(idWorker.nextId()))
.userId(userInfo.getId())
.sex(artistRegisterDto.getSex())
.name(artistRegisterDto.getNickName())

@ -413,4 +413,19 @@ public class UserInfoService {
userInfoDao.save(userInfo);
}
/**
*
*
* @param userName
* @param password
* @return null
*/
public UserInfo findByUserNameAndPassword(String userName, String password) {
UserInfo userInfoByUserName = userInfoDao.findUserInfoByUserName(userName);
if(userInfoByUserName != null && encoder.matches(password, userInfoByUserName.getPassword())) {
return userInfoByUserName;
} else {
return null;
}
}
}

Loading…
Cancel
Save