-
Notifications
You must be signed in to change notification settings - Fork 8
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 #142 from FS-FAST-TRACK/feature/quizmaster-fronten…
…d-profile-maintenance Feature/quizmaster frontend profile maintenance
- Loading branch information
Showing
22 changed files
with
1,038 additions
and
9 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
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
87 changes: 87 additions & 0 deletions
87
WebApp/backend/QuizMaster.API.Account/Service/EmailSenderService.cs
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,87 @@ | ||
using Microsoft.Extensions.Options; | ||
using QuizMaster.API.Account.Configuration; | ||
using System.Net.Mail; | ||
using System.Net; | ||
|
||
namespace QuizMaster.API.Account.Service | ||
{ | ||
public class EmailSenderService | ||
{ | ||
private readonly ApplicationSettings _settings; | ||
public EmailSenderService(IOptions<ApplicationSettings> appsettings) | ||
{ | ||
_settings = appsettings.Value; | ||
} | ||
|
||
public void SendEmail(string email, string firstname, string token) | ||
{ | ||
MailMessage mailMessage = new MailMessage(); | ||
mailMessage.From = new MailAddress(_settings.SMTP_EMAIL, "🔎QuizMaster@no-reply", System.Text.Encoding.UTF8); | ||
mailMessage.To.Add(email); | ||
mailMessage.Subject = "Quiz Master Password Reset"; | ||
mailMessage.Body = @$" | ||
<html><body> | ||
<div style=""width: 400px""> | ||
<img | ||
style=""width: 400px; height: 84px"" | ||
src=""https://github.com/jaymar921/Public-Repo/blob/main/wave_fs_vector_1.png?raw=true"" | ||
/> | ||
<h3 style=""text-align: center; color: #18a44c""> | ||
Reset Password Confirmation | ||
</h3> | ||
<img | ||
style=""width: 400px; height: 300px"" | ||
src=""https://github.com/jaymar921/Public-Repo/blob/main/reset_pass_fs.png?raw=true"" | ||
/> | ||
<h3 style=""font-size: 18px; padding: 5px 20px 5px 20px"">Hello {firstname}</h3> | ||
<p style=""font-size: 14px; padding: 5px 20px 5px 20px""> | ||
You are receiving this email because you requested a change on your | ||
password. Click the button below to reset your password. | ||
</p> | ||
<div style=""padding: 5px 20px 5px 20px; text-align: center""> | ||
<a | ||
style="" | ||
background-color: #18a44c; | ||
color: white; | ||
padding: 10px; | ||
font-size: 14px; | ||
outline: none; | ||
border: none; | ||
border-radius: 4px; | ||
width: 500px; | ||
cursor: pointer; | ||
text-decoration: none; | ||
"" | ||
href='https://localhost:7081/gateway/api/account/update_password/{token}' | ||
> | ||
Confirm Reset | ||
Password | ||
</a> | ||
</div> | ||
<p style=""padding: 0px 20px 0px 20px; font-size: 12px; color: gray""> | ||
If you did not request a password reset, you can ignore this email. | ||
</p> | ||
<hr /> | ||
<p style=""padding: 0px 20px 0px 20px; font-size: 12px; color: gray""> | ||
Copyright 2023 Ⓒ QuizMaster | ||
</p> | ||
</div> | ||
</body></html> | ||
"; | ||
mailMessage.IsBodyHtml = true; | ||
|
||
// Create the credentials to login to the gmail account associated with my custom domain | ||
string sendEmailsFrom = _settings.SMTP_EMAIL; | ||
string sendEmailsFromPassword = _settings.SMTP_PASSWORD; | ||
NetworkCredential cred = new NetworkCredential(sendEmailsFrom, sendEmailsFromPassword); | ||
|
||
SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587); | ||
mailClient.EnableSsl = true; | ||
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network; | ||
mailClient.UseDefaultCredentials = false; | ||
mailClient.Timeout = 20000; | ||
mailClient.Credentials = cred; | ||
mailClient.Send(mailMessage); | ||
} | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
WebApp/backend/QuizMaster.API.Account/Service/PasswordHandler.cs
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,31 @@ | ||
namespace QuizMaster.API.Account.Service | ||
{ | ||
public class PasswordHandler | ||
{ | ||
private readonly IDictionary<string, IDictionary<string, string>> _passwordHolder; | ||
public PasswordHandler() { | ||
_passwordHolder = new Dictionary<string, IDictionary<string, string>>(); | ||
} | ||
|
||
public string GenerateToken(string userId,string currentPassword, string newPassword) | ||
{ | ||
string token = Guid.NewGuid().ToString(); | ||
IDictionary<string, string> Passwords = new Dictionary<string, string>(); | ||
Passwords["userId"] = userId; | ||
Passwords["currentPassword"] = currentPassword; | ||
Passwords["newPassword"] = newPassword; | ||
_passwordHolder[token] = Passwords; | ||
return token; | ||
} | ||
|
||
public (string, string, string) GetPassword(string guid) | ||
{ | ||
if(_passwordHolder.ContainsKey(guid)) | ||
{ | ||
var map = _passwordHolder[guid]; | ||
return (map["userId"], map["currentPassword"], map["newPassword"]); | ||
} | ||
return (string.Empty, string.Empty, string.Empty); | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -49,6 +49,7 @@ | |
|
||
<ItemGroup> | ||
<Folder Include="Migrations\" /> | ||
<Folder Include="sessionDb\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
8 changes: 8 additions & 0 deletions
8
WebApp/backend/QuizMaster.Library.Common/Models/Accounts/ChangePasswordDTO.cs
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,8 @@ | ||
namespace QuizMaster.Library.Common.Models.Accounts | ||
{ | ||
public class ChangePasswordDTO | ||
{ | ||
public string CurrentPassword { get; set; } = string.Empty; | ||
public string NewPassword { get; set; } = string.Empty; | ||
} | ||
} |
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
Oops, something went wrong.