diff --git a/Moonlight/App/Models/Forms/UserDataModel.cs b/Moonlight/App/Models/Forms/UserDataModel.cs new file mode 100644 index 00000000..bc2ff8ef --- /dev/null +++ b/Moonlight/App/Models/Forms/UserDataModel.cs @@ -0,0 +1,27 @@ +using System.ComponentModel.DataAnnotations; + +namespace Moonlight.App.Models.Forms; + +public class UserDataModel +{ + [Required] + public string FirstName { get; set; } = ""; + + [Required] + public string LastName { get; set; } = ""; + + [Required] + public string Email { get; set; } = ""; + + [Required] + public string Address { get; set; } = ""; + + [Required] + public string City { get; set; } = ""; + + [Required] + public string State { get; set; } = ""; + + [Required] + public string Country { get; set; } = ""; +} \ No newline at end of file diff --git a/Moonlight/App/Models/Forms/UserRegisterModel.cs b/Moonlight/App/Models/Forms/UserRegisterModel.cs new file mode 100644 index 00000000..399ddb7d --- /dev/null +++ b/Moonlight/App/Models/Forms/UserRegisterModel.cs @@ -0,0 +1,21 @@ +using System.ComponentModel.DataAnnotations; + +namespace Moonlight.App.Models.Forms; + +public class UserRegisterModel +{ + [Required, EmailAddress] + public string Email { get; set; } + + [Required, MinLength(3)] + public string FirstName { get; set; } + + [Required, MinLength(3)] + public string LastName { get; set; } + + [Required] + public string Password { get; set; } + + [Required] + public string ConfirmPassword { get; set; } +} \ No newline at end of file diff --git a/Moonlight/Shared/Components/Auth/Register.razor b/Moonlight/Shared/Components/Auth/Register.razor index ab8010b8..0b284a2d 100644 --- a/Moonlight/Shared/Components/Auth/Register.razor +++ b/Moonlight/Shared/Components/Auth/Register.razor @@ -7,11 +7,17 @@ @using Moonlight.App.Services @using Moonlight.App.Services.OAuth2 +@using Moonlight.App.Models.Forms +@using Moonlight.App.Services.Interop +@using Moonlight.App.Services.Sessions @inject SmartTranslateService SmartTranslateService @inject GoogleOAuth2Service GoogleOAuth2Service @inject NavigationManager NavigationManager @inject DiscordOAuth2Service DiscordOAuth2Service +@inject AlertService AlertService +@inject UserService UserService +@inject CookieService CookieService
@@ -46,38 +52,44 @@
-
+
Or with email
+ + +
+ +
+ +
+
+ +
-
- -
+
+ +
+
-
- -
- -
- -
- -
- -
- -
- -
- -
- -
+
+
+ +
+
+ +
+
+ +
+ +
+
+
Already registered? @@ -93,6 +105,8 @@ @code { + private UserRegisterModel UserRegisterModel = new(); + private async Task DoGoogle() { var url = await GoogleOAuth2Service.GetUrl(); @@ -104,4 +118,21 @@ var url = await DiscordOAuth2Service.GetUrl(); NavigationManager.NavigateTo(url, true); } + + private async Task CreateUser() + { + if (UserRegisterModel.ConfirmPassword != UserRegisterModel.Password) + { + await AlertService.Error(SmartTranslateService.Translate("Passwords need to match")); + return; + } + + var token = await UserService.Register(UserRegisterModel.Email, UserRegisterModel.Password, UserRegisterModel.FirstName, UserRegisterModel.LastName); + await CookieService.SetValue("token", token, 10); + + if (NavigationManager.Uri.EndsWith("register")) + NavigationManager.NavigateTo("/", true); + else + NavigationManager.NavigateTo(NavigationManager.Uri, true); + } } diff --git a/Moonlight/Shared/Views/Profile/Index.razor b/Moonlight/Shared/Views/Profile/Index.razor index cb1451ce..ea552ff4 100644 --- a/Moonlight/Shared/Views/Profile/Index.razor +++ b/Moonlight/Shared/Views/Profile/Index.razor @@ -3,7 +3,9 @@ @using Moonlight.Shared.Components.Navigations @using Moonlight.App.Services.Sessions @using Moonlight.App.Database.Entities +@using Moonlight.App.Models.Forms @using Moonlight.App.Repositories +@using Moonlight.Shared.Components.Auth @inject IdentityService IdentityService @inject UserRepository UserRepository @@ -74,17 +76,32 @@ @code { - private User User = new User(); + private UserDataModel User = new UserDataModel(); + private User CurrentUser; private async Task Load(LazyLoader loader) { - User = await IdentityService.Get(); + CurrentUser = await IdentityService.Get(); + User.FirstName = CurrentUser.FirstName; + User.LastName = CurrentUser.LastName; + User.Email = CurrentUser.Email; + User.Address = CurrentUser.Address; + User.City = CurrentUser.City; + User.State = CurrentUser.State; + User.Country = CurrentUser.Country; } private Task Save() { - UserRepository.Update(User); + CurrentUser.FirstName = User.FirstName; + CurrentUser.LastName = User.LastName; + CurrentUser.Email = User.Email; + CurrentUser.Address = User.Address; + CurrentUser.City = User.City; + CurrentUser.State = User.State; + CurrentUser.Country = User.Country; + UserRepository.Update(CurrentUser); return Task.CompletedTask; } diff --git a/Moonlight/resources/lang/de_de.lang b/Moonlight/resources/lang/de_de.lang index 1b1909d6..47d35db4 100644 --- a/Moonlight/resources/lang/de_de.lang +++ b/Moonlight/resources/lang/de_de.lang @@ -536,3 +536,7 @@ Configure your domain;Configure your domain You reached the maximum amount of domains in your subscription;You reached the maximum amount of domains in your subscription You need to specify a shared domain;You need to specify a shared domain A domain with this name does already exist for this shared domain;A domain with this name does already exist for this shared domain +The Email field is required.;The Email field is required. +The Password field is required.;The Password field is required. +The ConfirmPassword field is required.;The ConfirmPassword field is required. +Passwords need to match;Passwords need to match