You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.8 KiB
55 lines
1.8 KiB
package com.bupt.note.Controller;
|
|
|
|
import com.bupt.note.Model.User;
|
|
import com.bupt.note.Repository.UserRepository;
|
|
import com.bupt.note.ResponseData.ResponseData;
|
|
import com.bupt.note.ResponseData.ResponseDataUtil;
|
|
import com.bupt.note.ResponseData.ResultEnums;
|
|
import com.bupt.note.dto.UserForm;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
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;
|
|
|
|
/**
|
|
* 用户接口
|
|
*/
|
|
@RestController
|
|
@RequestMapping(value = "/v1/api/users")
|
|
public class UserController {
|
|
|
|
@Autowired
|
|
UserRepository userRepository;
|
|
|
|
/**
|
|
* 注册用户
|
|
* @param user 用户信息
|
|
* @return
|
|
*/
|
|
@PostMapping("/sign_up")
|
|
public ResponseData signUp(@RequestBody UserForm user) {
|
|
User exist = userRepository.findByUserName(user.getUserName());
|
|
if (exist == null) {
|
|
userRepository.save(user.getUser());
|
|
User u = userRepository.findByUserName(user.getUserName());
|
|
return ResponseDataUtil.buildSuccess(u);
|
|
}
|
|
return ResponseDataUtil.buildError(ResultEnums.ErrUserNameConflict);
|
|
}
|
|
|
|
/**
|
|
* 登录用户
|
|
* @param user 用户信息
|
|
* @return
|
|
*/
|
|
@PostMapping("/sign_in")
|
|
public ResponseData signIn(@RequestBody UserForm user){
|
|
User exist = userRepository.findByUserName(user.getUserName());
|
|
if(exist==null||!exist.getPassword().equals(user.getPassword())){
|
|
return ResponseDataUtil.buildError(ResultEnums.ERROR);
|
|
}else {
|
|
return ResponseDataUtil.buildSuccess(ResultEnums.SUCCESS);
|
|
}
|
|
}
|
|
}
|
|
|