diff --git a/Yavsc/Controllers/AccountController.cs b/Yavsc/Controllers/AccountController.cs index 8c16babc..a65d9214 100644 --- a/Yavsc/Controllers/AccountController.cs +++ b/Yavsc/Controllers/AccountController.cs @@ -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 { @@ -49,7 +46,7 @@ namespace Yavsc.Controllers IOptions siteSettings, IOptions smtpSettings, ILoggerFactory loggerFactory, IOptions twilioSettings, - IStringLocalizer localizer, + IStringLocalizer localizer, ApplicationDbContext dbContext) { _userManager = userManager; @@ -65,8 +62,8 @@ namespace Yavsc.Controllers _dbContext = dbContext; } - [Authorize(Roles=Constants.AdminGroupName)] - public async Task UserList () + [Authorize(Roles = Constants.AdminGroupName)] + public async Task UserList() { return View(await _dbContext.Users.ToArrayAsync()); } @@ -95,10 +92,10 @@ namespace Yavsc.Controllers { ViewBag.UserIsSignedIn = User.IsSignedIn(); if (string.IsNullOrWhiteSpace(requestUrl)) - if (string.IsNullOrWhiteSpace(Request.Headers["Referer"])) - requestUrl = "/"; + if (string.IsNullOrWhiteSpace(Request.Headers["Referer"])) + requestUrl = "/"; else requestUrl = Request.Headers["Referer"]; - return View("AccessDenied",requestUrl); + return View("AccessDenied", requestUrl); } [AllowAnonymous] @@ -216,7 +213,7 @@ namespace Yavsc.Controllers if (result.Succeeded) { _logger.LogInformation(3, "User created a new account with password."); - await _emailSender.SendEmailAsync(_siteSettings, _smtpSettings, Startup.SiteSetup.Owner.EMail, + await _emailSender.SendEmailAsync(_siteSettings, _smtpSettings, Startup.SiteSetup.Owner.EMail, $"[{_siteSettings.Title}] Inscription avec mot de passe: {user.UserName} ", $"{user.Id}/{user.UserName}/{user.Email}"); // TODO user.DiskQuota = Startup.SiteSetup.UserFiles.Quota; @@ -224,20 +221,23 @@ 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: link"); - await _signInManager.SignInAsync(user, isPersistent: false); - if (!emailSent) { + 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) + { _logger.LogWarning("User created with error sending email confirmation request"); - this.NotifyWarning ( + this.NotifyWarning( "E-mail confirmation", _localizer["ErrorSendingEmailForConfirm"] - ) ; - } else this.NotifyInfo ( - "E-mail confirmation", - _localizer["EmailSentForConfirm"] - ) ; - + ); + } + else + this.NotifyInfo( + "E-mail confirmation", + _localizer["EmailSentForConfirm"] + ); + return View("AccountCreated"); } AddErrors(result); @@ -247,15 +247,22 @@ namespace Yavsc.Controllers return View(model); } - [Authorize,HttpPost,ValidateAntiForgeryToken] - public async Task SendEMailForConfirm () { - var user = await _userManager.FindByIdAsync( User.GetUserId() ); - 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", - "Please confirm your account by clicking this link: link"); + [Authorize, HttpPost, ValidateAntiForgeryToken] + public async Task SendEMailForConfirm() + { + var user = await _userManager.FindByIdAsync(User.GetUserId()); + ViewBag.EmailSent = SendEMailForConfirm(user); return View("ConfirmEmailSent"); } + + private async Task 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); + var res = await _emailSender.SendEmailAsync(_siteSettings, _smtpSettings, user.Email, "Confirm your account", + "Please confirm your account by clicking this link: link"); + return res; + } // // POST: /Account/LogOff [HttpPost(Constants.LogoutPath)] @@ -282,14 +289,14 @@ namespace Yavsc.Controllers } // Sign in the user with this external login provider if the user already has a login. - info.ProviderDisplayName = info.ExternalPrincipal.Claims.First(c=>c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")?.Value; + info.ProviderDisplayName = info.ExternalPrincipal.Claims.First(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")?.Value; var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false); if (result.Succeeded) { - _logger.LogInformation(5, $"User logged in with {info.LoginProvider} provider, as {info.ProviderDisplayName} ({info.ProviderKey})." ); + _logger.LogInformation(5, $"User logged in with {info.LoginProvider} provider, as {info.ProviderDisplayName} ({info.ProviderKey})."); - var ninfo = _dbContext.UserLogins.First(l=>l.ProviderKey == info.ProviderKey && l.LoginProvider == info.LoginProvider); + var ninfo = _dbContext.UserLogins.First(l => l.ProviderKey == info.ProviderKey && l.LoginProvider == info.LoginProvider); ninfo.ProviderDisplayName = info.ProviderDisplayName; _dbContext.Entry(ninfo).State = EntityState.Modified; _dbContext.SaveChanges(User.GetUserId()); @@ -357,7 +364,7 @@ namespace Yavsc.Controllers var result = await _userManager.CreateAsync(user); if (result.Succeeded) { - info.ProviderDisplayName = info.ExternalPrincipal.Claims.First(c=>c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")?.Value; + info.ProviderDisplayName = info.ExternalPrincipal.Claims.First(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")?.Value; result = await _userManager.AddLoginAsync(user, info); if (result.Succeeded) @@ -365,8 +372,8 @@ namespace Yavsc.Controllers await _signInManager.SignInAsync(user, isPersistent: false); - await _emailSender.SendEmailAsync(_siteSettings, _smtpSettings, Startup.SiteSetup.Owner.EMail, - $"[{_siteSettings.Title}] Inscription via {info.LoginProvider}: {user.UserName} ", $"{user.Id}/{user.UserName}/{user.Email}"); + await _emailSender.SendEmailAsync(_siteSettings, _smtpSettings, Startup.SiteSetup.Owner.EMail, + $"[{_siteSettings.Title}] Inscription via {info.LoginProvider}: {user.UserName} ", $"{user.Id}/{user.UserName}/{user.Email}"); _logger.LogInformation(6, "User created an account using {Name} provider.", info.LoginProvider); @@ -419,9 +426,10 @@ 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) + if (user == null) { _logger.LogWarning($"ForgotPassword: Email or User name {model.LoginOrEmail} not found"); return View("ForgotPasswordConfirmation"); @@ -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"); } @@ -439,8 +448,8 @@ namespace Yavsc.Controllers // Send an email with this link var code = await _userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); - await _emailSender.SendEmailAsync(_siteSettings,_smtpSettings,model.LoginOrEmail, _localizer["Reset Password"], - _localizer["Please reset your password by following this link:"] +" <"+ callbackUrl +">" ); + await _emailSender.SendEmailAsync(_siteSettings, _smtpSettings, model.LoginOrEmail, _localizer["Reset Password"], + _localizer["Please reset your password by following this link:"] + " <" + callbackUrl + ">"); return View("ForgotPasswordConfirmation"); } @@ -640,7 +649,7 @@ namespace Yavsc.Controllers { foreach (var error in result.Errors) { - ModelState.AddModelError(string.Empty, _localizer[ error.Code ]); + ModelState.AddModelError(string.Empty, _localizer[error.Code]); } } @@ -648,7 +657,7 @@ namespace Yavsc.Controllers { return await _userManager.FindByIdAsync(HttpContext.User.GetUserId()); } - + #endregion } } diff --git a/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.en.resources b/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.en.resources deleted file mode 100644 index 31e1440c..00000000 Binary files a/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.en.resources and /dev/null differ diff --git a/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.en.resx b/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.en.resx index de8d8e65..5b952b31 100644 --- a/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.en.resx +++ b/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.en.resx @@ -774,4 +774,13 @@ Valid caracters are: underscore '_', '-', 'a' - 'z', 'A' - 'Z', '0' - '9', th An email has been sent to confirm your addresse. - \ No newline at end of file + Please, confirm your e-mail + You successfully created your {0} account, +but your e-mail address is not yet confirmed. +Please, in order to validate it, follow this link <{1}>. + +Thanks. +-- +{0} - {2} <https://{3}> + + diff --git a/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resources b/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resources deleted file mode 100644 index 1b01e4bc..00000000 Binary files a/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resources and /dev/null differ diff --git a/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx b/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx index 68b3b78c..843c3ca4 100644 --- a/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx +++ b/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx @@ -449,5 +449,11 @@ Confirmation du mot de passe L'envoi de de courrier pour confirmation de l'adresse e-mail a échoué. Un courrier a été envoyé pour confirmation de l'adresse e-mail . + S'il vous plait, confirmez votre addresse e-mail + Vous avez créé avec succès votre compte {0}, +mais votre adresse e-mail reste à confirmer. +Pour ce faire, suivez le lien suivant : <{1}>. +-- +{0} - {2} <{3}>