Compare commits
5 Commits
441c984108
...
9b64f24a69
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b64f24a69 | |||
| a5e87f6964 | |||
| 9dac5ad484 | |||
| 5206c93083 | |||
| 9c7174e882 |
@ -0,0 +1,60 @@
|
|||||||
|
package org.cmh.backend.authentication.controller;
|
||||||
|
|
||||||
|
import org.cmh.backend.authentication.model.User;
|
||||||
|
import org.cmh.backend.authentication.service.UserService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.springframework.http.ResponseEntity.ok;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/users")
|
||||||
|
public class UserController {
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/tmdshabi")
|
||||||
|
public ResponseEntity<User> login(@RequestBody Map<String, String> credentials) {
|
||||||
|
String account = credentials.get("account");
|
||||||
|
String password = credentials.get("password");
|
||||||
|
System.out.println(account);
|
||||||
|
System.out.println(password);
|
||||||
|
System.out.println("hahaha");
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
@PostMapping("/checkLogin")
|
||||||
|
public ResponseEntity<User> hahaha(@RequestBody Map<String, String> credentials){
|
||||||
|
String account = credentials.get("account");
|
||||||
|
String password = credentials.get("password");
|
||||||
|
System.out.println(account);
|
||||||
|
System.out.println(password);
|
||||||
|
System.out.println("hahaha");
|
||||||
|
System.out.println("hahaha");
|
||||||
|
User user = userService.getUserByAccountAndPassword(account, password);
|
||||||
|
//判断逻辑
|
||||||
|
System.out.println(user);
|
||||||
|
return ok(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/checkRegister")
|
||||||
|
public String register(@RequestBody User user) {
|
||||||
|
// String account = user.getAccount();
|
||||||
|
// String password = user.getPassword();
|
||||||
|
// String name = user.getName();
|
||||||
|
// String organization = user.getOrganization();
|
||||||
|
// String gender = user.getGender();
|
||||||
|
// String email = user.getEmail();
|
||||||
|
// String phone = user.getPhone();
|
||||||
|
|
||||||
|
System.out.println(user.toString());
|
||||||
|
|
||||||
|
if(userService.registerUser(user) != null){
|
||||||
|
return "注册成功";
|
||||||
|
}
|
||||||
|
return "注册错误";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,36 +4,66 @@ import jakarta.persistence.Entity;
|
|||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class User {
|
public class User {
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
private String username;
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private String account;
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
private String password;
|
private String password;
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private String name;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private String organization;
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private String gender;
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private String email;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
public User() {
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(Long id) {
|
public User(String account, String password, String name, String organization, String gender, String email, String phone) {
|
||||||
this.id = id;
|
this.account = account;
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String username) {
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
this.password = password;
|
||||||
|
this.name = name;
|
||||||
|
this.organization = organization;
|
||||||
|
this.gender = gender;
|
||||||
|
this.email = email;
|
||||||
|
this.phone = phone;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" +
|
||||||
|
"id=" + id +
|
||||||
|
", account='" + account + '\'' +
|
||||||
|
", password='" + password + '\'' +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
", organization='" + organization + '\'' +
|
||||||
|
", gender='" + gender + '\'' +
|
||||||
|
", email='" + email + '\'' +
|
||||||
|
", phone='" + phone + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -4,5 +4,7 @@ import org.cmh.backend.authentication.model.User;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface UserRepository extends JpaRepository<User, Long> {
|
public interface UserRepository extends JpaRepository<User, Long> {
|
||||||
User findByUsername(String username);
|
User findByAccount(String username);
|
||||||
|
User findByAccountAndPassword(String username, String password);
|
||||||
|
User save(User user);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,15 @@ public class UserService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
|
||||||
public User getUserByUsername(String username) {
|
public User getUserByAccount(String account) {
|
||||||
return userRepository.findByUsername(username);
|
return userRepository.findByAccount(account);
|
||||||
|
}
|
||||||
|
public User getUserByAccountAndPassword(String account, String password) {
|
||||||
|
return userRepository.findByAccountAndPassword(account, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public User registerUser(User user) {
|
||||||
|
User savedUser = userRepository.save(user);
|
||||||
|
return savedUser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user