|
|
@ -5,12 +5,13 @@ import com.bupt.note.Repository.UserRepository; |
|
|
|
import com.bupt.note.ResponseData.ResponseData; |
|
|
|
import com.bupt.note.ResponseData.ResponseData; |
|
|
|
import com.bupt.note.ResponseData.ResponseDataUtil; |
|
|
|
import com.bupt.note.ResponseData.ResponseDataUtil; |
|
|
|
import com.bupt.note.ResponseData.ResultEnums; |
|
|
|
import com.bupt.note.ResponseData.ResultEnums; |
|
|
|
|
|
|
|
import com.bupt.note.dto.UpdatePwd; |
|
|
|
import com.bupt.note.dto.UserForm; |
|
|
|
import com.bupt.note.dto.UserForm; |
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 用户接口 |
|
|
|
* 用户接口 |
|
|
@ -22,6 +23,8 @@ public class UserController { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
UserRepository userRepository; |
|
|
|
UserRepository userRepository; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Logger logger= LoggerFactory.getLogger(UserController.class); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 注册用户 |
|
|
|
* 注册用户 |
|
|
|
* @param user 用户信息 |
|
|
|
* @param user 用户信息 |
|
|
@ -29,8 +32,7 @@ public class UserController { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@PostMapping("/sign_up") |
|
|
|
@PostMapping("/sign_up") |
|
|
|
public ResponseData signUp(@RequestBody UserForm user) { |
|
|
|
public ResponseData signUp(@RequestBody UserForm user) { |
|
|
|
User exist = userRepository.findByUserName(user.getUserName()); |
|
|
|
if (!userRepository.existsByUserName(user.getUserName())) { |
|
|
|
if (exist == null) { |
|
|
|
|
|
|
|
userRepository.save(user.getUser()); |
|
|
|
userRepository.save(user.getUser()); |
|
|
|
User u = userRepository.findByUserName(user.getUserName()); |
|
|
|
User u = userRepository.findByUserName(user.getUserName()); |
|
|
|
return ResponseDataUtil.buildSuccess(u); |
|
|
|
return ResponseDataUtil.buildSuccess(u); |
|
|
@ -45,11 +47,43 @@ public class UserController { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@PostMapping("/sign_in") |
|
|
|
@PostMapping("/sign_in") |
|
|
|
public ResponseData signIn(@RequestBody UserForm user){ |
|
|
|
public ResponseData signIn(@RequestBody UserForm user){ |
|
|
|
User exist = userRepository.findByUserName(user.getUserName()); |
|
|
|
if(StringUtils.isNoneEmpty(user.getUserName(),user.getPassword())&& |
|
|
|
if(exist==null||!exist.getPassword().equals(user.getPassword())){ |
|
|
|
userRepository.existsByUserName(user.getUserName())){ |
|
|
|
|
|
|
|
User exists= userRepository.findByUserName(user.getUserName()); |
|
|
|
|
|
|
|
if(user.getPassword().equals(exists.getPassword())){ |
|
|
|
|
|
|
|
return ResponseDataUtil.buildError(ResultEnums.SUCCESS); |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
logger.error("账号或者密码错误"); |
|
|
|
return ResponseDataUtil.buildError(ResultEnums.ERROR); |
|
|
|
return ResponseDataUtil.buildError(ResultEnums.ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
}else { |
|
|
|
}else { |
|
|
|
return ResponseDataUtil.buildSuccess(ResultEnums.SUCCESS); |
|
|
|
logger.error("登陆校验失败"); |
|
|
|
|
|
|
|
return ResponseDataUtil.buildSuccess(ResultEnums.ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 修改密码 |
|
|
|
|
|
|
|
* @param user |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@PutMapping("update") |
|
|
|
|
|
|
|
public ResponseData put(@RequestBody UpdatePwd user,@CookieValue("user") String username){ |
|
|
|
|
|
|
|
if(StringUtils.isNoneEmpty(username,user.getOldpwd(),user.getNewpwd())&& |
|
|
|
|
|
|
|
userRepository.existsByUserName(username)){ |
|
|
|
|
|
|
|
User exists= userRepository.findByUserName(username); |
|
|
|
|
|
|
|
if(user.getOldpwd().equals(exists.getPassword())){ |
|
|
|
|
|
|
|
exists.setPassword(user.getNewpwd()); |
|
|
|
|
|
|
|
userRepository.save(exists); |
|
|
|
|
|
|
|
return ResponseDataUtil.buildSuccess(); |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
logger.error("原密码错误"); |
|
|
|
|
|
|
|
return ResponseDataUtil.buildError("原密码错误"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
logger.error("修改密码表单校验失败"); |
|
|
|
|
|
|
|
return ResponseDataUtil.buildError(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|