Merge branch 'backend' of https://github.com/TeamBNBN/edufocus into be/Quiz
This commit is contained in:
commit
fbcaff40dd
@ -1,5 +1,7 @@
|
|||||||
package com.edufocus.edufocus.user.controller;
|
package com.edufocus.edufocus.user.controller;
|
||||||
|
|
||||||
|
import com.edufocus.edufocus.user.model.entity.InfoDto;
|
||||||
|
import com.edufocus.edufocus.user.model.entity.PasswordDto;
|
||||||
import com.edufocus.edufocus.user.model.entity.User;
|
import com.edufocus.edufocus.user.model.entity.User;
|
||||||
import com.edufocus.edufocus.user.model.service.UserService;
|
import com.edufocus.edufocus.user.model.service.UserService;
|
||||||
import com.edufocus.edufocus.user.util.JWTUtil;
|
import com.edufocus.edufocus.user.util.JWTUtil;
|
||||||
@ -42,7 +44,30 @@ public class UserController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("/updateinfo/{id}")
|
||||||
|
public ResponseEntity<String> updateUserInfo(
|
||||||
|
@PathVariable("id") Long id,
|
||||||
|
@RequestBody InfoDto infoDto) {
|
||||||
|
try {
|
||||||
|
userService.changeuInfo(infoDto, id);
|
||||||
|
return ResponseEntity.ok("User info updated successfully");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseEntity.badRequest().body(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 비밀번호 변경
|
||||||
|
@PutMapping("/updatepassword/{id}")
|
||||||
|
public ResponseEntity<String> updatePassword(
|
||||||
|
@PathVariable("id") Long id,
|
||||||
|
@RequestBody PasswordDto passwordDto) {
|
||||||
|
try {
|
||||||
|
userService.changePassword(passwordDto, id);
|
||||||
|
return ResponseEntity.ok("Password changed successfully");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseEntity.badRequest().body(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
@Operation(summary = "로그인", description = "아이디와 비밀번호를 이용하여 로그인 처리.")
|
@Operation(summary = "로그인", description = "아이디와 비밀번호를 이용하여 로그인 처리.")
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public ResponseEntity<Map<String, Object>> login(
|
public ResponseEntity<Map<String, Object>> login(
|
||||||
|
@ -1,8 +1,15 @@
|
|||||||
package com.edufocus.edufocus.user.model.entity;
|
package com.edufocus.edufocus.user.model.entity;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
|
||||||
public class InfoDto {
|
public class InfoDto {
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
String email;
|
String email;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.edufocus.edufocus.user.model.entity;
|
||||||
|
|
||||||
|
import lombok.Generated;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class PasswordDto {
|
||||||
|
|
||||||
|
String currentPassword;
|
||||||
|
String newPassword;
|
||||||
|
String newPasswordCheck;
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package com.edufocus.edufocus.user.model.service;
|
package com.edufocus.edufocus.user.model.service;
|
||||||
|
|
||||||
|
import com.edufocus.edufocus.user.model.entity.InfoDto;
|
||||||
|
import com.edufocus.edufocus.user.model.entity.PasswordDto;
|
||||||
import com.edufocus.edufocus.user.model.entity.User;
|
import com.edufocus.edufocus.user.model.entity.User;
|
||||||
|
|
||||||
public interface UserService {
|
public interface UserService {
|
||||||
@ -12,7 +14,7 @@ public interface UserService {
|
|||||||
void sendEamail(User user) throws Exception;
|
void sendEamail(User user) throws Exception;
|
||||||
void userCheck(Long id) throws Exception;
|
void userCheck(Long id) throws Exception;
|
||||||
String getUserName(Long id) throws Exception;
|
String getUserName(Long id) throws Exception;
|
||||||
void changeuInfo(Long id) throws Exception;
|
void changeuInfo(InfoDto infoDto,Long id) throws Exception;
|
||||||
void changePassword(Long id) throws Exception;
|
void changePassword(PasswordDto passwordDto,Long id) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package com.edufocus.edufocus.user.model.service;
|
package com.edufocus.edufocus.user.model.service;
|
||||||
|
|
||||||
|
|
||||||
import com.edufocus.edufocus.user.model.entity.MailDto;
|
import com.edufocus.edufocus.user.model.entity.*;
|
||||||
import com.edufocus.edufocus.user.model.entity.MemberChangeDto;
|
|
||||||
import com.edufocus.edufocus.user.model.entity.User;
|
|
||||||
import com.edufocus.edufocus.user.model.exception.UserException;
|
import com.edufocus.edufocus.user.model.exception.UserException;
|
||||||
import com.edufocus.edufocus.user.model.repository.UserRepository;
|
import com.edufocus.edufocus.user.model.repository.UserRepository;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
@ -28,39 +26,31 @@ public class UserServiceImpl implements UserService{
|
|||||||
private final JavaMailSender mailSender;
|
private final JavaMailSender mailSender;
|
||||||
|
|
||||||
|
|
||||||
|
public void join(User user) {
|
||||||
public void join(User user)
|
|
||||||
{
|
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public User login(User user) throws SQLException
|
public User login(User user) throws SQLException {
|
||||||
{
|
|
||||||
Optional<User> findUser = userRepository.findByUserId(user.getUserId());
|
Optional<User> findUser = userRepository.findByUserId(user.getUserId());
|
||||||
|
|
||||||
|
|
||||||
if(findUser.isEmpty())
|
if (findUser.isEmpty()) {
|
||||||
{
|
|
||||||
throw new UserException("없는 유저");
|
throw new UserException("없는 유저");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(findUser.isPresent())
|
if (findUser.isPresent()) {
|
||||||
{
|
|
||||||
|
|
||||||
User find = findUser.get();
|
User find = findUser.get();
|
||||||
if(find.getPassword().equals(user.getPassword()))
|
if (find.getPassword().equals(user.getPassword())) {
|
||||||
{
|
|
||||||
return find;
|
return find;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
throw new UserException("비밀번호 틀림");
|
throw new UserException("비밀번호 틀림");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
throw new UserException("없는 유저");
|
throw new UserException("없는 유저");
|
||||||
|
|
||||||
|
|
||||||
@ -69,13 +59,10 @@ public class UserServiceImpl implements UserService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User userInfo(Long id)
|
public User userInfo(Long id) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
return userRepository.findById(id).get();
|
return userRepository.findById(id).get();
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw new UserException(e.getMessage());
|
throw new UserException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +76,6 @@ public class UserServiceImpl implements UserService{
|
|||||||
SimpleMailMessage message = new SimpleMailMessage();
|
SimpleMailMessage message = new SimpleMailMessage();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
message.setTo(mailDto.getAddress());
|
message.setTo(mailDto.getAddress());
|
||||||
message.setFrom("passfinder111@gmail.com");
|
message.setFrom("passfinder111@gmail.com");
|
||||||
message.setSubject(mailDto.getTitle());
|
message.setSubject(mailDto.getTitle());
|
||||||
@ -125,13 +111,11 @@ public class UserServiceImpl implements UserService{
|
|||||||
User user = userRepository.findById(id).orElse(null);
|
User user = userRepository.findById(id).orElse(null);
|
||||||
|
|
||||||
|
|
||||||
if(user == null)
|
if (user == null) {
|
||||||
{
|
|
||||||
System.out.println("불가");
|
System.out.println("불가");
|
||||||
throw new RuntimeException("유효하지 않은 아이디입니다. 다시 입력하세요");
|
throw new RuntimeException("유효하지 않은 아이디입니다. 다시 입력하세요");
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
|
|
||||||
sendEamail(user);
|
sendEamail(user);
|
||||||
}
|
}
|
||||||
@ -143,16 +127,48 @@ public class UserServiceImpl implements UserService{
|
|||||||
return userRepository.findById(id).get().getName();
|
return userRepository.findById(id).get().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void changeuInfo(Long id) throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void changePassword(Long id) throws Exception {
|
public void changeuInfo(InfoDto infoDto, Long id) throws Exception {
|
||||||
|
|
||||||
|
User user = userRepository.findById(id).orElse(null);
|
||||||
|
|
||||||
|
if (user == null) {
|
||||||
|
throw new Exception("User not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (infoDto.getName() != null)
|
||||||
|
{
|
||||||
|
user.setName(infoDto.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(infoDto.getEmail()!=null)
|
||||||
|
{
|
||||||
|
user.setEmail(infoDto.getEmail());
|
||||||
|
}
|
||||||
|
userRepository.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changePassword(PasswordDto passwordDto, Long id) throws Exception {
|
||||||
|
User user = userRepository.findById(id).orElse(null);
|
||||||
|
|
||||||
|
if (user == null) {
|
||||||
|
throw new Exception("User not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user.getPassword().equals(passwordDto.getCurrentPassword())) {
|
||||||
|
throw new Exception("Current password is incorrect");
|
||||||
|
} else {
|
||||||
|
if (!passwordDto.getNewPassword().equals(passwordDto.getNewPasswordCheck())) {
|
||||||
|
throw new Exception("New password confirmation does not match");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
user.setPassword(passwordDto.getNewPassword());
|
||||||
|
userRepository.save(user);
|
||||||
|
}
|
||||||
public String getTempPassword() {
|
public String getTempPassword() {
|
||||||
char[] charSet = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
|
char[] charSet = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
|
||||||
'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
|
'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
|
||||||
|
Loading…
Reference in New Issue
Block a user