Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed email related things #63

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/main/java/com/pecacm/backend/controllers/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.pecacm.backend.model.AuthenticationRequest;
import com.pecacm.backend.response.AuthenticationResponse;
import com.pecacm.backend.response.RegisterResponse;
import com.pecacm.backend.services.EmailService;
import com.pecacm.backend.services.VerificationService;
import com.pecacm.backend.services.JwtService;
import com.pecacm.backend.services.UserService;
import org.springframework.data.domain.Page;
Expand All @@ -25,15 +25,13 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;

import java.awt.print.Pageable;
import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/v1/user")
public class UserController {

private final EmailService emailService;
private final VerificationService verificationService;

private final UserService userService;

Expand All @@ -43,8 +41,8 @@ public class UserController {

private final PasswordEncoder passwordEncoder;

public UserController(EmailService emailService, UserService userService, JwtService jwtService, AuthenticationManager authenticationManager, PasswordEncoder passwordEncoder) {
this.emailService = emailService;
public UserController(VerificationService verificationService, UserService userService, JwtService jwtService, AuthenticationManager authenticationManager, PasswordEncoder passwordEncoder) {
this.verificationService = verificationService;
this.userService = userService;
this.jwtService = jwtService;
this.authenticationManager = authenticationManager;
Expand All @@ -55,8 +53,7 @@ public UserController(EmailService emailService, UserService userService, JwtSer
@PreAuthorize(Constants.HAS_ANY_ROLE)
public ResponseEntity<RegisterResponse> registerUser(@RequestBody User user) {
userService.addUser(user, passwordEncoder);
// emailService.sendVerificationEmail(newUser); REASON : too much latency
VerificationToken token = emailService.getVerificationToken(user);
VerificationToken token = verificationService.getVerificationToken(user);
return ResponseEntity.status(HttpStatus.CREATED).body(new RegisterResponse(token.getToken().toString()));
}

Expand Down
48 changes: 0 additions & 48 deletions src/main/java/com/pecacm/backend/services/EmailService.java

This file was deleted.

26 changes: 26 additions & 0 deletions src/main/java/com/pecacm/backend/services/VerificationService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.pecacm.backend.services;

import com.pecacm.backend.entities.User;
import com.pecacm.backend.entities.VerificationToken;
import com.pecacm.backend.repository.VerificationTokenRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class VerificationService {

private final VerificationTokenRepository verificationTokenRepository;

@Autowired
public VerificationService(VerificationTokenRepository verificationTokenRepository) {
this.verificationTokenRepository = verificationTokenRepository;
}

@Transactional
public VerificationToken getVerificationToken(User user) {
return verificationTokenRepository.save(
VerificationToken.builder().user(user).build()
);
}
}
12 changes: 1 addition & 11 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@ spring:
show-sql: true
use_sql_comments: true
database-platform: org.hibernate.dialect.PostgreSQLDialect
mail:
host: smtp.gmail.com
port: 587
username: your_email
password: your_app_password
properties:
mail:
smtp:
auth: true
starttls:
enable: true

verify:
base:
frontend: http://localhost:3000/
12 changes: 0 additions & 12 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ spring:
show-sql: true
use_sql_comments: true
database-platform: org.hibernate.dialect.PostgreSQLDialect
mail:
host: smtp.gmail.com
port: 587
username: ${SMTP_EMAIL}
password: ${SMTP_PASSWORD}
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true

jwt:
secret: nyanpasu
Expand Down