Esempio n. 1
0
        public ActionResult PasswordRecovery(PasswordRecoveryModel model)
        {
            var student = _studentService.GetStudentByUsername(model.Username);

            if (student == null && !student.StudentRoles.Contains(_studentService.GetStudentRoleBySystemName(SystemStudentRoleNames.Administrators)))
            {
                ModelState.AddModelError("", "Username not found");
            }

            if (ModelState.IsValid)
            {
                var response = _studentRegistrationService.ChangePassword(new ChangePasswordRequest(model.Username,
                                                                                                    false, model.Password));

                model.Result = "Password has been changed.";
                model.SuccessfullyChanged = true;

                //activity log
                _studentActivityService.InsertActivity("Game.PasswordRecovery.Success", "ActivityLog.Game.PasswordRecovery.Success");

                return(View(model));
            }

            //If we got this far, something failed, redisplay form

            //activity log
            _studentActivityService.InsertActivity("Game.PasswordRecovery.Fail", "ActivityLog.Game.PasswordRecovery.Fail");

            return(View(model));
        }
Esempio n. 2
0
        public virtual IActionResult PasswordRecoverySend(PasswordRecoveryModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _userService.GetUserByEmail(model.Email);
                if (user != null && !user.Deleted)
                {
                    //save token and current date
                    var passwordRecoveryToken = Guid.NewGuid();
                    _genericAttributeService.SaveAttribute(user, AldanUserDefaults.PasswordRecoveryTokenAttribute,
                                                           passwordRecoveryToken.ToString());
                    DateTime?generatedDateTime = DateTime.UtcNow;
                    _genericAttributeService.SaveAttribute(user,
                                                           AldanUserDefaults.PasswordRecoveryTokenDateGeneratedAttribute, generatedDateTime);

                    //send email
                    _workflowMessageService.SendUserPasswordRecoveryMessage(user);

                    model.Result = "Email with instructions has been sent to you.";
                }
                else
                {
                    model.Result = "Email not found.";
                }

                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 3
0
        public ActionResult PasswordRecovery(PasswordRecoveryModel model)
        {
            var result = _readOnlyRepository.First <Account>(a => a.EMail == model.EMailAddress);

            if (result != null)
            {
                var fechaActual = DateTime.Now.Date;

                var pass  = result.Password;
                var data  = "" + fechaActual.Day + fechaActual.Month + fechaActual.Year;
                var token = pass + ";" + EncriptacionMD5.Encriptar(data);

                //var url = "http://Galeria-1.apphb.com/PasswordReset/PasswordReset";
                var url = "http://Galeriaclase.apphb.com/PasswordReset/PasswordReset";

                var emailBody = new StringBuilder("<b>Go to the following link to change your password: </b>");
                emailBody.Append("<br/>");
                emailBody.Append("<br/>");
                emailBody.Append("<b>" + url + "?token=" + token + "<b>");
                emailBody.Append("<br/>");
                emailBody.Append("<br/>");
                emailBody.Append("<b>This link is only valid through " + fechaActual.Day + "/" + fechaActual.Month + "/" + fechaActual.Year + "</b>");

                if (MailSender.SendEmail(model.EMailAddress, "Password Recovery", emailBody.ToString()))
                {
                    return(Cancel());
                }

                Error("E-Mail failed to be sent, please try again!!!");
                return(View(model));
            }

            Error("E-Mail address is not registered in this site!!!");
            return(View(model));
        }
Esempio n. 4
0
        public async Task <IActionResult> Post([FromBody] PasswordRecoveryModel model)
        {
            var users = await this.userService.GetAll(email : model.Email);

            if (users.Count > 0)
            {
                var token = StringHelpers.ToSha1(StringHelpers.GetRandomString(15));

                var user = users.FirstOrDefault();
                user.PasswordRecoveryToken = token;

                var url = this.seoService.GetFullRoute("passwordrecovery", token);

                await this.userService.Update(user);

                await this.notificationService.NewNotification(
                    user,
                    null,
                    Data.NotificationType.PasswordRecovery,
                    url,
                    new List <NotificationParameter>());

                return(this.Ok());
            }
            else
            {
                return(this.NotFound());
            }
        }
        public async Task <IActionResult> PasswordRecoveryFormAction(PasswordRecoveryModel model)
        {
            int    id;
            string code = await _moneyUserManager.GeneratePasswordResetTokenAsync(model.Email);

            if (code == null)
            {
                return(View(nameof(AccountController.Login)));
            }

            try
            {
                id = await _moneyUserManager.GetUserIdAsync(model.Email);
            }
            catch
            {
                return(View(nameof(AccountController.Login)));
            }

            string callbackUrl = Url.ResetPasswordCallbackLink(id, code, Request.Scheme);

            await _emailSender.SendEmailAsync(model.Email, "Password recovery", $"Please reset your password on PVT.Money by clicking here: <a href='{callbackUrl}'>link</a>");

            string userName = await _moneyUserManager.GetUserNameAsync(model.Email);

            if (userName != null)
            {
                await _logManager.WriteAsync(userName, $"User '{userName}' requested password recovery.");
            }

            return(View("Login"));
        }
Esempio n. 6
0
        public async Task <IHttpActionResult> ResetPassword(PasswordRecoveryModel passwordRecoveryModel)
        {
            if (!ModelState.IsValid)
            {
                var message = responseService.ModelStateErrorsToString(ModelState);
                return(BadRequest(message));
            }

            IdentityUser user = await repository.FindUserByEmail(passwordRecoveryModel.Email);

            if (user == null)
            {
                return(BadRequest("User not found."));
            }

            var result = await repository.ResetPassword(user.Id, passwordRecoveryModel.Token, passwordRecoveryModel.Password);

            if (!result.Succeeded)
            {
                var message = responseService.IdentityResultErrorsToString(result.Errors);
                return(BadRequest(message));
            }

            return(Ok());
        }
        public virtual ActionResult Recovery(PasswordRecoveryModel model)
        {
            try
            {
                User user = null;

                if (!string.IsNullOrEmpty(model.Email))
                {
                    user = service.GetUserByEmail(model.Email);
                }

                if (user == null)
                {
                    return(new AjaxResult().Alert(T("Email not found. Please try again.")));
                }

                var passwordVerificationToken = service.GeneratePasswordResetToken(user, 1440);

                eventBus.Notify <IMembershipEventHandler>(x => x.PasswordReset(user, passwordVerificationToken));

                return(new AjaxResult()
                       .Alert(T("Email with instructions has been sent to you."))
                       .Redirect(Url.Action("ResetPassword")));
            }
            catch (Exception)
            {
                return(new AjaxResult().Alert(T(SecurityConstants.ResetPasswordError)));
            }
        }
        public async Task <IActionResult> PasswordRecovery(PasswordRecoveryModel model)
        {
            if (ModelState.IsValid)
            {
                var customer = await _userManager.FindByEmailAsync(model.Email);

                if (customer != null && customer.Active)
                {
                    var token = await _userManager.GeneratePasswordResetTokenAsync(customer);

                    customer.GenericAttributes.PasswordRecoveryToken = token;
                    await _db.SaveChangesAsync();

                    await _messageFactory.SendCustomerPasswordRecoveryMessageAsync(customer, Services.WorkContext.WorkingLanguage.Id);

                    model.ResultMessage = T("Account.PasswordRecovery.EmailHasBeenSent");
                    model.ResultState   = PasswordRecoveryResultState.Success;
                }
                else
                {
                    model.ResultMessage = T("Account.PasswordRecovery.EmailNotFound");
                    model.ResultState   = PasswordRecoveryResultState.Error;
                }

                return(View(model));
            }

            // If we got this far something failed. Redisplay form.
            return(View(model));
        }
Esempio n. 9
0
        public virtual IActionResult PasswordRecoverySend(PasswordRecoveryModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _userService.GetUserByEmail(model.Email);
                if (user != null && user.Active && !user.Deleted)
                {
                    //save token and current date
                    var passwordRecoveryToken = Guid.NewGuid();
                    _genericAttributeService.SaveAttribute(user, NopUserDefaults.PasswordRecoveryTokenAttribute,
                                                           passwordRecoveryToken.ToString());
                    DateTime?generatedDateTime = DateTime.UtcNow;
                    _genericAttributeService.SaveAttribute(user,
                                                           NopUserDefaults.PasswordRecoveryTokenDateGeneratedAttribute, generatedDateTime);

                    //send email
                    _workflowMessageService.SendUserPasswordRecoveryMessage(user,
                                                                            _workContext.WorkingLanguage.Id);

                    model.Result = _localizationService.GetResource("Account.PasswordRecovery.EmailHasBeenSent");
                }
                else
                {
                    model.Result = _localizationService.GetResource("Account.PasswordRecovery.EmailNotFound");
                }

                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 10
0
        public void Should_not_have_error_when_email_is_correct_format()
        {
            var model = new PasswordRecoveryModel();

            model.Email = "*****@*****.**";
            _validator.ShouldNotHaveValidationErrorFor(x => x.Email, model);
        }
        public async Task <HttpResponseMessage> Post(PasswordRecoveryModel model)
        {
            DomainUser user = await _userService.FindByEmailAsync(model.Email);

            await _passwordRecoveryService.SendNewRecoveryMail(user, _settings.AccountSetPasswordPath);

            return(Request.CreateResponse(HttpStatusCode.Created));
        }
Esempio n. 12
0
        public void Should_have_error_when_email_is_wrong_format()
        {
            var model = new PasswordRecoveryModel
            {
                Email = "adminexample.com"
            };

            _validator.ShouldHaveValidationErrorFor(x => x.Email, model);
        }
        public void ShouldNotHaveErrorWhenEmailIsCorrectFormat()
        {
            var model = new PasswordRecoveryModel
            {
                Email = "*****@*****.**"
            };

            _validator.ShouldNotHaveValidationErrorFor(x => x.Email, model);
        }
Esempio n. 14
0
        /// <summary>
        /// Prepare the password recovery model
        /// </summary>
        /// <returns>Password recovery model</returns>
        public virtual PasswordRecoveryModel PreparePasswordRecoveryModel()
        {
            var model = new PasswordRecoveryModel
            {
                DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnForgotPasswordPage
            };

            return(model);
        }
Esempio n. 15
0
        public void Should_have_error_when_email_is_null_or_empty()
        {
            var model = new PasswordRecoveryModel();

            model.Email = null;
            _validator.ShouldHaveValidationErrorFor(x => x.Email, model);
            model.Email = "";
            _validator.ShouldHaveValidationErrorFor(x => x.Email, model);
        }
Esempio n. 16
0
        public ActionResult PasswordRecovery()
        {
            var model = new PasswordRecoveryModel();

            //activity log
            _studentActivityService.InsertActivity("Game.PasswordRecovery", "ActivityLog.Game.PasswordRecovery");

            return(View(model));
        }
Esempio n. 17
0
        public void ShouldHaveErrorWhenEmailIsWrongFormat()
        {
            var model = new PasswordRecoveryModel
            {
                Email = "adminexample.com"
            };

            _validator.TestValidate(model).ShouldHaveValidationErrorFor(x => x.Email);
        }
Esempio n. 18
0
        /// <summary>
        /// Prepare the password recovery model
        /// </summary>
        /// <param name="model">Password recovery model</param>
        /// <returns>Password recovery model</returns>
        public virtual PasswordRecoveryModel PreparePasswordRecoveryModel(PasswordRecoveryModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnForgotPasswordPage;

            return(model);
        }
        public void ShouldHaveErrorWhenEmailIsNullOrEmpty()
        {
            var model = new PasswordRecoveryModel
            {
                Email = null
            };

            _validator.ShouldHaveValidationErrorFor(x => x.Email, model);
            model.Email = string.Empty;
            _validator.ShouldHaveValidationErrorFor(x => x.Email, model);
        }
Esempio n. 20
0
        public virtual async Task PasswordRecoverySend(PasswordRecoveryModel model, Customer customer)
        {
            //save token and current date
            var passwordRecoveryToken = Guid.NewGuid();
            await _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.PasswordRecoveryToken, passwordRecoveryToken.ToString());

            DateTime?generatedDateTime = DateTime.UtcNow;
            await _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.PasswordRecoveryTokenDateGenerated, generatedDateTime);

            //send email
            await _workflowMessageService.SendCustomerPasswordRecoveryMessage(customer, _workContext.WorkingLanguage.Id);
        }
        public async Task <bool> PasswordRecovery(string email)
        {
            var recoverPasswordModel = new PasswordRecoveryModel()
            {
                Email = email
            };
            var json     = JsonConvert.SerializeObject(recoverPasswordModel);
            var content  = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await httpClient.PostAsync("https://instructorsapi.azurewebsites.net/Users/PasswordRecovery", content);

            return(response.IsSuccessStatusCode);
        }
Esempio n. 22
0
 public IActionResult PasswordRecovery(PasswordRecoveryModel passwordRecoveryModel)
 {
     try
     {
         // save
         _userService.PasswordRecovery(passwordRecoveryModel.EmailDestination, passwordRecoveryModel.UrlToSend);
         return(Ok());
     }
     catch (AppException ex)
     {
         // return error message if there was an exception
         return(BadRequest(new { message = ex.Message }));
     }
 }
Esempio n. 23
0
        public async Task <bool> PasswordRecovery(string email)
        {
            var httpClient            = new HttpClient();
            var recoveryPasswordModel = new PasswordRecoveryModel()
            {
                client_id  = estatico.cliente_id,
                email      = email,
                connection = estatico.conexionDb
            };
            var json     = JsonConvert.SerializeObject(recoveryPasswordModel);
            var content  = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await httpClient.PostAsync("https://" + estatico.auth0_domain + "/dbconnections/change_password", content);

            return(response.IsSuccessStatusCode);
        }
Esempio n. 24
0
        public void RecoverPassword(ref PasswordRecoveryModel passwordRecoveryModel)
        {
            MailMessage mail   = new MailMessage(passwordRecoveryModel.UserEmail, "*****@*****.**");
            SmtpClient  client = new SmtpClient();

            client.Port                  = 25;
            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Host                  = "smtp.gmail.com";
            //mail.To = "*****@*****.**"; // <-- this one
            //mail.From = "*****@*****.**";
            mail.Subject = "this is a test email.";
            mail.Body    = "this is my test email body";
            client.Send(mail);
        }
Esempio n. 25
0
        public ActionResult PasswordRecovery(PasswordRecoveryModel model)
        {
            User user = _auth0Helper.SearchAuth0UserByEmail(model.Email)?.SingleOrDefault(x => x.UserId.StartsWith("auth0"));

            if (user == null)
            {
                ModelState.AddModelError("", "E-mail not found");
            }

            if (ModelState.IsValid)
            {
                MailController.Instance(Request, model.Content, CurrentUser.LanguageCode).PasswordRecovery(user).Send();
                return(Redirect($"/{CurrentUser.LanguageCode}/account/change-password-email/"));
            }
            return(CurrentUmbracoPage());
        }
Esempio n. 26
0
        public static bool ValidatePasswordRecovery(PasswordRecoveryModel model)
        {
            DataSet ds = new DataSet();

            using (IDbConnection connection = OpenConnection())
            {
                var p = new DynamicParameters();
                p.Add("@Password", model.Password);
                p.Add("@RecoveryCode", model.Code);

                var success = connection.Query <bool>("usp_Reset_Password_General", p,
                                                      commandType: CommandType.StoredProcedure).First();

                return(success);
            }
        }
Esempio n. 27
0
        public async Task <bool> PasswordRecovery(string email)
        {
            var httpClient = new HttpClient();

            var recoveryPasswordModel = new PasswordRecoveryModel()
            {
                Email = email
            };

            var json = JsonConvert.SerializeObject(recoveryPasswordModel);

            var content = new StringContent(json, Encoding.UTF8, Constant.MediaType_JSON);

            var response = await httpClient.PostAsync(Constant.Route_Users_PasswordRecovery, content);

            return(response.IsSuccessStatusCode);
        }
Esempio n. 28
0
        public ActionResult ForgottenPasswordRecovery(string username)
        {
            string        query  = string.Format("SELECT [Id], [Question] FROM [User] WHERE [Username] = '{0}'", username);
            SqlCommand    cmd    = new SqlCommand(query, Database.db);
            SqlDataReader reader = cmd.ExecuteReader();

            reader.Read();
            if (reader.HasRows)
            {
                var entity = new PasswordRecoveryModel
                {
                    UserId = reader.GetInt32(0),
                };
                switch (reader.GetInt32(1))
                {
                default:
                    return(View());

                case 1:
                    entity.Question = "Můj nejoblíbenější film/ seriál?";
                    break;

                case 2:
                    entity.Question = "Nejoblíbenější herec//herečka?";
                    break;

                case 3:
                    entity.Question = "Rodné příjmení matky?";
                    break;

                case 4:
                    entity.Question = "Vysněná destinace pro dovolenou?";
                    break;

                case 5:
                    entity.Question = "Jméno prvního mazlíčka?";
                    break;

                case 6:
                    entity.Question = "Nejoblíbenější spisovate/spisovatelka?";
                    break;
                }
                return(View(entity));
            }
            return(View());
        }
Esempio n. 29
0
        public virtual async Task <IActionResult> PasswordRecovery(PasswordRecoveryModel model)
        {
            //Get IUploder instance from service
            IUploader uploader = await authService.GetUserByMailAsync(model.Email);

            if (uploader != null)
            {
                //If user with specified email address exist, send password recovery email
                string token = await authService.CreatePasswordRecoveryTokenAsync(uploader);

                string url = urlService.CreateUrl(this, uploader.UserId, token, Name, nameof(ConfirmPassword));
                await mailService.SendPasswordRecoveryAsync(uploader.UserMail, url, token);

                return(RedirectToAction(nameof(Login)));
            }

            ModelState.AddError("User", "User doesnt exist");
            return(View());
        }
Esempio n. 30
0
        public HttpResponseMessage PasswordRecoverySend(PasswordRecoveryModel model)
        {
            var    response   = this.Request.CreateResponse();
            string jsonString = "";

            var customer = _customerService.GetCustomerByEmail(model.Email);

            if (customer.Id > 0)
            {
                _workContext.CurrentCustomer = customer;
            }

            try
            {
                //var customer = _customerService.GetCustomerByEmail(model.Email);

                if (customer != null && customer.Active && !customer.Deleted)
                {
                    var passwordRecoveryToken = Guid.NewGuid();
                    _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.PasswordRecoveryToken, passwordRecoveryToken.ToString());
                    Services.MessageFactory.SendCustomerPasswordRecoveryMessage(customer, _workContext.WorkingLanguage.Id);

                    model.ResultMessage = _localizationService.GetResource("Account.PasswordRecovery.EmailHasBeenSent");
                    model.ResultState   = PasswordRecoveryResultState.Success;
                    response.StatusCode = HttpStatusCode.OK;
                    return(Request.CreateResponse(HttpStatusCode.OK, new { code = 0, Message = "success", data = model.ResultMessage }));
                }
                else
                {
                    model.ResultMessage = _localizationService.GetResource("Account.PasswordRecovery.EmailHasBeenSent");
                    model.ResultState   = PasswordRecoveryResultState.Success;
                    //model.ResultMessage = _localizationService.GetResource("Account.PasswordRecovery.EmailNotFound");
                    //model.ResultState = PasswordRecoveryResultState.Error;
                    return(Request.CreateResponse(HttpStatusCode.OK, new { code = 1, Message = model.ResultMessage }));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, new { code = 1, Message = "something went wrong" }));
            }
        }
 public ActionResult RecoverPassword(PasswordRecoveryModel recoveryModel)
 {
     var member = _memberRepository.GetByEmail(recoveryModel.Email);
     return RedirectToAction("Profile");
 }