Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
Medic
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hasan.bahjat
Medic
Commits
ea519b6a
Commit
ea519b6a
authored
May 21, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
scafold identity
parent
20a9baae
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
874 additions
and
0 deletions
+874
-0
IdentityHostingStartup.cs
WebPresentation/Areas/Identity/IdentityHostingStartup.cs
+22
-0
AccessDenied.cshtml
...entation/Areas/Identity/Pages/Account/AccessDenied.cshtml
+10
-0
AccessDenied.cshtml.cs
...ation/Areas/Identity/Pages/Account/AccessDenied.cshtml.cs
+17
-0
Login.cshtml
WebPresentation/Areas/Identity/Pages/Account/Login.cshtml
+85
-0
Login.cshtml.cs
WebPresentation/Areas/Identity/Pages/Account/Login.cshtml.cs
+111
-0
Logout.cshtml
WebPresentation/Areas/Identity/Pages/Account/Logout.cshtml
+21
-0
Logout.cshtml.cs
...resentation/Areas/Identity/Pages/Account/Logout.cshtml.cs
+44
-0
ChangePassword.cshtml
...Areas/Identity/Pages/Account/Manage/ChangePassword.cshtml
+36
-0
ChangePassword.cshtml.cs
...as/Identity/Pages/Account/Manage/ChangePassword.cshtml.cs
+101
-0
ManageNavPages.cs
...ion/Areas/Identity/Pages/Account/Manage/ManageNavPages.cs
+50
-0
_ManageNav.cshtml
...ion/Areas/Identity/Pages/Account/Manage/_ManageNav.cshtml
+15
-0
_ViewImports.cshtml
...n/Areas/Identity/Pages/Account/Manage/_ViewImports.cshtml
+1
-0
Register.cshtml
WebPresentation/Areas/Identity/Pages/Account/Register.cshtml
+107
-0
Register.cshtml.cs
...sentation/Areas/Identity/Pages/Account/Register.cshtml.cs
+98
-0
ResetPassword.cshtml
...ntation/Areas/Identity/Pages/Account/ResetPassword.cshtml
+37
-0
ResetPassword.cshtml.cs
...tion/Areas/Identity/Pages/Account/ResetPassword.cshtml.cs
+91
-0
_ViewImports.cshtml
...entation/Areas/Identity/Pages/Account/_ViewImports.cshtml
+1
-0
_ValidationScriptsPartial.cshtml
...ion/Areas/Identity/Pages/_ValidationScriptsPartial.cshtml
+18
-0
_ViewImports.cshtml
WebPresentation/Areas/Identity/Pages/_ViewImports.cshtml
+5
-0
_ViewStart.cshtml
WebPresentation/Areas/Identity/Pages/_ViewStart.cshtml
+4
-0
No files found.
WebPresentation/Areas/Identity/IdentityHostingStartup.cs
0 → 100644
View file @
ea519b6a
using
System
;
using
ApplicationCore.Entities
;
using
Infrastructure.Data
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Identity.UI
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
[assembly: HostingStartup(typeof(WebPresentation.Areas.Identity.IdentityHostingStartup))]
namespace
WebPresentation.Areas.Identity
{
public
class
IdentityHostingStartup
:
IHostingStartup
{
public
void
Configure
(
IWebHostBuilder
builder
)
{
builder
.
ConfigureServices
((
context
,
services
)
=>
{
});
}
}
}
\ No newline at end of file
WebPresentation/Areas/Identity/Pages/Account/AccessDenied.cshtml
0 → 100644
View file @
ea519b6a
@page
@model AccessDeniedModel
@{
ViewData["Title"] = "Access denied";
}
<header>
<h1 class="text-danger">@ViewData["Title"]</h1>
<p class="text-danger">You do not have access to this resource.</p>
</header>
WebPresentation/Areas/Identity/Pages/Account/AccessDenied.cshtml.cs
0 → 100644
View file @
ea519b6a
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Mvc.RazorPages
;
namespace
WebPresentation.Areas.Identity.Pages.Account
{
public
class
AccessDeniedModel
:
PageModel
{
public
void
OnGet
()
{
}
}
}
WebPresentation/Areas/Identity/Pages/Account/Login.cshtml
0 → 100644
View file @
ea519b6a
@page
@model LoginModel
@{
ViewData["Title"] = "Log in";
}
<h1>@ViewData["Title"]</h1>
<div class="row">
<div class="col-md-4">
<section>
<form id="account" method="post">
<h4>Use a local account to log in.</h4>
<hr />
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="Input.Email"></label>
<input asp-for="Input.Email" class="form-control" />
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.Password"></label>
<input asp-for="Input.Password" class="form-control" />
<span asp-validation-for="Input.Password" class="text-danger"></span>
</div>
<div class="form-group">
<div class="checkbox">
<label asp-for="Input.RememberMe">
<input asp-for="Input.RememberMe" />
@Html.DisplayNameFor(m => m.Input.RememberMe)
</label>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Log in</button>
</div>
<div class="form-group">
<p>
<a id="forgot-password" asp-page="./ForgotPassword">Forgot your password?</a>
</p>
<p>
<a asp-page="./Register" asp-route-returnUrl="@Model.ReturnUrl">Register as a new user</a>
</p>
<p>
<a id="resend-confirmation" asp-page="./ResendEmailConfirmation">Resend email confirmation</a>
</p>
</div>
</form>
</section>
</div>
<div class="col-md-6 col-md-offset-2">
<section>
<h4>Use another service to log in.</h4>
<hr />
@{
if ((Model.ExternalLogins?.Count ?? 0) == 0)
{
<div>
<p>
There are no external authentication services configured. See <a href="https://go.microsoft.com/fwlink/?LinkID=532715">this article</a>
for details on setting up this ASP.NET application to support logging in via external services.
</p>
</div>
}
else
{
<form id="external-account" asp-page="./ExternalLogin" asp-route-returnUrl="@Model.ReturnUrl" method="post" class="form-horizontal">
<div>
<p>
@foreach (var provider in Model.ExternalLogins)
{
<button type="submit" class="btn btn-primary" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
}
</p>
</div>
</form>
}
}
</section>
</div>
</div>
@section Scripts {
<partial name="_ValidationScriptsPartial" />
}
WebPresentation/Areas/Identity/Pages/Account/Login.cshtml.cs
0 → 100644
View file @
ea519b6a
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
System.Linq
;
using
System.Text.Encodings.Web
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Authorization
;
using
ApplicationCore.Entities
;
using
Microsoft.AspNetCore.Authentication
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Identity.UI.Services
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc.RazorPages
;
using
Microsoft.Extensions.Logging
;
namespace
WebPresentation.Areas.Identity.Pages.Account
{
[
AllowAnonymous
]
public
class
LoginModel
:
PageModel
{
private
readonly
UserManager
<
User
>
_userManager
;
private
readonly
SignInManager
<
User
>
_signInManager
;
private
readonly
ILogger
<
LoginModel
>
_logger
;
public
LoginModel
(
SignInManager
<
User
>
signInManager
,
ILogger
<
LoginModel
>
logger
,
UserManager
<
User
>
userManager
)
{
_userManager
=
userManager
;
_signInManager
=
signInManager
;
_logger
=
logger
;
}
[
BindProperty
]
public
InputModel
Input
{
get
;
set
;
}
public
IList
<
AuthenticationScheme
>
ExternalLogins
{
get
;
set
;
}
public
string
ReturnUrl
{
get
;
set
;
}
[
TempData
]
public
string
ErrorMessage
{
get
;
set
;
}
public
class
InputModel
{
[
Required
]
[
EmailAddress
]
public
string
Email
{
get
;
set
;
}
[
Required
]
[
DataType
(
DataType
.
Password
)]
public
string
Password
{
get
;
set
;
}
[
Display
(
Name
=
"Remember me?"
)]
public
bool
RememberMe
{
get
;
set
;
}
}
public
async
Task
OnGetAsync
(
string
returnUrl
=
null
)
{
if
(!
string
.
IsNullOrEmpty
(
ErrorMessage
))
{
ModelState
.
AddModelError
(
string
.
Empty
,
ErrorMessage
);
}
returnUrl
??=
Url
.
Content
(
"~/"
);
// Clear the existing external cookie to ensure a clean login process
await
HttpContext
.
SignOutAsync
(
IdentityConstants
.
ExternalScheme
);
ExternalLogins
=
(
await
_signInManager
.
GetExternalAuthenticationSchemesAsync
()).
ToList
();
ReturnUrl
=
returnUrl
;
}
public
async
Task
<
IActionResult
>
OnPostAsync
(
string
returnUrl
=
null
)
{
returnUrl
??=
Url
.
Content
(
"~/"
);
ExternalLogins
=
(
await
_signInManager
.
GetExternalAuthenticationSchemesAsync
()).
ToList
();
if
(
ModelState
.
IsValid
)
{
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
var
result
=
await
_signInManager
.
PasswordSignInAsync
(
Input
.
Email
,
Input
.
Password
,
Input
.
RememberMe
,
lockoutOnFailure
:
false
);
if
(
result
.
Succeeded
)
{
_logger
.
LogInformation
(
"User logged in."
);
return
LocalRedirect
(
returnUrl
);
}
if
(
result
.
RequiresTwoFactor
)
{
return
RedirectToPage
(
"./LoginWith2fa"
,
new
{
ReturnUrl
=
returnUrl
,
RememberMe
=
Input
.
RememberMe
});
}
if
(
result
.
IsLockedOut
)
{
_logger
.
LogWarning
(
"User account locked out."
);
return
RedirectToPage
(
"./Lockout"
);
}
else
{
ModelState
.
AddModelError
(
string
.
Empty
,
"Invalid login attempt."
);
return
Page
();
}
}
// If we got this far, something failed, redisplay form
return
Page
();
}
}
}
WebPresentation/Areas/Identity/Pages/Account/Logout.cshtml
0 → 100644
View file @
ea519b6a
@page
@model LogoutModel
@{
ViewData["Title"] = "Log out";
}
<header>
<h1>@ViewData["Title"]</h1>
@{
if (User.Identity.IsAuthenticated)
{
<form class="form-inline" asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="@Url.Page("/", new { area = "" })" method="post">
<button type="submit" class="nav-link btn btn-link text-dark">Click here to Logout</button>
</form>
}
else
{
<p>You have successfully logged out of the application.</p>
}
}
</header>
\ No newline at end of file
WebPresentation/Areas/Identity/Pages/Account/Logout.cshtml.cs
0 → 100644
View file @
ea519b6a
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Authorization
;
using
ApplicationCore.Entities
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc.RazorPages
;
using
Microsoft.Extensions.Logging
;
namespace
WebPresentation.Areas.Identity.Pages.Account
{
[
AllowAnonymous
]
public
class
LogoutModel
:
PageModel
{
private
readonly
SignInManager
<
User
>
_signInManager
;
private
readonly
ILogger
<
LogoutModel
>
_logger
;
public
LogoutModel
(
SignInManager
<
User
>
signInManager
,
ILogger
<
LogoutModel
>
logger
)
{
_signInManager
=
signInManager
;
_logger
=
logger
;
}
public
void
OnGet
()
{
}
public
async
Task
<
IActionResult
>
OnPost
(
string
returnUrl
=
null
)
{
await
_signInManager
.
SignOutAsync
();
_logger
.
LogInformation
(
"User logged out."
);
if
(
returnUrl
!=
null
)
{
return
LocalRedirect
(
returnUrl
);
}
else
{
return
RedirectToPage
();
}
}
}
}
WebPresentation/Areas/Identity/Pages/Account/Manage/ChangePassword.cshtml
0 → 100644
View file @
ea519b6a
@page
@model ChangePasswordModel
@{
ViewData["Title"] = "Change password";
ViewData["ActivePage"] = ManageNavPages.ChangePassword;
}
<h4>@ViewData["Title"]</h4>
<partial name="_StatusMessage" for="StatusMessage" />
<div class="row">
<div class="col-md-6">
<form id="change-password-form" method="post">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="Input.OldPassword"></label>
<input asp-for="Input.OldPassword" class="form-control" />
<span asp-validation-for="Input.OldPassword" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.NewPassword"></label>
<input asp-for="Input.NewPassword" class="form-control" />
<span asp-validation-for="Input.NewPassword" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.ConfirmPassword"></label>
<input asp-for="Input.ConfirmPassword" class="form-control" />
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Update password</button>
</form>
</div>
</div>
@section Scripts {
<partial name="_ValidationScriptsPartial" />
}
\ No newline at end of file
WebPresentation/Areas/Identity/Pages/Account/Manage/ChangePassword.cshtml.cs
0 → 100644
View file @
ea519b6a
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
ApplicationCore.Entities
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc.RazorPages
;
using
Microsoft.Extensions.Logging
;
namespace
WebPresentation.Areas.Identity.Pages.Account.Manage
{
public
class
ChangePasswordModel
:
PageModel
{
private
readonly
UserManager
<
User
>
_userManager
;
private
readonly
SignInManager
<
User
>
_signInManager
;
private
readonly
ILogger
<
ChangePasswordModel
>
_logger
;
public
ChangePasswordModel
(
UserManager
<
User
>
userManager
,
SignInManager
<
User
>
signInManager
,
ILogger
<
ChangePasswordModel
>
logger
)
{
_userManager
=
userManager
;
_signInManager
=
signInManager
;
_logger
=
logger
;
}
[
BindProperty
]
public
InputModel
Input
{
get
;
set
;
}
[
TempData
]
public
string
StatusMessage
{
get
;
set
;
}
public
class
InputModel
{
[
Required
]
[
DataType
(
DataType
.
Password
)]
[
Display
(
Name
=
"Current password"
)]
public
string
OldPassword
{
get
;
set
;
}
[
Required
]
[
StringLength
(
100
,
ErrorMessage
=
"The {0} must be at least {2} and at max {1} characters long."
,
MinimumLength
=
6
)]
[
DataType
(
DataType
.
Password
)]
[
Display
(
Name
=
"New password"
)]
public
string
NewPassword
{
get
;
set
;
}
[
DataType
(
DataType
.
Password
)]
[
Display
(
Name
=
"Confirm new password"
)]
[
Compare
(
"NewPassword"
,
ErrorMessage
=
"The new password and confirmation password do not match."
)]
public
string
ConfirmPassword
{
get
;
set
;
}
}
public
async
Task
<
IActionResult
>
OnGetAsync
()
{
var
user
=
await
_userManager
.
GetUserAsync
(
User
);
if
(
user
==
null
)
{
return
NotFound
(
$"Unable to load user with ID '
{
_userManager
.
GetUserId
(
User
)}
'."
);
}
var
hasPassword
=
await
_userManager
.
HasPasswordAsync
(
user
);
if
(!
hasPassword
)
{
return
RedirectToPage
(
"./SetPassword"
);
}
return
Page
();
}
public
async
Task
<
IActionResult
>
OnPostAsync
()
{
if
(!
ModelState
.
IsValid
)
{
return
Page
();
}
var
user
=
await
_userManager
.
GetUserAsync
(
User
);
if
(
user
==
null
)
{
return
NotFound
(
$"Unable to load user with ID '
{
_userManager
.
GetUserId
(
User
)}
'."
);
}
var
changePasswordResult
=
await
_userManager
.
ChangePasswordAsync
(
user
,
Input
.
OldPassword
,
Input
.
NewPassword
);
if
(!
changePasswordResult
.
Succeeded
)
{
foreach
(
var
error
in
changePasswordResult
.
Errors
)
{
ModelState
.
AddModelError
(
string
.
Empty
,
error
.
Description
);
}
return
Page
();
}
await
_signInManager
.
RefreshSignInAsync
(
user
);
_logger
.
LogInformation
(
"User changed their password successfully."
);
StatusMessage
=
"Your password has been changed."
;
return
RedirectToPage
();
}
}
}
WebPresentation/Areas/Identity/Pages/Account/Manage/ManageNavPages.cs
0 → 100644
View file @
ea519b6a
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Mvc.Rendering
;
namespace
WebPresentation.Areas.Identity.Pages.Account.Manage
{
public
static
class
ManageNavPages
{
public
static
string
Index
=>
"Index"
;
public
static
string
Email
=>
"Email"
;
public
static
string
ChangePassword
=>
"ChangePassword"
;
public
static
string
DownloadPersonalData
=>
"DownloadPersonalData"
;
public
static
string
DeletePersonalData
=>
"DeletePersonalData"
;
public
static
string
ExternalLogins
=>
"ExternalLogins"
;
public
static
string
PersonalData
=>
"PersonalData"
;
public
static
string
TwoFactorAuthentication
=>
"TwoFactorAuthentication"
;
public
static
string
IndexNavClass
(
ViewContext
viewContext
)
=>
PageNavClass
(
viewContext
,
Index
);
public
static
string
EmailNavClass
(
ViewContext
viewContext
)
=>
PageNavClass
(
viewContext
,
Email
);
public
static
string
ChangePasswordNavClass
(
ViewContext
viewContext
)
=>
PageNavClass
(
viewContext
,
ChangePassword
);
public
static
string
DownloadPersonalDataNavClass
(
ViewContext
viewContext
)
=>
PageNavClass
(
viewContext
,
DownloadPersonalData
);
public
static
string
DeletePersonalDataNavClass
(
ViewContext
viewContext
)
=>
PageNavClass
(
viewContext
,
DeletePersonalData
);
public
static
string
ExternalLoginsNavClass
(
ViewContext
viewContext
)
=>
PageNavClass
(
viewContext
,
ExternalLogins
);
public
static
string
PersonalDataNavClass
(
ViewContext
viewContext
)
=>
PageNavClass
(
viewContext
,
PersonalData
);
public
static
string
TwoFactorAuthenticationNavClass
(
ViewContext
viewContext
)
=>
PageNavClass
(
viewContext
,
TwoFactorAuthentication
);
private
static
string
PageNavClass
(
ViewContext
viewContext
,
string
page
)
{
var
activePage
=
viewContext
.
ViewData
[
"ActivePage"
]
as
string
??
System
.
IO
.
Path
.
GetFileNameWithoutExtension
(
viewContext
.
ActionDescriptor
.
DisplayName
);
return
string
.
Equals
(
activePage
,
page
,
StringComparison
.
OrdinalIgnoreCase
)
?
"active"
:
null
;
}
}
}
WebPresentation/Areas/Identity/Pages/Account/Manage/_ManageNav.cshtml
0 → 100644
View file @
ea519b6a
@inject SignInManager<User> SignInManager
@{
var hasExternalLogins = (await SignInManager.GetExternalAuthenticationSchemesAsync()).Any();
}
<ul class="nav nav-pills flex-column">
<li class="nav-item"><a class="nav-link @ManageNavPages.IndexNavClass(ViewContext)" id="profile" asp-page="./Index">Profile</a></li>
<li class="nav-item"><a class="nav-link @ManageNavPages.EmailNavClass(ViewContext)" id="email" asp-page="./Email">Email</a></li>
<li class="nav-item"><a class="nav-link @ManageNavPages.ChangePasswordNavClass(ViewContext)" id="change-password" asp-page="./ChangePassword">Password</a></li>
@if (hasExternalLogins)
{
<li id="external-logins" class="nav-item"><a id="external-login" class="nav-link @ManageNavPages.ExternalLoginsNavClass(ViewContext)" asp-page="./ExternalLogins">External logins</a></li>
}
<li class="nav-item"><a class="nav-link @ManageNavPages.TwoFactorAuthenticationNavClass(ViewContext)" id="two-factor" asp-page="./TwoFactorAuthentication">Two-factor authentication</a></li>
<li class="nav-item"><a class="nav-link @ManageNavPages.PersonalDataNavClass(ViewContext)" id="personal-data" asp-page="./PersonalData">Personal data</a></li>
</ul>
WebPresentation/Areas/Identity/Pages/Account/Manage/_ViewImports.cshtml
0 → 100644
View file @
ea519b6a
@using WebPresentation.Areas.Identity.Pages.Account.Manage
WebPresentation/Areas/Identity/Pages/Account/Register.cshtml
0 → 100644
View file @
ea519b6a
@page
@model RegisterModel
@{
ViewData["Title"] = "Register";
}
<h1>@ViewData["Title"]</h1>
<style>
.card-registration .select-input.form-control[readonly]:not([disabled]) {
font-size: 1rem;
line-height: 2.15;
padding-left: .75em;
padding-right: .75em;
}
sectin * {
color: black !important;
}
.card-registration .select-arrow {
top: 13px;
}
</style>
<section class="page-section bg-primary text-black mb-0">
<h3 class="mb-5 text-uppercase text-center">Owner Registration</h3>
<form asp-route-returnUrl="@Model.ReturnUrl" method="post">
<div class="container py-5 h-100">
<div class="row d-flex justify-content-center align-items-center h-100">
<div class="col">
<div class="card card-registration my-4">
<div class="row g-0">
<div class="col-xl-6 d-none d-xl-block">
<img src="https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-registration/img4.webp"
alt="Sample photo" class="img-fluid"
style="border-top-left-radius: .25rem; border-bottom-left-radius: .25rem;" />
</div>
<div class="col-xl-6">
<div class="card-body p-md-5 text-black">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group row">
<label asp-for="Input.Email"></label>
<input asp-for="Input.Email" class="form-control" />
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>
<div class="form-group row ">
<label asp-for="Input.Password"></label>
<input asp-for="Input.Password" class="form-control" />
<span asp-validation-for="Input.Password" class="text-danger"></span>
</div>
<div class="form-group row">
<label asp-for="Input.ConfirmPassword"></label>
<input asp-for="Input.ConfirmPassword" class="form-control" />
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
</div>
<div class="form-group row mb-4">
<div data-mdb-input-init class="col form-outline">
<input type="text" asp-for="Input.Patient.FirstName" class="form-control form-control-lg" />
<label class="form-label" asp-for="Input.Patient.FirstName">First name</label>
</div>
<div data-mdb-input-init class="col form-outline">
<input type="text" asp-for="Input.Patient.LastName" class="form-control form-control-lg" />
<label class="form-label" asp-for="Input.Patient.LastName">Last name</label>
</div>
</div>
<div class="form-group row mb-4">
<div data-mdb-input-init class="form-outline col">
<input type="text" asp-for="Input.Patient.BIO" class="form-control form-control-lg" />
<label class="form-label" asp-for="Input.Patient.BIO">BIO</label>
</div>
</div>
<div class="form-group row mb-4">
<div data-mdb-input-init class="form-outline col">
<input type="text" asp-for="Input.Patient.Avatar" class="form-control form-control-lg" />
<label class="form-label" asp-for="Input.Patient.Avatar">Image</label>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary">Register</button>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</section>
@section Scripts {
<partial name="_ValidationScriptsPartial" />
}
WebPresentation/Areas/Identity/Pages/Account/Register.cshtml.cs
0 → 100644
View file @
ea519b6a
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
System.Linq
;
using
System.Text
;
using
System.Text.Encodings.Web
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Authentication
;
using
Microsoft.AspNetCore.Authorization
;
using
ApplicationCore.Entities
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Identity.UI.Services
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc.RazorPages
;
using
Microsoft.AspNetCore.WebUtilities
;
using
Microsoft.Extensions.Logging
;
using
cleanArchWebApp.ApplicationCore.Aggregate
;
namespace
WebPresentation.Areas.Identity.Pages.Account
{
[
AllowAnonymous
]
public
class
RegisterModel
:
PageModel
{
private
readonly
SignInManager
<
User
>
_signInManager
;
private
readonly
UserManager
<
User
>
_userManager
;
private
readonly
ILogger
<
RegisterModel
>
_logger
;
private
readonly
IEmailSender
_emailSender
;
public
RegisterModel
(
UserManager
<
User
>
userManager
,
SignInManager
<
User
>
signInManager
,
ILogger
<
RegisterModel
>
logger
,
IEmailSender
emailSender
)
{
_userManager
=
userManager
;
_signInManager
=
signInManager
;
_logger
=
logger
;
_emailSender
=
emailSender
;
}
[
BindProperty
]
public
RegisterationInputModel
Input
{
get
;
set
;
}
public
string
ReturnUrl
{
get
;
set
;
}
public
IList
<
AuthenticationScheme
>
ExternalLogins
{
get
;
set
;
}
public
async
Task
OnGetAsync
(
string
returnUrl
=
null
)
{
ReturnUrl
=
returnUrl
;
ExternalLogins
=
(
await
_signInManager
.
GetExternalAuthenticationSchemesAsync
()).
ToList
();
}
public
async
Task
<
IActionResult
>
OnPostAsync
(
string
returnUrl
=
null
)
{
returnUrl
??=
Url
.
Content
(
"~/"
);
ExternalLogins
=
(
await
_signInManager
.
GetExternalAuthenticationSchemesAsync
()).
ToList
();
if
(
ModelState
.
IsValid
)
{
var
user
=
new
User
{
NormalizedEmail
=
Input
.
Email
,
UserName
=
Input
.
Email
,
Email
=
Input
.
Email
,
Patient
=
Input
.
Patient
,
CreationTime
=
DateTime
.
Now
};
var
result
=
await
_userManager
.
CreateAsync
(
user
,
Input
.
Password
);
if
(
result
.
Succeeded
)
{
_logger
.
LogInformation
(
"User created a new account with password."
);
var
code
=
await
_userManager
.
GenerateEmailConfirmationTokenAsync
(
user
);
code
=
WebEncoders
.
Base64UrlEncode
(
Encoding
.
UTF8
.
GetBytes
(
code
));
var
callbackUrl
=
Url
.
Page
(
"/Account/ConfirmEmail"
,
pageHandler
:
null
,
values
:
new
{
area
=
"Identity"
,
userId
=
user
.
Id
,
code
=
code
,
returnUrl
=
returnUrl
},
protocol
:
Request
.
Scheme
);
await
_emailSender
.
SendEmailAsync
(
Input
.
Email
,
"Confirm your email"
,
$"Please confirm your account by <a href='
{
HtmlEncoder
.
Default
.
Encode
(
callbackUrl
)}
'>clicking here</a>."
);
if
(
_userManager
.
Options
.
SignIn
.
RequireConfirmedAccount
)
{
return
RedirectToPage
(
"RegisterConfirmation"
,
new
{
email
=
Input
.
Email
,
returnUrl
=
returnUrl
});
}
else
{
await
_signInManager
.
SignInAsync
(
user
,
isPersistent
:
false
);
return
LocalRedirect
(
returnUrl
);
}
}
foreach
(
var
error
in
result
.
Errors
)
{
ModelState
.
AddModelError
(
string
.
Empty
,
error
.
Description
);
}
}
// If we got this far, something failed, redisplay form
return
Page
();
}
}
}
WebPresentation/Areas/Identity/Pages/Account/ResetPassword.cshtml
0 → 100644
View file @
ea519b6a
@page
@model ResetPasswordModel
@{
ViewData["Title"] = "Reset password";
}
<h1>@ViewData["Title"]</h1>
<h4>Reset your password.</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input asp-for="Input.Code" type="hidden" />
<div class="form-group">
<label asp-for="Input.Email"></label>
<input asp-for="Input.Email" class="form-control" />
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.Password"></label>
<input asp-for="Input.Password" class="form-control" />
<span asp-validation-for="Input.Password" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.ConfirmPassword"></label>
<input asp-for="Input.ConfirmPassword" class="form-control" />
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Reset</button>
</form>
</div>
</div>
@section Scripts {
<partial name="_ValidationScriptsPartial" />
}
WebPresentation/Areas/Identity/Pages/Account/ResetPassword.cshtml.cs
0 → 100644
View file @
ea519b6a
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Authorization
;
using
ApplicationCore.Entities
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc.RazorPages
;
using
Microsoft.AspNetCore.WebUtilities
;
namespace
WebPresentation.Areas.Identity.Pages.Account
{
[
AllowAnonymous
]
public
class
ResetPasswordModel
:
PageModel
{
private
readonly
UserManager
<
User
>
_userManager
;
public
ResetPasswordModel
(
UserManager
<
User
>
userManager
)
{
_userManager
=
userManager
;
}
[
BindProperty
]
public
InputModel
Input
{
get
;
set
;
}
public
class
InputModel
{
[
Required
]
[
EmailAddress
]
public
string
Email
{
get
;
set
;
}
[
Required
]
[
StringLength
(
100
,
ErrorMessage
=
"The {0} must be at least {2} and at max {1} characters long."
,
MinimumLength
=
6
)]
[
DataType
(
DataType
.
Password
)]
public
string
Password
{
get
;
set
;
}
[
DataType
(
DataType
.
Password
)]
[
Display
(
Name
=
"Confirm password"
)]
[
Compare
(
"Password"
,
ErrorMessage
=
"The password and confirmation password do not match."
)]
public
string
ConfirmPassword
{
get
;
set
;
}
public
string
Code
{
get
;
set
;
}
}
public
IActionResult
OnGet
(
string
code
=
null
)
{
if
(
code
==
null
)
{
return
BadRequest
(
"A code must be supplied for password reset."
);
}
else
{
Input
=
new
InputModel
{
Code
=
Encoding
.
UTF8
.
GetString
(
WebEncoders
.
Base64UrlDecode
(
code
))
};
return
Page
();
}
}
public
async
Task
<
IActionResult
>
OnPostAsync
()
{
if
(!
ModelState
.
IsValid
)
{
return
Page
();
}
var
user
=
await
_userManager
.
FindByEmailAsync
(
Input
.
Email
);
if
(
user
==
null
)
{
// Don't reveal that the user does not exist
return
RedirectToPage
(
"./ResetPasswordConfirmation"
);
}
var
result
=
await
_userManager
.
ResetPasswordAsync
(
user
,
Input
.
Code
,
Input
.
Password
);
if
(
result
.
Succeeded
)
{
return
RedirectToPage
(
"./ResetPasswordConfirmation"
);
}
foreach
(
var
error
in
result
.
Errors
)
{
ModelState
.
AddModelError
(
string
.
Empty
,
error
.
Description
);
}
return
Page
();
}
}
}
WebPresentation/Areas/Identity/Pages/Account/_ViewImports.cshtml
0 → 100644
View file @
ea519b6a
@using WebPresentation.Areas.Identity.Pages.Account
\ No newline at end of file
WebPresentation/Areas/Identity/Pages/_ValidationScriptsPartial.cshtml
0 → 100644
View file @
ea519b6a
<environment include="Development">
<script src="~/Identity/lib/jquery-validation/dist/jquery.validate.js"></script>
<script src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
</environment>
<environment exclude="Development">
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.17.0/jquery.validate.min.js"
asp-fallback-src="~/Identity/lib/jquery-validation/dist/jquery.validate.min.js"
asp-fallback-test="window.jQuery && window.jQuery.validator"
crossorigin="anonymous"
integrity="sha384-rZfj/ogBloos6wzLGpPkkOr/gpkBNLZ6b6yLy4o+ok+t/SAKlL5mvXLr0OXNi1Hp">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validation.unobtrusive/3.2.9/jquery.validate.unobtrusive.min.js"
asp-fallback-src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"
asp-fallback-test="window.jQuery && window.jQuery.validator && window.jQuery.validator.unobtrusive"
crossorigin="anonymous"
integrity="sha384-ifv0TYDWxBHzvAk2Z0n8R434FL1Rlv/Av18DXE43N/1rvHyOG4izKst0f2iSLdds">
</script>
</environment>
WebPresentation/Areas/Identity/Pages/_ViewImports.cshtml
0 → 100644
View file @
ea519b6a
@using Microsoft.AspNetCore.Identity
@using WebPresentation.Areas.Identity
@using WebPresentation.Areas.Identity.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@using ApplicationCore.Entities
WebPresentation/Areas/Identity/Pages/_ViewStart.cshtml
0 → 100644
View file @
ea519b6a
@{
Layout = "/Views/Shared/_Layout.cshtml";
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment