|
|
|
|
@ -14,12 +14,9 @@ using Microsoft.AspNet.Http;
|
|
|
|
|
using Yavsc.Models;
|
|
|
|
|
using Yavsc.Services;
|
|
|
|
|
using Yavsc.ViewModels.Account;
|
|
|
|
|
using Yavsc.Helpers;
|
|
|
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
|
using Microsoft.Data.Entity;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Yavsc.Models.Messaging;
|
|
|
|
|
|
|
|
|
|
namespace Yavsc.Controllers
|
|
|
|
|
{
|
|
|
|
|
@ -224,16 +221,19 @@ namespace Yavsc.Controllers
|
|
|
|
|
// Send an email with this link
|
|
|
|
|
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
|
|
|
|
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
|
|
|
|
|
var emailSent = await _emailSender.SendEmailAsync(_siteSettings, _smtpSettings, model.Email, "Confirm your account",
|
|
|
|
|
"Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
|
|
|
|
|
var emailSent = await _emailSender.SendEmailAsync(_siteSettings, _smtpSettings, model.Email, _localizer["ConfirmYourAccountTitle"],
|
|
|
|
|
string.Format(_localizer["ConfirmYourAccountBody"], _siteSettings.Title, callbackUrl, _siteSettings.Slogan, _siteSettings.Audience));
|
|
|
|
|
await _signInManager.SignInAsync(user, isPersistent: false);
|
|
|
|
|
if (!emailSent) {
|
|
|
|
|
if (!emailSent)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("User created with error sending email confirmation request");
|
|
|
|
|
this.NotifyWarning(
|
|
|
|
|
"E-mail confirmation",
|
|
|
|
|
_localizer["ErrorSendingEmailForConfirm"]
|
|
|
|
|
);
|
|
|
|
|
} else this.NotifyInfo (
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
this.NotifyInfo(
|
|
|
|
|
"E-mail confirmation",
|
|
|
|
|
_localizer["EmailSentForConfirm"]
|
|
|
|
|
);
|
|
|
|
|
@ -248,13 +248,20 @@ namespace Yavsc.Controllers
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authorize, HttpPost, ValidateAntiForgeryToken]
|
|
|
|
|
public async Task <IActionResult> SendEMailForConfirm () {
|
|
|
|
|
public async Task<IActionResult> SendEMailForConfirm()
|
|
|
|
|
{
|
|
|
|
|
var user = await _userManager.FindByIdAsync(User.GetUserId());
|
|
|
|
|
ViewBag.EmailSent = SendEMailForConfirm(user);
|
|
|
|
|
return View("ConfirmEmailSent");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<bool> SendEMailForConfirm(ApplicationUser user)
|
|
|
|
|
{
|
|
|
|
|
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
|
|
|
|
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
|
|
|
|
|
await _emailSender.SendEmailAsync(_siteSettings, _smtpSettings, user.Email, "Confirm your account",
|
|
|
|
|
var res = await _emailSender.SendEmailAsync(_siteSettings, _smtpSettings, user.Email, "Confirm your account",
|
|
|
|
|
"Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
|
|
|
|
|
return View("ConfirmEmailSent");
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
// POST: /Account/LogOff
|
|
|
|
|
@ -419,7 +426,8 @@ namespace Yavsc.Controllers
|
|
|
|
|
var user = await _userManager.FindByEmailAsync(model.LoginOrEmail);
|
|
|
|
|
|
|
|
|
|
// Don't reveal that the user does not exist or is not confirmed
|
|
|
|
|
if (user == null) {
|
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
user = await _userManager.FindByNameAsync(model.LoginOrEmail);
|
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
@ -430,7 +438,8 @@ namespace Yavsc.Controllers
|
|
|
|
|
// user != null
|
|
|
|
|
// We want him to have a confirmed e-mail, and prevent this script
|
|
|
|
|
// to be used to send e-mail to any arbitrary person
|
|
|
|
|
if (!await _userManager.IsEmailConfirmedAsync(user)) {
|
|
|
|
|
if (!await _userManager.IsEmailConfirmedAsync(user))
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning($"ForgotPassword: Email {model.LoginOrEmail} not confirmed");
|
|
|
|
|
return View("ForgotPasswordConfirmation");
|
|
|
|
|
}
|
|
|
|
|
|