parent
5f6ff0f9ac
commit
603d85f591
@ -1,22 +1,56 @@
|
||||
// package com.cmkg.cmkg.Controller;
|
||||
package com.cmkg.cmkg.Controller;
|
||||
|
||||
|
||||
// import com.cmkg.cmkg.database.ReturnData;
|
||||
// import org.springframework.data.repository.query.Param;
|
||||
// import org.springframework.web.bind.annotation.RequestMapping;
|
||||
// import org.springframework.web.bind.annotation.RequestParam;
|
||||
import com.cmkg.cmkg.database.user;
|
||||
import com.cmkg.cmkg.repository.Login_Register_Repository;
|
||||
import com.cmkg.cmkg.server.ReturnData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
// @RequestMapping("/request")
|
||||
// public class LoginRegisterController {
|
||||
@RestController
|
||||
@RequestMapping("/request")
|
||||
public class LoginRegisterController {
|
||||
|
||||
// @RequestMapping("/login")
|
||||
// public ReturnData LoginGet(@RequestParam("phonenumber") String phonenumber, @RequestParam("password") String password){
|
||||
@Autowired
|
||||
Login_Register_Repository login_register_repository;
|
||||
|
||||
// }
|
||||
@RequestMapping("/login")
|
||||
public ReturnData LoginGet(@RequestParam("phonenumber") String phonenumber, @RequestParam("password") String password){
|
||||
ReturnData returnData=new ReturnData();
|
||||
user user=login_register_repository.findById(phonenumber).orElse(null);
|
||||
if(user==null){
|
||||
returnData.setMsg("该用户不存在");
|
||||
}
|
||||
else{
|
||||
if(user.getPassword().equals(password)){
|
||||
returnData.setMsg("登录成功");
|
||||
returnData.setData(user.getUsername());
|
||||
}else{
|
||||
returnData.setData("密码错误,登陆失败");
|
||||
}
|
||||
}
|
||||
return returnData;
|
||||
|
||||
// @RequestMapping("/register")
|
||||
// public ReturnData RegisterGet(@RequestParam("phonenumber") String phonenumber, @RequestParam("username") String username,@RequestParam("password") String password,
|
||||
// @RequestParam("region") String region, @RequestParam("age") Long age){
|
||||
}
|
||||
|
||||
// }
|
||||
// }
|
||||
@RequestMapping("/register")
|
||||
public ReturnData RegisterGet(@RequestParam("phonenumber") String phonenumber, @RequestParam("username") String username,@RequestParam("password") String password,
|
||||
@RequestParam("region") String region, @RequestParam("age") Integer age,@RequestParam("sex") Integer sex){
|
||||
ReturnData returnData=new ReturnData();
|
||||
user user=login_register_repository.findById(phonenumber).orElse(null);
|
||||
if(user==null) {
|
||||
login_register_repository.save(new user(phonenumber, username, password, age, sex, region));
|
||||
returnData.setCode(200);
|
||||
returnData.setMsg("注册成功");
|
||||
returnData.setData(null);
|
||||
}else{
|
||||
returnData.setCode(404);
|
||||
returnData.setMsg("注册失败");
|
||||
returnData.setData(null);
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue