-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #486 from bounswe/forgot-password
Forgot Password Implementation - BE
- Loading branch information
Showing
11 changed files
with
230 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/backend/src/main/java/com/app/gamereview/dto/request/VerifyResetCodeRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.app.gamereview.dto.request; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class VerifyResetCodeRequestDto { | ||
|
||
private String resetCode; | ||
|
||
private String userEmail; | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
app/backend/src/main/java/com/app/gamereview/model/ResetCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.app.gamereview.model; | ||
|
||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.index.Indexed; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
import java.util.Date; | ||
|
||
@Document(collection = "resetCodes") | ||
public class ResetCode { | ||
|
||
@Id | ||
private String id; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getCode() { | ||
return code; | ||
} | ||
|
||
public void setCode(String code) { | ||
this.code = code; | ||
} | ||
|
||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
public void setUser(String userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public Date getExpirationDate() { | ||
return expirationDate; | ||
} | ||
|
||
public void setExpirationDate(Date expirationDate) { | ||
this.expirationDate = expirationDate; | ||
} | ||
|
||
private String code; | ||
|
||
@Indexed(unique = true) // Ensures a unique constraint on userId field | ||
private String userId; // ID of the associated user | ||
|
||
private Date expirationDate; | ||
|
||
public ResetCode(String code, String userId, Date expirationDate) { | ||
|
||
this.code = code; | ||
this.userId = userId; | ||
this.expirationDate = expirationDate; | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
app/backend/src/main/java/com/app/gamereview/repository/ResetCodeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.app.gamereview.repository; | ||
|
||
import com.app.gamereview.model.ResetCode; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ResetCodeRepository extends MongoRepository<ResetCode, String> { | ||
|
||
ResetCode findByUserId(String userId); | ||
|
||
Optional<ResetCode> findByCode(String code); | ||
|
||
void deleteByUserId(String userId); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/backend/src/main/java/com/app/gamereview/service/EmailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.app.gamereview.service; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.mail.SimpleMailMessage; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class EmailService { | ||
|
||
@Autowired | ||
private JavaMailSender mailSender; | ||
|
||
public void sendEmail(String toEmail, String subject, String body) { | ||
SimpleMailMessage message = new SimpleMailMessage(); | ||
message.setFrom("[email protected]"); | ||
message.setTo(toEmail); | ||
message.setText(body); | ||
message.setSubject(subject); | ||
mailSender.send(message); | ||
System.out.println("Mail Send..."); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
MONGO_DATABASE= | ||
MONGO_USER= | ||
MONGO_PASSWORD= | ||
MONGO_CLUSTER= | ||
MAIL_HOST= | ||
MAIL_PORT= | ||
MAIL_USERNAME= | ||
MAIL_PASSWORD= | ||
MAIL_AUTH= | ||
MAIL_STARTTLS= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
spring.data.mongodb.database=${MONGO_DATABASE} | ||
spring.data.mongodb.uri=mongodb+srv://${MONGO_USER}:${MONGO_PASSWORD}@${MONGO_CLUSTER} | ||
spring.mail.host=${MAIL_HOST} | ||
spring.mail.port=${MAIL_PORT} | ||
spring.mail.username=${MAIL_USERNAME} | ||
spring.mail.password=${MAIL_PASSWORD} | ||
spring.mail.properties.mail.smtp.auth=${MAIL_AUTH} | ||
spring.mail.properties.mail.smtp.starttls.enable=${MAIL_STARTTLS} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
spring.data.mongodb.database=${MONGO_DATABASE} | ||
spring.data.mongodb.uri=mongodb+srv://${MONGO_USER}:${MONGO_PASSWORD}@${MONGO_CLUSTER} | ||
spring.mail.host=${MAIL_HOST} | ||
spring.mail.port=${MAIL_PORT} | ||
spring.mail.username=${MAIL_USERNAME} | ||
spring.mail.password=${MAIL_PASSWORD} | ||
spring.mail.properties.mail.smtp.auth=${MAIL_AUTH} | ||
spring.mail.properties.mail.smtp.starttls.enable=${MAIL_STARTTLS} |