Ejemplo n.º 1
0
        public async Task <IHttpActionResult> PostForgot(JObject value)
        {
            var email = (string)value["email"];

            if (!String.IsNullOrEmpty(email))
            {
                var user = await OwinUserManager.FindByEmailAsync(email.Trim());

                if (user != null)
                {
                    if (await OwinUserManager.IsEmailConfirmedAsync(user.Id))
                    {
                        // Send the link.
                        var token = await OwinUserManager.GeneratePasswordResetTokenAsync(user.Id);

                        var queryString = AccountUtils.GetMailLinkQueryString(token, user.Id);
                        var host        = Request.RequestUri.GetComponents(UriComponents.Host, UriFormat.Unescaped);
                        var link        = "https://" + host + "/account/reset-password?" + queryString;
                        await EmailUtils.SendPasswordResetEmailAsync(email, link);
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Send the confirmation link in background
 /// </summary>
 /// <param name="email"></param>
 /// <param name="userId"></param>
 /// <param name="confirmationToken"></param>
 /// <param name="currentRequestUri">It is used to determine the server address (production/development) where the confirmation link should point</param>
 public async Task SendConfirmationEmail(string email, int userId, string displayName, string confirmationToken, Uri currentRequestUri)
 //public void SendConfirmationEmailInBackground(string email, int userId, string displayName, string confirmationToken, Uri currentRequestUri)
 {
     var queryString = AccountUtils.GetMailLinkQueryString(confirmationToken, userId);
     var host        = currentRequestUri.GetComponents(UriComponents.Host, UriFormat.Unescaped);
     var link        = "http://" + host + "/account/confirm-email?" + queryString;
     // TODO If the task fails, we will lose the message. The proper solution is to place the message into a reliable queue.
     //HostingEnvironment.QueueBackgroundWorkItem(ct => EmailUtils.SendConfirmationEmailAsync(email, displayName, link));
     await EmailUtils.SendConfirmationEmailAsync(email, displayName, link);
 }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> PutEmail(JObject value)
        {
            var userId = this.GetUserId();

            // TODO. Store the old confirmed email. To replace a confirmed email with an unconfirmed one is a bed idea. But we have no infrastructure currently to store an unconfirmed email temporarily.
            if (await OwinUserManager.IsEmailConfirmedAsync(userId))
            {
                return(BadRequest("Unable to change a confirmed email address."));
            }

            var email = (string)value["email"];

            if (String.IsNullOrWhiteSpace(email))
            {
                return(BadRequest());
            }
            email = email.Trim();

            var result = await OwinUserManager.SetEmailAsync(userId, email);

            if (result.Succeeded)
            {
                var confirmationToken = await OwinUserManager.GenerateEmailConfirmationTokenAsync(userId);

                var queryString = AccountUtils.GetMailLinkQueryString(confirmationToken, userId);
                var host        = Request.RequestUri.GetComponents(UriComponents.Host, UriFormat.Unescaped);
                var link        = "http://" + host + "/account/confirm-email?" + queryString;
                var displayName = this.GetUserDisplayName();
                await EmailUtils.SendVerificationEmailAsync(email, displayName, link);

                return(StatusCode(HttpStatusCode.NoContent));
            }
            else
            {
                return(BadRequest(result.PlainErrorMessage("Failed to change email address.")));
            }
        }