personal/pjq/organization #3
@ -1,13 +0,0 @@
|
||||
package org.cmh.backend.authentication.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
class AuthenticationController {
|
||||
@GetMapping("/hello")
|
||||
public String hello(){
|
||||
return "Hello SpringBoot!";
|
||||
}
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
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 "注册错误";
|
||||
}
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
package org.cmh.backend.authentication.model;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
||||
@Entity
|
||||
public class User {
|
||||
@Setter
|
||||
@Getter
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
@Setter
|
||||
@Getter
|
||||
private String account;
|
||||
@Setter
|
||||
@Getter
|
||||
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 User(String account, String password, String name, String organization, String gender, String email, String phone) {
|
||||
this.account = account;
|
||||
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 + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
package org.cmh.backend.authentication.repository;
|
||||
|
||||
import org.cmh.backend.authentication.model.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface UserRepository extends JpaRepository<User, Long> {
|
||||
User findByAccount(String username);
|
||||
User findByAccountAndPassword(String username, String password);
|
||||
User save(User user);
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
package org.cmh.backend.authentication.service;
|
||||
|
||||
import org.cmh.backend.authentication.model.User;
|
||||
import org.cmh.backend.authentication.repository.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
public User getUserByAccount(String account) {
|
||||
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