Merge pull request #59 from Moonlight-Panel/Register

register
This commit is contained in:
Daniel Balk 2023-04-12 18:03:08 +02:00 committed by GitHub
commit 4434d5f7dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 129 additions and 29 deletions

View file

@ -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; } = "";
}

View file

@ -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; }
}

View file

@ -7,11 +7,17 @@
@using Moonlight.App.Services @using Moonlight.App.Services
@using Moonlight.App.Services.OAuth2 @using Moonlight.App.Services.OAuth2
@using Moonlight.App.Models.Forms
@using Moonlight.App.Services.Interop
@using Moonlight.App.Services.Sessions
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@inject GoogleOAuth2Service GoogleOAuth2Service @inject GoogleOAuth2Service GoogleOAuth2Service
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject DiscordOAuth2Service DiscordOAuth2Service @inject DiscordOAuth2Service DiscordOAuth2Service
@inject AlertService AlertService
@inject UserService UserService
@inject CookieService CookieService
<div class="d-flex flex-center"> <div class="d-flex flex-center">
<div class="card rounded-3 w-md-550px"> <div class="card rounded-3 w-md-550px">
@ -46,37 +52,43 @@
</div> </div>
</div> </div>
<div class="separator separator-content my-14"> <div class="separator separator-content my-10">
<span class="w-125px text-gray-500 fw-semibold fs-7"> <span class="w-125px text-gray-500 fw-semibold fs-7">
<TL>Or with email</TL> <TL>Or with email</TL>
</span> </span>
</div> </div>
<div class="fv-row mb-8 fv-plugins-icon-container"> <SmartForm Model="UserRegisterModel" OnValidSubmit="CreateUser">
<input type="text" placeholder="@(SmartTranslateService.Translate("Firstname"))" name="text" class="form-control bg-transparent"> <div class="fv-row mb-4 fv-plugins-icon-container">
<InputText @bind-Value="UserRegisterModel.Email" placeholder="@(SmartTranslateService.Translate("Email"))" name="email" autocomplete="off" class="form-control bg-transparent" />
</div> </div>
<div class="fv-row mb-8 fv-plugins-icon-container"> <div class="row">
<input type="text" placeholder="@(SmartTranslateService.Translate("Lastname"))" name="text"class="form-control bg-transparent"> <div class="col-lg-6 mb-4 fv-plugins-icon-container">
<InputText @bind-Value="UserRegisterModel.FirstName" type="text" placeholder="@(SmartTranslateService.Translate("Firstname"))" name="text" class="form-control bg-transparent" />
</div> </div>
<div class="fv-row mb-8 fv-plugins-icon-container"> <div class="col-lg-6 mb-4 fv-plugins-icon-container">
<input type="text" placeholder="@(SmartTranslateService.Translate("Email"))" name="email" autocomplete="off" class="form-control bg-transparent"> <InputText @bind-Value="UserRegisterModel.LastName" type="text" placeholder="@(SmartTranslateService.Translate("Lastname"))" name="text"class="form-control bg-transparent" />
</div>
</div> </div>
<div class="fv-row mb-3 fv-plugins-icon-container"> <div class="row">
<input type="password" placeholder="@(SmartTranslateService.Translate("Password"))" name="password" autocomplete="off" class="form-control bg-transparent"> <div class="col-lg-6 mb-4 fv-plugins-icon-container">
<InputText @bind-Value="UserRegisterModel.Password" type="password" placeholder="@(SmartTranslateService.Translate("Password"))" name="password" autocomplete="off" class="form-control bg-transparent" />
</div> </div>
<div class="fv-row mb-5 fv-plugins-icon-container"> <div class="col-lg-6 mb-4 fv-plugins-icon-container">
<input type="password" placeholder="@(SmartTranslateService.Translate("Repeat password"))" name="password" autocomplete="off" class="form-control bg-transparent"> <InputText @bind-Value="UserRegisterModel.ConfirmPassword" type="password" placeholder="@(SmartTranslateService.Translate("Repeat password"))" name="password" autocomplete="off" class="form-control bg-transparent" />
</div>
</div> </div>
<div class="d-grid mb-10"> <div class="d-grid mb-6">
<button class="btn btn-primary"> <button type="submit" class="btn btn-primary">
<TL>Sign-up</TL> <TL>Sign-up</TL>
</button> </button>
</div> </div>
</SmartForm>
<div class="text-gray-500 text-center fw-semibold fs-6"> <div class="text-gray-500 text-center fw-semibold fs-6">
<TL>Already registered?</TL> <TL>Already registered?</TL>
@ -93,6 +105,8 @@
@code @code
{ {
private UserRegisterModel UserRegisterModel = new();
private async Task DoGoogle() private async Task DoGoogle()
{ {
var url = await GoogleOAuth2Service.GetUrl(); var url = await GoogleOAuth2Service.GetUrl();
@ -104,4 +118,21 @@
var url = await DiscordOAuth2Service.GetUrl(); var url = await DiscordOAuth2Service.GetUrl();
NavigationManager.NavigateTo(url, true); 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);
}
} }

View file

@ -3,7 +3,9 @@
@using Moonlight.Shared.Components.Navigations @using Moonlight.Shared.Components.Navigations
@using Moonlight.App.Services.Sessions @using Moonlight.App.Services.Sessions
@using Moonlight.App.Database.Entities @using Moonlight.App.Database.Entities
@using Moonlight.App.Models.Forms
@using Moonlight.App.Repositories @using Moonlight.App.Repositories
@using Moonlight.Shared.Components.Auth
@inject IdentityService IdentityService @inject IdentityService IdentityService
@inject UserRepository UserRepository @inject UserRepository UserRepository
@ -74,17 +76,32 @@
@code @code
{ {
private User User = new User(); private UserDataModel User = new UserDataModel();
private User CurrentUser;
private async Task Load(LazyLoader loader) 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() 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; return Task.CompletedTask;
} }

View file

@ -536,6 +536,10 @@ 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 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 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 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
Cleanup exception;Cleanup exception Cleanup exception;Cleanup exception
No shared domain found;No shared domain found No shared domain found;No shared domain found
Searching for deploy plesk server;Searching for deploy plesk server Searching for deploy plesk server;Searching for deploy plesk server