Ejemplo n.º 1
0
        public object UserSendPasswordResetEmailById(Guid userId)
        {
            var user = Database.PlayerData.User.Find(userId);

            if (user == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $@"No user with name '{userId}'."));
            }

            if (Options.Smtp.IsValid())
            {
                var email = new PasswordResetEmail(user);
                if (email.Send())
                {
                    return(Request.CreateMessageResponse(HttpStatusCode.OK, "Password reset email sent."));
                }

                return(Request.CreateMessageResponse(HttpStatusCode.InternalServerError, "Failed to send reset email."));
            }
            else
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.NotFound,
                           "Could not send password reset email, SMTP settings on the server are not configured!"
                           ));
            }
        }
Ejemplo n.º 2
0
        public async Task <CommandResult> Handle(ForgotPasswordCommand email)
        {
            var user = userRepo.Get(email.Email);

            if (user == null)
            {
                return(CommandResult.Fail());
            }
            user.ValidationCodes = user.ValidationCodes.Where(v => v.Type != ValidationCodeType.PasswordReset).ToList();

            var code = new ValidationCode()
            {
                Code        = codeGenerator.Generate(30),
                CreatedDate = DateTime.Now,
                Type        = ValidationCodeType.PasswordReset,
            };

            user.ValidationCodes.Add(code);
            userRepo.Update(user);

            var em = new PasswordResetEmail()
            {
                To  = user.Credentials.Email,
                Url = string.Format(appSettings.PasswordResetUrl, user.Id.ToString(), code.Code)
            };
            await emailSender.Send(em);

            return(CommandResult.Success());
        }
Ejemplo n.º 3
0
        public static PasswordResetEmail PasswordReset(string to, string password, string loginUrl)
        {
            PasswordResetEmail email = CreateEmail <PasswordResetEmail>(to, "Password reset");

            email.Password = password;
            email.LoginUrl = CombineUrl(loginUrl);
            return(email);
        }
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                SchedulerUser user = await UserManager.FindByNameAsync(model.Email);

                if (user == null)
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPasswordConfirmation"));
                }

                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

                //await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");

                #region create and send email with postal instead usermanager

                var email = new PasswordResetEmail
                {
                    ReceiverEmail    = user.Email,
                    ReceiverName     = user.FirstName,
                    AdminEmail       = "*****@*****.**",
                    EmailSubject     = "Reset password",
                    PassWordRestLink = callbackUrl
                };

                PostalEmailManager.SendResetPassword(email);

                #endregion

                return(RedirectToAction("ForgotPasswordConfirmation", "Account", new { userEmail = model.Email }));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                SchedulerUser user = await UserManager.FindByNameAsync(model.Email);
                if (user == null)
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return View("ForgotPasswordConfirmation");
                }

                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

                //await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");

                #region create and send email with postal instead usermanager

                var email = new PasswordResetEmail
                                {
                                    ReceiverEmail = user.Email,
                                    ReceiverName = user.FirstName + " " + user.LastName,
                                    AdminEmail = "*****@*****.**",
                                    EmailSubject = "Reset password",
                                    PassWordRestLink = callbackUrl
                                };

                PostalEmailManager.SendResetPassword(email);

                #endregion

                return RedirectToAction("ForgotPasswordConfirmation", "Account", new { userEmail = model.Email });
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public static void SendResetPassword(PasswordResetEmail resetEmail)
        {
            dynamic email = new Email("ResetPassword");

            email.To = resetEmail.ReceiverEmail;
            email.From = "*****@*****.**";
            email.EmailSubject = resetEmail.EmailSubject;

            email.Name = resetEmail.ReceiverName;
            email.ResetLink = resetEmail.PassWordRestLink;

            SendCorespondingEmail(email);
        }