Last change
on this file since 57e58a3 was 57e58a3, checked in by ste08 <sjovanoska@…>, 4 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | package com.example.skychasemk.services;
|
---|
2 |
|
---|
3 | import com.example.skychasemk.dto.ApplicationUserDTO;
|
---|
4 | import com.example.skychasemk.model.ApplicationUser;
|
---|
5 | import com.example.skychasemk.repository.ApplicationUserRepository;
|
---|
6 | import jakarta.transaction.Transactional;
|
---|
7 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
8 | import org.springframework.stereotype.Service;
|
---|
9 |
|
---|
10 | import java.time.Instant;
|
---|
11 | import java.time.LocalDate;
|
---|
12 | //import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
---|
13 |
|
---|
14 |
|
---|
15 | @Service
|
---|
16 | public class ApplicationUserService {
|
---|
17 |
|
---|
18 | @Autowired
|
---|
19 | private ApplicationUserRepository userRepository;
|
---|
20 |
|
---|
21 | //private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
---|
22 |
|
---|
23 | @Transactional
|
---|
24 | public ApplicationUser registerUser(ApplicationUserDTO userDTO) {
|
---|
25 | if (userRepository.findByEmail(userDTO.getEmail()).isPresent()) {
|
---|
26 | throw new RuntimeException("Email already registered");
|
---|
27 | }
|
---|
28 |
|
---|
29 | ApplicationUser user = new ApplicationUser();
|
---|
30 | user.setName(userDTO.getName());
|
---|
31 | user.setSurname(userDTO.getSurname());
|
---|
32 | user.setEmail(userDTO.getEmail());
|
---|
33 | user.setPassword(userDTO.getPassword());
|
---|
34 | user.setPhoneNumber(userDTO.getPhoneNumber());
|
---|
35 | ApplicationUser savedUser = userRepository.save(user);
|
---|
36 | userRepository.flush();
|
---|
37 | return savedUser;
|
---|
38 | }
|
---|
39 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.