diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/BaseIdentificationDocumentPageModel.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/BaseIdentificationDocumentPageModel.cs new file mode 100644 index 0000000..b842ddc --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/BaseIdentificationDocumentPageModel.cs @@ -0,0 +1,32 @@ +using EnotaryoPH.Data; +using EnotaryoPH.Web.Common.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace EnotaryoPH.Web.Pages +{ + public abstract class BaseIdentificationDocumentPageModel : PageModel + { + protected readonly NotaryoDBContext _notaryoDBContext; + + protected BaseIdentificationDocumentPageModel(NotaryoDBContext notaryoDBContext) => _notaryoDBContext = notaryoDBContext; + + protected void CreateIdentificationDocument(Guid user_UID) + { + ArgumentOutOfRangeException.ThrowIfEqual(Guid.Empty, user_UID); + var user = _notaryoDBContext.Users.AsNoTracking().FirstOrDefault(u => u.User_UID == user_UID) ?? throw new ArgumentException("User does not exist."); + var entity = NewIdentificationDocument.ToEntity(user.UserID); + _notaryoDBContext.Add(entity); + _notaryoDBContext.SaveChanges(); + } + + [BindProperty(SupportsGet = true)] + public Guid IdentificationDocument_UID { get; set; } + + [BindProperty] + public IdentificationDocumentModel NewIdentificationDocument { get; set; } + + [BindProperty] + public bool UploadNewIdentification { get; set; } + } +} \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Index.cshtml.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Index.cshtml.cs index d9f40ea..46ffed7 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Index.cshtml.cs +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Index.cshtml.cs @@ -9,10 +9,15 @@ namespace EnotaryoPH.Web.Pages.Participant.Registration public class IndexModel : PageModel { private readonly NotaryoDBContext _notaryoDBContext; + private readonly ISignInService _signInService; - public IndexModel(NotaryoDBContext notaryoDBContext) => _notaryoDBContext = notaryoDBContext; + public IndexModel(NotaryoDBContext notaryoDBContext, ISignInService signInService) + { + _notaryoDBContext = notaryoDBContext; + _signInService = signInService; + } - public IActionResult OnGet() + public async Task OnGetAsync() { if (string.IsNullOrEmpty(InvitationCode)) { @@ -20,7 +25,9 @@ namespace EnotaryoPH.Web.Pages.Participant.Registration } var invitationCodeGuid = InvitationCode.ToGuidFromBase64(); - var signatory = _notaryoDBContext.TransactionSignatories.FirstOrDefault(e => e.InvitationCode == invitationCodeGuid.ToString() && e.Status == nameof(SignatoryStatus.New)); + var signatory = _notaryoDBContext.TransactionSignatories + .Include(e => e.Transaction) + .FirstOrDefault(e => e.InvitationCode == invitationCodeGuid.ToString() && (e.Status == nameof(SignatoryStatus.New) || e.Status == nameof(SignatoryStatus.Registered))); if (signatory == null) { return NotFound(); @@ -33,7 +40,15 @@ namespace EnotaryoPH.Web.Pages.Participant.Registration signatory.UserID = existingUser.UserID; _notaryoDBContext.Update(signatory); _notaryoDBContext.SaveChanges(); - return Redirect("Steps/UploadIdentification"); + + await _signInService.SignInAsync(new UserLogin + { + Email = existingUser.Email, + Role = existingUser.Role, + User_UID = existingUser.User_UID.Value + }); + + return Redirect($"Steps/UploadIdentification/{signatory.Transaction.Transaction_UID}"); } TransactionSignatory_UID = signatory.TransactionSignatory_UID.GetValueOrDefault(); @@ -41,7 +56,7 @@ namespace EnotaryoPH.Web.Pages.Participant.Registration return Page(); } - public IActionResult OnPost() + public async Task OnPostAsync() { if (!ModelState.IsValid) { @@ -54,7 +69,8 @@ namespace EnotaryoPH.Web.Pages.Participant.Registration return Page(); } - var signatory = _notaryoDBContext.TransactionSignatories.FirstOrDefault(e => e.TransactionSignatory_UID == TransactionSignatory_UID && e.Status == nameof(SignatoryStatus.New)); + var signatory = _notaryoDBContext.TransactionSignatories + .FirstOrDefault(e => e.TransactionSignatory_UID == TransactionSignatory_UID && e.Status == nameof(SignatoryStatus.New)); if (signatory == null) { return BadRequest(); @@ -81,7 +97,14 @@ namespace EnotaryoPH.Web.Pages.Participant.Registration _notaryoDBContext.Update(signatory); _notaryoDBContext.SaveChanges(); - return Redirect("Steps/UploadIdentification"); + await _signInService.SignInAsync(new UserLogin + { + Email = newUser.Email, + Role = newUser.Role, + User_UID = newUser.User_UID.Value + }); + + return Redirect($"Steps/UploadIdentification/{signatory.Transaction.Transaction_UID}"); } [BindProperty(SupportsGet = true)] diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/TakeSelfie.cshtml b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/TakeSelfie.cshtml new file mode 100644 index 0000000..8a6e2ed --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/TakeSelfie.cshtml @@ -0,0 +1,37 @@ +@page "{Transaction_UID:guid}" +@model EnotaryoPH.Web.Pages.Participant.Registration.Steps.TakeSelfieModel +@{ +} + + +
+
+

Registration Steps

+ +
+
+
+
+
+
+ TAKE PICTUREAGAIN +
+
+
+
+
+
\ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/TakeSelfie.cshtml.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/TakeSelfie.cshtml.cs new file mode 100644 index 0000000..385032e --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/TakeSelfie.cshtml.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace EnotaryoPH.Web.Pages.Participant.Registration.Steps +{ + public class TakeSelfieModel : PageModel + { + public void OnGet() + { + } + + [BindProperty(SupportsGet = true)] + public Guid Transaction_UID { get; set; } + } +} \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/UploadIdentification.cshtml b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/UploadIdentification.cshtml index ad8ea2d..8615fa2 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/UploadIdentification.cshtml +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/UploadIdentification.cshtml @@ -1,106 +1,46 @@ -@page +@page "{Transaction_UID:guid}" +@using EnotaryoPH.Web.Pages.Shared.Components.NotaryoSteps +@using EnotaryoPH.Web.Pages.Shared.Components.UploadOrChooseIdentificationDocument @model EnotaryoPH.Web.Pages.Participant.Registration.Steps.UploadIdentificationModel -
+@section Head { + +} + +
-

Registration Steps

- -
-
-
-
-
-
-
+
+
+

Notaryo Steps

+
+ @await Component.InvokeAsync("NotaryoSteps", new + { + NotaryoSteps = new List() + { + new NotaryoStep { Name = "Upload Identification", Step = 1, IsActive = true }, + new NotaryoStep { Name = "Take Selfie", Step = 2 } + } + }) +
+
+ + @await Component.InvokeAsync("UploadOrChooseIdentificationDocument", Model.Transaction_UID) +
+
+ +
+
+
-
-
-
- -
-

passport-2024-12-07__final.jpg

-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

Existing Identification Documents

-
- - - - - - - - - - - - - - - - - - - - -
Identification Document TypeUploaded On
Driver's License2024-11-31
Passport2024-12-17
-
-
-
-
-
-
NEXT
-
\ No newline at end of file +
+ +@section Scripts { + + + + + +} \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/UploadIdentification.cshtml.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/UploadIdentification.cshtml.cs index b780ade..05f5159 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/UploadIdentification.cshtml.cs +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/UploadIdentification.cshtml.cs @@ -1,12 +1,36 @@ +using EnotaryoPH.Data; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; namespace EnotaryoPH.Web.Pages.Participant.Registration.Steps { - public class UploadIdentificationModel : PageModel + public class UploadIdentificationModel : BaseIdentificationDocumentPageModel { + private readonly ICurrentUserService _currentUserService; + + public UploadIdentificationModel(NotaryoDBContext notaryoDBContext, ICurrentUserService currentUserService) + : base(notaryoDBContext) => _currentUserService = currentUserService; + public void OnGet() { } + + public async Task OnPostAsync() + { + if (UploadNewIdentification) + { + + if (!ModelState.IsValid) + { + return Page(); + } + + CreateIdentificationDocument(_currentUserService.GetUser_UID()); + } + + return Redirect($"../TakeSelfie/{Transaction_UID}"); + } + + [BindProperty(SupportsGet = true)] + public Guid Transaction_UID { get; set; } } -} +} \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/UploadIdentification.cshtml.js b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/UploadIdentification.cshtml.js new file mode 100644 index 0000000..9f3ae8a --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Participant/Registration/Steps/UploadIdentification.cshtml.js @@ -0,0 +1,34 @@ +"use strict"; +(function () { + const + control_existingDocumentsContainer = document.getElementById("ExistingDocumentsContainer"), + control_newIdentificationDocumentContainer = document.getElementById("NewIdentificationDocumentContainer"), + control_uploadNewIdentificationRadios = document.getElementsByName("UploadNewIdentification"); + + function _bindEvents() { + + control_uploadNewIdentificationRadios.forEach(radio => { + radio.addEventListener("change", _radioOptionChanged) + }); + } + + function _init() { + _bindEvents(); + + _radioOptionChanged(null); + } + + function _radioOptionChanged(sender) { + let uploadNewIdentificationDocument = sender?.target?.value ?? "true"; + if (uploadNewIdentificationDocument === "true") { + jfa.utilities.element.hide(control_existingDocumentsContainer); + jfa.utilities.element.show(control_newIdentificationDocumentContainer) + } + else { + jfa.utilities.element.show(control_existingDocumentsContainer); + jfa.utilities.element.hide(control_newIdentificationDocumentContainer) + } + } + + _init(); +})(); \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadIdentification.cshtml.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadIdentification.cshtml.cs index 960461e..0c97b6b 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadIdentification.cshtml.cs +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Principal/NotaryoSteps/UploadIdentification.cshtml.cs @@ -3,7 +3,6 @@ using EnotaryoPH.Web.Common.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; -using Microsoft.EntityFrameworkCore; namespace EnotaryoPH.Web.Pages.Principal.NotaryoSteps { @@ -37,7 +36,6 @@ namespace EnotaryoPH.Web.Pages.Principal.NotaryoSteps return Page(); } - [IgnoreAntiforgeryToken] public async Task OnPostAsync() { if (UploadNewIdentification) @@ -50,11 +48,6 @@ namespace EnotaryoPH.Web.Pages.Principal.NotaryoSteps }; return Page(); } - - var user = _notaryoDBContext.Users.AsNoTracking().FirstOrDefault(u => u.User_UID == _currentUserService.GetUser_UID()); - var entity = NewIdentificationDocument.ToEntity(user.UserID); - _notaryoDBContext.Add(entity); - _notaryoDBContext.SaveChanges(); } return RedirectToPage("/Principal/NotaryoSteps/TakeSelfie"); diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/UploadOrChooseIdentificationDocument/Default.cshtml b/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/UploadOrChooseIdentificationDocument/Default.cshtml new file mode 100644 index 0000000..28d0ed0 --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/UploadOrChooseIdentificationDocument/Default.cshtml @@ -0,0 +1,59 @@ +@model UploadOrChooseIdentificationDocumentModel + +@if (Model.ExistingIdentificationDocuments.Count > 0) +{ +
+
+
+
+
+
+
+
+} +else +{ + +} + +
+ @Html.EditorFor(m => m.NewIdentificationDocument) +
+@if (Model.ExistingIdentificationDocuments.Count > 0) +{ +
+
+
+

Existing Identification Documents

+
+ + + + + + + + + + @foreach (var id in Model.ExistingIdentificationDocuments) + { + + + + + + } + +
Identification Document TypeExpiration
@id.IdentificationType@id.ExpirationDate.Value.ToShortDateString() + +
+
+
+
+
+} + + diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/UploadOrChooseIdentificationDocument/Default.cshtml.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/UploadOrChooseIdentificationDocument/Default.cshtml.cs new file mode 100644 index 0000000..1a9343a --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/UploadOrChooseIdentificationDocument/Default.cshtml.cs @@ -0,0 +1,59 @@ +using EnotaryoPH.Data; +using EnotaryoPH.Web.Common.Models; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; + +namespace EnotaryoPH.Web.Pages.Shared.Components.UploadOrChooseIdentificationDocument +{ + public class UploadOrChooseIdentificationDocumentViewComponent : ViewComponent + { + private readonly ICurrentUserService _currentUserService; + private readonly NotaryoDBContext _notaryoDBContext; + + public UploadOrChooseIdentificationDocumentViewComponent(NotaryoDBContext notaryoDBContext, ICurrentUserService currentUserService) + { + _notaryoDBContext = notaryoDBContext; + _currentUserService = currentUserService; + } + + public async Task InvokeAsync(Guid transaction_UID) + { + var model = new UploadOrChooseIdentificationDocumentModel + { + ExistingIdentificationDocuments = [], + NewIdentificationDocument = new(), + UploadNewIdentification = true + }; + var user = _notaryoDBContext.Users.AsNoTracking().FirstOrDefault(u => u.User_UID == _currentUserService.GetUser_UID()); + if (user == null) + { + return View(model); + } + model.ExistingIdentificationDocuments = GetIdentityDocumentsByUserID(user.UserID); + model.NewIdentificationDocument = new IdentificationDocumentModel + { + IdentificationTypes = GetIdentificationDocumentTypes() + }; + model.UploadNewIdentification = true; + + return View(model); + } + + private List GetIdentificationDocumentTypes() + { + var lookupIdentificationTypes = _notaryoDBContext.LookupData.AsNoTracking().Include(e => e.LookupDataValues).FirstOrDefault(e => e.Name == "Identification Types"); + return lookupIdentificationTypes.LookupDataValues + .ConvertAll(m => new SelectListItem + { + Text = m.Title.DefaultIfEmpty(m.Value), + Value = m.Value + }); + } + + private List GetIdentityDocumentsByUserID(int userID) + => _notaryoDBContext.IdentificationDocuments + .AsNoTracking() + .Where(d => d.UserID == userID) + .Select(d => new IdentificationDocumentModel(d)).ToList(); + } +} \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/UploadOrChooseIdentificationDocument/UploadOrChooseIdentificationDocumentModel.cs b/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/UploadOrChooseIdentificationDocument/UploadOrChooseIdentificationDocumentModel.cs new file mode 100644 index 0000000..d47cb47 --- /dev/null +++ b/EnotaryoPH/EnotaryoPH.Web/Pages/Shared/Components/UploadOrChooseIdentificationDocument/UploadOrChooseIdentificationDocumentModel.cs @@ -0,0 +1,18 @@ +using EnotaryoPH.Web.Common.Models; +using Microsoft.AspNetCore.Mvc; + +namespace EnotaryoPH.Web.Pages.Shared.Components.UploadOrChooseIdentificationDocument +{ + public class UploadOrChooseIdentificationDocumentModel + { + public int ExistingIdentificationDocumentCount => ExistingIdentificationDocuments.Count; + + public List ExistingIdentificationDocuments { get; set; } = []; + + [BindProperty] + public IdentificationDocumentModel NewIdentificationDocument { get; set; } + + [BindProperty] + public bool UploadNewIdentification { get; set; } + } +} \ No newline at end of file diff --git a/EnotaryoPH/EnotaryoPH.Web/Program.cs b/EnotaryoPH/EnotaryoPH.Web/Program.cs index 62799a1..04739ff 100644 --- a/EnotaryoPH/EnotaryoPH.Web/Program.cs +++ b/EnotaryoPH/EnotaryoPH.Web/Program.cs @@ -18,8 +18,13 @@ namespace EnotaryoPH.Web builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => options.LoginPath = new Microsoft.AspNetCore.Http.PathString("/Login")); - builder.Services.AddAuthorization(options => options.AddPolicy("PrincipalPolicy", policy => policy.RequireRole("Principal"))); - var razorBuilder = builder.Services.AddRazorPages(options => options.Conventions.AuthorizeFolder("/Principal", "PrincipalPolicy")); + builder.Services.AddAuthorization(options => options.AddPolicy("PrincipalPolicy", policy => policy.RequireRole(nameof(UserType.Principal)))); + builder.Services.AddAuthorization(options => options.AddPolicy("ParticipantPolicy", policy => policy.RequireRole(nameof(UserType.Witness), nameof(UserType.Principal)))); + var razorBuilder = builder.Services.AddRazorPages(options => + { + options.Conventions.AuthorizeFolder("/Principal", "PrincipalPolicy"); + options.Conventions.AuthorizeFolder("/Participant/Registration/Steps", "ParticipantPolicy"); + }); #if DEBUG razorBuilder.AddRazorRuntimeCompilation(); #endif @@ -34,7 +39,6 @@ namespace EnotaryoPH.Web { BaseUrl = config.GetValue("BaseUrl") ?? "" }); - builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient();