✨ Reset password
This commit is contained in:
		
							
								
								
									
										65
									
								
								DysonNetwork.Sphere/Pages/Emails/PasswordResetEmail.razor
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								DysonNetwork.Sphere/Pages/Emails/PasswordResetEmail.razor
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,65 @@ | ||||
| @using DysonNetwork.Sphere.Localization | ||||
| @using Microsoft.Extensions.Localization | ||||
| @using EmailResource = DysonNetwork.Sphere.Localization.EmailResource | ||||
|  | ||||
| <EmailLayout> | ||||
|     <table class="container"> | ||||
|         <tr> | ||||
|             <td class="columns"> | ||||
|                 <h1 style="font-size: 1.875rem; font-weight: 700; color: #111827; margin: 0; text-align: center;"> | ||||
|                     @(Localizer["PasswordResetHeader"]) | ||||
|                 </h1> | ||||
|             </td> | ||||
|         </tr> | ||||
|  | ||||
|         <tr> | ||||
|             <td class="columns"> | ||||
|                 <p style="color: #374151; margin: 0;"> | ||||
|                     @(Localizer["PasswordResetPara1"]) @@@Name, | ||||
|                 </p> | ||||
|                 <p style="color: #374151; margin: 0;"> | ||||
|                     @(Localizer["PasswordResetPara2"]) | ||||
|                 </p> | ||||
|                 <p style="color: #374151; margin: 0;"> | ||||
|                     @(Localizer["PasswordResetPara3"]) | ||||
|                 </p> | ||||
|             </td> | ||||
|         </tr> | ||||
|  | ||||
|         <tr> | ||||
|             <td class="columns"> | ||||
|                 <div style="text-align: center;"> | ||||
|                     <a href="@Link" target="_blank" | ||||
|                        style="background-color: #2563eb; color: #ffffff; padding: 0.75rem 1.5rem; border-radius: 0.5rem; font-weight: 600; text-decoration: none;"> | ||||
|                         @(Localizer["PasswordResetButton"]) | ||||
|                     </a> | ||||
|                 </div> | ||||
|             </td> | ||||
|         </tr> | ||||
|  | ||||
|         <tr> | ||||
|             <td class="columns"> | ||||
|                 <p style="color: #374151; margin: 0;"> | ||||
|                     @(LocalizerShared["EmailLinkHint"]) | ||||
|                     <br> | ||||
|                     <a href="@Link" style="color: #2563eb; word-break: break-all;">@Link</a> | ||||
|                 </p> | ||||
|                 <p style="color: #374151; margin: 0;"> | ||||
|                     @(Localizer["PasswordResetPara4"]) | ||||
|                 </p> | ||||
|                 <p style="color: #374151; margin: 2rem 0 0 0;"> | ||||
|                     @(LocalizerShared["EmailFooter1"]) <br /> | ||||
|                     @(LocalizerShared["EmailFooter2"]) | ||||
|                 </p> | ||||
|             </td> | ||||
|         </tr> | ||||
|     </table> | ||||
| </EmailLayout> | ||||
|  | ||||
| @code { | ||||
|     [Parameter] public required string Name { get; set; } | ||||
|     [Parameter] public required string Link { get; set; } | ||||
|  | ||||
|     [Inject] IStringLocalizer<EmailResource> Localizer { get; set; } = null!; | ||||
|     [Inject] IStringLocalizer<SharedResource> LocalizerShared { get; set; } = null!; | ||||
| } | ||||
| @@ -1,4 +1,5 @@ | ||||
| @page "/spells/{spellWord}" | ||||
| @using DysonNetwork.Sphere.Account | ||||
| @model DysonNetwork.Sphere.Pages.Spell.MagicSpellPage | ||||
|  | ||||
| @{ | ||||
| @@ -25,11 +26,13 @@ | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 <div class="px-4 py-12 bg-white dark:bg-gray-800 text-gray-900 dark:text-white shadow-lg rounded-lg mb-6"> | ||||
|                 <div | ||||
|                     class="px-4 py-12 bg-white dark:bg-gray-800 text-gray-900 dark:text-white shadow-lg rounded-lg mb-6"> | ||||
|                     <div class="mb-2"> | ||||
|                         <p> | ||||
|                             <span class="font-medium">The spell is for </span> | ||||
|                             <span class="font-bold">@System.Text.RegularExpressions.Regex.Replace(Model.CurrentSpell!.Type.ToString(), "([a-z])([A-Z])", "$1 $2")</span> | ||||
|                             <span | ||||
|                                 class="font-bold">@System.Text.RegularExpressions.Regex.Replace(Model.CurrentSpell!.Type.ToString(), "([a-z])([A-Z])", "$1 $2")</span> | ||||
|                         </p> | ||||
|                         <p><span class="font-medium">for @@</span>@Model.CurrentSpell.Account?.Name</p> | ||||
|                     </div> | ||||
| @@ -48,6 +51,28 @@ | ||||
|  | ||||
|                 <form method="post" class="mt-4"> | ||||
|                     <input type="hidden" asp-for="CurrentSpell!.Id"/> | ||||
|  | ||||
|                     @if (Model.CurrentSpell?.Type == MagicSpellType.AuthPasswordReset) | ||||
|                     { | ||||
|                         <div class="mb-4"> | ||||
|                             <label | ||||
|                                 asp-for="NewPassword" | ||||
|                                 class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2" | ||||
|                             > | ||||
|                                 New Password | ||||
|                             </label> | ||||
|                             <input type="password" | ||||
|                                    asp-for="NewPassword" | ||||
|                                    required | ||||
|                                    minlength="8" | ||||
|                                    style="padding: 0.5rem 1rem" | ||||
|                                    placeholder="Your new password" | ||||
|                                    class="w-full border-2 border-gray-300 dark:border-gray-600 rounded-lg  | ||||
|                                           focus:ring-2 focus:ring-blue-400 | ||||
|                                           dark:text-white bg-gray-100 dark:bg-gray-800"/> | ||||
|                         </div> | ||||
|                     } | ||||
|  | ||||
|                     <button type="submit" | ||||
|                             class="px-6 py-3 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors | ||||
|                                    transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-blue-400"> | ||||
|   | ||||
| @@ -8,8 +8,8 @@ namespace DysonNetwork.Sphere.Pages.Spell; | ||||
|  | ||||
| public class MagicSpellPage(AppDatabase db, MagicSpellService spells) : PageModel | ||||
| { | ||||
|     [BindProperty] | ||||
|     public MagicSpell? CurrentSpell { get; set; } | ||||
|     [BindProperty] public MagicSpell? CurrentSpell { get; set; } | ||||
|     [BindProperty] public string? NewPassword { get; set; } | ||||
|  | ||||
|     public bool IsSuccess { get; set; } | ||||
|  | ||||
| @@ -39,10 +39,13 @@ public class MagicSpellPage(AppDatabase db, MagicSpellService spells) : PageMode | ||||
|             .Where(e => e.AffectedAt == null || now >= e.AffectedAt) | ||||
|             .FirstOrDefaultAsync(); | ||||
|  | ||||
|         if (spell == null) | ||||
|         if (spell == null || spell.Type == MagicSpellType.AuthPasswordReset && string.IsNullOrWhiteSpace(NewPassword)) | ||||
|             return Page(); | ||||
|  | ||||
|         await spells.ApplyMagicSpell(spell); | ||||
|         if (spell.Type == MagicSpellType.AuthPasswordReset) | ||||
|             await spells.ApplyPasswordReset(spell, NewPassword!); | ||||
|         else | ||||
|             await spells.ApplyMagicSpell(spell); | ||||
|         IsSuccess = true; | ||||
|         return Page(); | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user