Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
victorrar committed Dec 23, 2020
1 parent 213a516 commit 85c87f7
Show file tree
Hide file tree
Showing 110 changed files with 1,272 additions and 1,508 deletions.
4 changes: 3 additions & 1 deletion TRPZ_PrintService/Areas/Identity/IdentityHostingStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
using TRPZ_PrintService.Data;

[assembly: HostingStartup(typeof(TRPZ_PrintService.Areas.Identity.IdentityHostingStartup))]

namespace TRPZ_PrintService.Areas.Identity
{
public class IdentityHostingStartup : IHostingStartup
{
public void Configure(IWebHostBuilder builder)
{
builder.ConfigureServices((context, services) => {
builder.ConfigureServices((context, services) =>
{
services.AddDbContext<TRPZ_PrintServiceContext>(options =>
options.UseNpgsql(
"Host=localhost;Port=5432;Database=printdb;Username=printuser;Password=printpasswd"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<header>
<h1 class="text-danger">@ViewData["Title"]</h1>
<p class="text-danger">You do not have access to this resource.</p>
</header>
</header>
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ public class AccessDeniedModel : PageModel
{
public void OnGet()
{

}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,19 @@ public ConfirmEmailModel(UserManager<TRPZ_PrintServiceUser> userManager)
_userManager = userManager;
}

[TempData]
public string StatusMessage { get; set; }
[TempData] public string StatusMessage { get; set; }

public async Task<IActionResult> OnGetAsync(string userId, string code)
{
if (userId == null || code == null)
{
return RedirectToPage("/Index");
}
if (userId == null || code == null) return RedirectToPage("/Index");

var user = await _userManager.FindByIdAsync(userId);
if (user == null)
{
return NotFound($"Unable to load user with ID '{userId}'.");
}
if (user == null) return NotFound($"Unable to load user with ID '{userId}'.");

code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
var result = await _userManager.ConfirmEmailAsync(user, code);
StatusMessage = result.Succeeded ? "Thank you for confirming your email." : "Error confirming your email.";
return Page();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
}

<h1>@ViewData["Title"]</h1>
<partial name="_StatusMessage" model="Model.StatusMessage" />
<partial name="_StatusMessage" model="Model.StatusMessage"/>
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,21 @@ public class ConfirmEmailChangeModel : PageModel
private readonly UserManager<TRPZ_PrintServiceUser> _userManager;
private readonly SignInManager<TRPZ_PrintServiceUser> _signInManager;

public ConfirmEmailChangeModel(UserManager<TRPZ_PrintServiceUser> userManager, SignInManager<TRPZ_PrintServiceUser> signInManager)
public ConfirmEmailChangeModel(UserManager<TRPZ_PrintServiceUser> userManager,
SignInManager<TRPZ_PrintServiceUser> signInManager)
{
_userManager = userManager;
_signInManager = signInManager;
}

[TempData]
public string StatusMessage { get; set; }
[TempData] public string StatusMessage { get; set; }

public async Task<IActionResult> OnGetAsync(string userId, string email, string code)
{
if (userId == null || email == null || code == null)
{
return RedirectToPage("/Index");
}
if (userId == null || email == null || code == null) return RedirectToPage("/Index");

var user = await _userManager.FindByIdAsync(userId);
if (user == null)
{
return NotFound($"Unable to load user with ID '{userId}'.");
}
if (user == null) return NotFound($"Unable to load user with ID '{userId}'.");

code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
var result = await _userManager.ChangeEmailAsync(user, email, code);
Expand All @@ -62,4 +56,4 @@ public async Task<IActionResult> OnGetAsync(string userId, string email, string
return Page();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<h1>@ViewData["Title"]</h1>
<h4 id="external-login-title">Associate your @Model.ProviderDisplayName account.</h4>
<hr />
<hr/>

<p id="external-login-description" class="text-info">
You've successfully authenticated with <strong>@Model.ProviderDisplayName</strong>.
Expand All @@ -20,7 +20,7 @@
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Input.Email"></label>
<input asp-for="Input.Email" class="form-control" />
<input asp-for="Input.Email" class="form-control"/>
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Register</button>
Expand All @@ -29,5 +29,5 @@
</div>

@section Scripts {
<partial name="_ValidationScriptsPartial" />
}
<partial name="_ValidationScriptsPartial"/>
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,17 @@ public ExternalLoginModel(
_emailSender = emailSender;
}

[BindProperty]
public InputModel Input { get; set; }
[BindProperty] public InputModel Input { get; set; }

public string ProviderDisplayName { get; set; }

public string ReturnUrl { get; set; }

[TempData]
public string ErrorMessage { get; set; }
[TempData] public string ErrorMessage { get; set; }

public class InputModel
{
[Required]
[EmailAddress]
public string Email { get; set; }
[Required] [EmailAddress] public string Email { get; set; }
}

public IActionResult OnGetAsync()
Expand All @@ -62,7 +58,7 @@ public IActionResult OnGetAsync()
public IActionResult OnPost(string provider, string returnUrl = null)
{
// Request a redirect to the external login provider.
var redirectUrl = Url.Page("./ExternalLogin", pageHandler: "Callback", values: new { returnUrl });
var redirectUrl = Url.Page("./ExternalLogin", "Callback", new {returnUrl});
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
return new ChallengeResult(provider, properties);
}
Expand All @@ -73,22 +69,26 @@ public async Task<IActionResult> OnGetCallbackAsync(string returnUrl = null, str
if (remoteError != null)
{
ErrorMessage = $"Error from external provider: {remoteError}";
return RedirectToPage("./Login", new {ReturnUrl = returnUrl });
return RedirectToPage("./Login", new {ReturnUrl = returnUrl});
}

var info = await _signInManager.GetExternalLoginInfoAsync();
if (info == null)
{
ErrorMessage = "Error loading external login information.";
return RedirectToPage("./Login", new { ReturnUrl = returnUrl });
return RedirectToPage("./Login", new {ReturnUrl = returnUrl});
}

// Sign in the user with this external login provider if the user already has a login.
var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false, bypassTwoFactor : true);
var result =
await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, false, true);
if (result.Succeeded)
{
_logger.LogInformation("{Name} logged in with {LoginProvider} provider.", info.Principal.Identity.Name, info.LoginProvider);
_logger.LogInformation("{Name} logged in with {LoginProvider} provider.", info.Principal.Identity.Name,
info.LoginProvider);
return LocalRedirect(returnUrl);
}

if (result.IsLockedOut)
{
return RedirectToPage("./Lockout");
Expand All @@ -99,12 +99,10 @@ public async Task<IActionResult> OnGetCallbackAsync(string returnUrl = null, str
ReturnUrl = returnUrl;
ProviderDisplayName = info.ProviderDisplayName;
if (info.Principal.HasClaim(c => c.Type == ClaimTypes.Email))
{
Input = new InputModel
{
Email = info.Principal.FindFirstValue(ClaimTypes.Email)
};
}
return Page();
}
}
Expand All @@ -117,12 +115,12 @@ public async Task<IActionResult> OnPostConfirmationAsync(string returnUrl = null
if (info == null)
{
ErrorMessage = "Error loading external login information during confirmation.";
return RedirectToPage("./Login", new { ReturnUrl = returnUrl });
return RedirectToPage("./Login", new {ReturnUrl = returnUrl});
}

if (ModelState.IsValid)
{
var user = new TRPZ_PrintServiceUser { UserName = Input.Email, Email = Input.Email };
var user = new TRPZ_PrintServiceUser {UserName = Input.Email, Email = Input.Email};

var result = await _userManager.CreateAsync(user);
if (result.Succeeded)
Expand All @@ -137,33 +135,29 @@ public async Task<IActionResult> OnPostConfirmationAsync(string returnUrl = null
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
var callbackUrl = Url.Page(
"/Account/ConfirmEmail",
pageHandler: null,
values: new { area = "Identity", userId = userId, code = code },
protocol: Request.Scheme);
null,
new {area = "Identity", userId = userId, code = code},
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 account confirmation is required, we need to show the link if we don't have a real email sender
if (_userManager.Options.SignIn.RequireConfirmedAccount)
{
return RedirectToPage("./RegisterConfirmation", new { Email = Input.Email });
}
return RedirectToPage("./RegisterConfirmation", new {Email = Input.Email});

await _signInManager.SignInAsync(user, isPersistent: false, info.LoginProvider);
await _signInManager.SignInAsync(user, false, info.LoginProvider);

return LocalRedirect(returnUrl);
}
}
foreach (var error in result.Errors)
{
ModelState.AddModelError(string.Empty, error.Description);
}

foreach (var error in result.Errors) ModelState.AddModelError(string.Empty, error.Description);
}

ProviderDisplayName = info.ProviderDisplayName;
ReturnUrl = returnUrl;
return Page();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

<h1>@ViewData["Title"]</h1>
<h4>Enter your email.</h4>
<hr />
<hr/>
<div class="row">
<div class="col-md-4">
<form method="post">
<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" />
<input asp-for="Input.Email" class="form-control"/>
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
Expand All @@ -22,5 +22,5 @@
</div>

@section Scripts {
<partial name="_ValidationScriptsPartial" />
}
<partial name="_ValidationScriptsPartial"/>
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,31 @@ public ForgotPasswordModel(UserManager<TRPZ_PrintServiceUser> userManager, IEmai
_emailSender = emailSender;
}

[BindProperty]
public InputModel Input { get; set; }
[BindProperty] public InputModel Input { get; set; }

public class InputModel
{
[Required]
[EmailAddress]
public string Email { get; set; }
[Required] [EmailAddress] public string Email { get; set; }
}

public async Task<IActionResult> OnPostAsync()
{
if (ModelState.IsValid)
{
var user = await _userManager.FindByEmailAsync(Input.Email);
if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
{
if (user == null || !await _userManager.IsEmailConfirmedAsync(user))
// Don't reveal that the user does not exist or is not confirmed
return RedirectToPage("./ForgotPasswordConfirmation");
}

// For more information on how to enable account confirmation and password reset please
// visit https://go.microsoft.com/fwlink/?LinkID=532713
var code = await _userManager.GeneratePasswordResetTokenAsync(user);
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
var callbackUrl = Url.Page(
"/Account/ResetPassword",
pageHandler: null,
values: new { area = "Identity", code },
protocol: Request.Scheme);
null,
new {area = "Identity", code},
Request.Scheme);

await _emailSender.SendEmailAsync(
Input.Email,
Expand All @@ -68,4 +63,4 @@ await _emailSender.SendEmailAsync(
return Page();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
<h1>@ViewData["Title"]</h1>
<p>
Please check your email to reset your password.
</p>

</p>
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public void OnGet()
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<header>
<h1 class="text-danger">@ViewData["Title"]</h1>
<p class="text-danger">This account has been locked out, please try again later.</p>
</header>
</header>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class LockoutModel : PageModel
{
public void OnGet()
{

}
}
}
}
Loading

0 comments on commit 85c87f7

Please sign in to comment.