Skip to content

Commit

Permalink
code formating upgraded
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper Jarocki committed Oct 21, 2023
1 parent fc5792b commit 427d4e1
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 182 deletions.
113 changes: 60 additions & 53 deletions server/src/main/java/server/service/AccountsService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package server.service;

import server.email.token.EmailConfirmationToken;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import server.email.token.EmailConfirmationToken;
import server.email.token.EmailConfirmationTokenService;
import server.exceptions.RegisterRequestException;
import server.model.Accounts;
Expand All @@ -17,61 +17,68 @@
@Service
@RequiredArgsConstructor
public class AccountsService {
public final AccountsRepository accountsRepository;
public final EmailConfirmationTokenService emailConfirmationTokenService;
private final PasswordEncoder passwordEncoder;
public List<Accounts> getAccounts() {return accountsRepository.findAll();}
public Accounts getAccount(int id){return accountsRepository.findById(id).orElseThrow();}
public Accounts postAccount(Accounts Acc)
{
return accountsRepository.save(Acc);
}
public Accounts putAccount(Accounts Acc)
{
Accounts editedAcc = accountsRepository.findById(Acc.getAccountId()).orElseThrow();
editedAcc.setNameUser(Acc.getNameUser());
editedAcc.setPassword(Acc.getPassword());
editedAcc.setEmail(Acc.getEmail());
return editedAcc;
}
public void deleteAccount(Accounts acc)
{
accountsRepository.delete(acc);
}
public final AccountsRepository accountsRepository;
public final EmailConfirmationTokenService emailConfirmationTokenService;
private final PasswordEncoder passwordEncoder;

public List<Accounts> getAccounts() {
return accountsRepository.findAll();
}

public Accounts getAccount(int id) {
return accountsRepository.findById(id).orElseThrow();
}

public Accounts postAccount(Accounts Acc) {
return accountsRepository.save(Acc);
}

public Accounts putAccount(Accounts Acc) {
Accounts editedAcc = accountsRepository.findById(Acc.getAccountId()).orElseThrow();
editedAcc.setNameUser(Acc.getNameUser());
editedAcc.setPassword(Acc.getPassword());
editedAcc.setEmail(Acc.getEmail());
return editedAcc;
}

public void deleteAccount(Accounts acc) {
accountsRepository.delete(acc);
}

public String signUpUser(Accounts accounts) {

public String signUpUser(Accounts accounts) {
String token = UUID.randomUUID().toString();

String token = UUID.randomUUID().toString();
EmailConfirmationToken emailConfirmationToken = new EmailConfirmationToken(
token,
LocalDateTime.now(),
LocalDateTime.now().plusMinutes(15),
accounts
);
emailConfirmationTokenService.saveConfirmationToken(
emailConfirmationToken);
return token;
}

EmailConfirmationToken emailConfirmationToken = new EmailConfirmationToken(
token,
LocalDateTime.now(),
LocalDateTime.now().plusMinutes(15),
accounts
);
emailConfirmationTokenService.saveConfirmationToken(
emailConfirmationToken);
return token;
}
public int enableAccounts(String email) {
return accountsRepository.enableAccounts(email);
}

public int enableAccounts(String email) {
return accountsRepository.enableAccounts(email);
}
public void editEmail(Accounts acc) {
Accounts editedAcc = accountsRepository.findByNameUser(acc.getNameUser());
if (!editedAcc.getEmail().equals(acc.getEmail())) {
if (accountsRepository.existsByEmail(acc.getEmail())) {
throw new RegisterRequestException("Email already exists", HttpStatus.BAD_REQUEST);
}
}
editedAcc.setEmail(acc.getEmail());
accountsRepository.save(editedAcc);
}

public void editEmail(Accounts acc){
Accounts editedAcc = accountsRepository.findByNameUser(acc.getNameUser());
if(!editedAcc.getEmail().equals(acc.getEmail())) {
if (accountsRepository.existsByEmail(acc.getEmail())) {
throw new RegisterRequestException("Email already exists", HttpStatus.BAD_REQUEST);
}
}
editedAcc.setEmail(acc.getEmail());
accountsRepository.save(editedAcc);
}
public void editPassword(Accounts acc){
Accounts editedAcc = accountsRepository.findByNameUser(acc.getNameUser());
editedAcc.setPassword(passwordEncoder.encode(acc.getPassword()));
accountsRepository.save(editedAcc);
}
public void editPassword(Accounts acc) {
Accounts editedAcc = accountsRepository.findByNameUser(acc.getNameUser());
editedAcc.setPassword(passwordEncoder.encode(acc.getPassword()));
accountsRepository.save(editedAcc);
}

}
}
Loading

0 comments on commit 427d4e1

Please sign in to comment.