[R9] Register user in auth service class
This commit is contained in:
parent
3adadc7489
commit
2685f95f80
@ -4,9 +4,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.mirna.hospitalmanagementapi.domain.dtos.auth.UserDTO;
|
||||
import com.mirna.hospitalmanagementapi.domain.entities.auth.User;
|
||||
import com.mirna.hospitalmanagementapi.domain.services.UserService;
|
||||
import com.mirna.hospitalmanagementapi.domain.services.auth.AuthService;
|
||||
|
||||
/**
|
||||
@ -23,10 +26,16 @@ public class AuthServiceImpl implements AuthService {
|
||||
@Autowired
|
||||
private AuthenticationManager manager;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
/**
|
||||
* Performs the user login
|
||||
*
|
||||
* @param userAuthDTO Data transfer object containing user credentials for authentication operations
|
||||
* @param userDTO Data transfer object containing user credentials for authentication operations
|
||||
* @return A fully authentication object including the credentials
|
||||
*/
|
||||
@Override
|
||||
@ -37,4 +46,19 @@ public class AuthServiceImpl implements AuthService {
|
||||
return manager.authenticate(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the user registration
|
||||
*
|
||||
* @param userDTO Data transfer object containing user credentials for authentication operations
|
||||
* @return A user object including the credentials
|
||||
*/
|
||||
@Override
|
||||
public User register(UserDTO userDTO) {
|
||||
|
||||
String encodedPassword = passwordEncoder.encode(userDTO.password());
|
||||
userDTO = new UserDTO(userDTO.login(), encodedPassword);
|
||||
|
||||
return this.userService.addUser(userDTO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.mirna.hospitalmanagementapi.domain.services.auth;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
||||
import com.mirna.hospitalmanagementapi.domain.dtos.auth.UserDTO;
|
||||
import com.mirna.hospitalmanagementapi.domain.entities.auth.User;
|
||||
|
||||
/**
|
||||
* Authentication service interface for managing authentication and registration.
|
||||
@ -20,4 +21,13 @@ public interface AuthService {
|
||||
* @return A fully authentication object including the credentials
|
||||
*/
|
||||
public Authentication login(UserDTO userDTO);
|
||||
|
||||
/**
|
||||
* Performs the user registration
|
||||
*
|
||||
* @param userDTO Data transfer object containing user credentials for authentication operations
|
||||
* @return A user object including the credentials
|
||||
*/
|
||||
public User register(UserDTO userDTO);
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user