Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recaptcha on password reset and email verification #60

Merged
merged 6 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Logging;
using Opc.Ua.Cloud.Library.Authentication;

namespace Opc.Ua.Cloud.Library.Areas.Identity.Pages.Account
{
Expand Down Expand Up @@ -171,8 +172,11 @@ public async Task<IActionResult> OnPostConfirmationAsync(string returnUrl = null
values: new { area = "Identity", userId = userId, code = code },
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>.").ConfigureAwait(false);
await EmailManager.SendConfirmExternalEmail(
_emailSender,
Input.Email,
callbackUrl
).ConfigureAwait(false);

// 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.WebUtilities;
using Opc.Ua.Cloud.Library.Authentication;

namespace Opc.Ua.Cloud.Library.Areas.Identity.Pages.Account
{
Expand Down Expand Up @@ -71,16 +72,11 @@ public async Task<IActionResult> OnPostAsync()
protocol: Request.Scheme);

//notify user of password reset w/ reset link
StringBuilder sbBody = new StringBuilder();
sbBody.AppendLine("<h1>Reset Password</h1>");
sbBody.AppendLine("<p>A request has been made to reset your password in the CESMII Cloud Library.");
sbBody.AppendLine($"<b>Please click here to <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>reset your password</a>.</b></p>");
sbBody.AppendLine("<p>If you did not make this request, please contact the <a href='mailto:[email protected]'>CESMII DevOps Team</a>.</p>");
sbBody.AppendLine("<p>The CESMII UA Cloud Library is hosted by <a href='https://www.cesmii.org/'>CESMII</a>, the Clean Energy Smart Manufacturing Institute! This Cloud Library contains curated node sets created by CESMII or its members, as well as node sets from the <a href='https://uacloudlibrary.opcfoundation.org/'>OPC Foundation Cloud Library</a>.</p>");
sbBody.AppendLine("<p>Sincerely,<br />CESMII DevOps Team</p>");

await _emailSender.SendEmailAsync(Input.Email, "CESMII | Cloud Library | Reset Password",
sbBody.ToString()).ConfigureAwait(false);
await EmailManager.SendPasswordReset(
_emailSender,
Input.Email,
callbackUrl
).ConfigureAwait(false);

return RedirectToPage("./ForgotPasswordConfirmation");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.WebUtilities;
using Opc.Ua.Cloud.Library.Authentication;

namespace Opc.Ua.Cloud.Library.Areas.Identity.Pages.Account.Manage
{
Expand Down Expand Up @@ -121,10 +122,12 @@ public async Task<IActionResult> OnPostChangeEmailAsync()
pageHandler: null,
values: new { area = "Identity", userId = userId, email = Input.NewEmail, code = code },
protocol: Request.Scheme);
await _emailSender.SendEmailAsync(

await EmailManager.SendConfirmEmailChange(
_emailSender,
Input.NewEmail,
"Confirm your email",
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.").ConfigureAwait(false);
callbackUrl
).ConfigureAwait(false);

StatusMessage = "Confirmation link to change email sent. Please check your email.";
return RedirectToPage();
Expand Down Expand Up @@ -157,10 +160,12 @@ public async Task<IActionResult> OnPostSendVerificationEmailAsync()
pageHandler: null,
values: new { area = "Identity", userId = userId, code = code },
protocol: Request.Scheme);
await _emailSender.SendEmailAsync(
email,
"Confirm your email",
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.").ConfigureAwait(false);

await EmailManager.SendReconfirmEmail(
_emailSender,
Input.NewEmail,
callbackUrl
).ConfigureAwait(false);

StatusMessage = "Verification email sent. Please check your email.";
return RedirectToPage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</td>
<td>
<div>
@Model.GeneratedApiKey
@Model.GeneratedApiKey
<clipboard-copy value="@Model.GeneratedApiKey" title="Copy to clipboard" class="btn btn-sm" style="line-height: 1;vertical-align: top;padding-top: 0px;padding-bottom: 0px">
<span class="copyButton">
<svg height="16" width="16">
Expand All @@ -63,7 +63,7 @@
</tbody>
</table>
<div class="alert">
Usage: Add an HTTP Header X-Api-key with the API key as the header value.
Usage: Add an HTTP Header X-Api-key with the API key as the header value.
Note that the key name does not need to be provided separately for authentication.
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.Encodings.Web;
Expand All @@ -18,6 +19,7 @@
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Opc.Ua.Cloud.Library.Authentication;

namespace Opc.Ua.Cloud.Library.Areas.Identity.Pages.Account
{
Expand Down Expand Up @@ -166,26 +168,12 @@ public async Task<IActionResult> OnPostAsync(string returnUrl = null)
protocol: Request.Scheme);

//notify registering user
StringBuilder sbBody = new StringBuilder();
sbBody.AppendLine("<h1>Welcome to the CESMII UA Cloud Library</h1>");
sbBody.AppendLine("<p>Thank you for creating an account on the CESMII UA Cloud Library. ");
if (_userManager.Options.SignIn.RequireConfirmedAccount)
{
sbBody.AppendLine($"<b>Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.</b></p>");
}
sbBody.AppendLine("<p>The CESMII UA Cloud Library is hosted by <a href='https://www.cesmii.org/'>CESMII</a>, the Clean Energy Smart Manufacturing Institute! This Cloud Library contains curated node sets created by CESMII or its members, as well as node sets from the <a href='https://uacloudlibrary.opcfoundation.org/'>OPC Foundation Cloud Library</a>.</p>");
sbBody.AppendLine("<p>Sincerely,<br />CESMII DevOps Team</p>");

await _emailSender.SendEmailAsync(Input.Email, "CESMII | Cloud Library | New Account Confirmation",
sbBody.ToString());

//notify CESMII dev ops as well
StringBuilder sbBody2 = new StringBuilder();
sbBody2.AppendLine("<h1>CESMII UA Cloud Library - New Account Sign Up</h1>");
sbBody2.AppendLine($"<p>User <b>'{Input.Email}'</b> created an account on the CESMII UA Cloud Library. ");
sbBody2.AppendLine("<p>The CESMII UA Cloud Library is hosted by <a href='https://www.cesmii.org/'>CESMII</a>, the Clean Energy Smart Manufacturing Institute! This Cloud Library contains curated node sets created by CESMII or its members, as well as node sets from the <a href='https://uacloudlibrary.opcfoundation.org/'>OPC Foundation Cloud Library</a>.</p>");
sbBody2.AppendLine("<p>Sincerely,<br />CESMII DevOps Team</p>");
await _emailSender.SendEmailAsync("[email protected]", "CESMII | Cloud Library | New Account Sign Up", sbBody2.ToString()).ConfigureAwait(false);
await EmailManager.SendConfirmRegistration(
_emailSender,
Input.Email,
callbackUrl,
_userManager.Options.SignIn.RequireConfirmedAccount
).ConfigureAwait(false);

if (_userManager.Options.SignIn.RequireConfirmedAccount)
{
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,15 @@
namespace Opc.Ua.Cloud.Library.Authentication
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Security.Claims;
using System.Text;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
using Opc.Ua.Cloud.Library.Interfaces;

public class BasicAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,13 @@
namespace Opc.Ua.Cloud.Library.Authentication
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Security.Claims;
using System.Text;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
using Opc.Ua.Cloud.Library.Interfaces;

public class SignedInUserAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
{
Expand Down
Loading
Loading