Пример #1
0
        private int ValidateUserChangePassword(UserChangePasswordViewModel objEntity)
        {
            int result = 0;
            AccountRepository objAccountRepository = new AccountRepository();
            var objUserRepository     = new UserRepository();
            var objLoginUserViewModel = objAccountRepository.GetUserDetailsforLogin(UserFlags.UserSignIn.GetHashCode(), new UserLoginViewModel()
            {
                UserEmail = objEntity.UserEmail
            });

            if (objLoginUserViewModel != null)
            {
                if (PasswordHelpers.Validate(objLoginUserViewModel.Password, objLoginUserViewModel.PasswordSalt, objEntity.NewPassword))
                {
                    result = ResultFlags.OldPasswordMismatch.GetHashCode();
                }
                else
                {
                    PasswordHelpers.HashedPassword objHashedPassword = PasswordHelpers.Generate(objEntity.NewPassword);
                    var objNewUserViewModel = new UserViewModel()
                    {
                        UserId       = SessionWrapper.UserAccount.UserId,
                        UserEmail    = SessionWrapper.UserAccount.UserEmail,
                        PasswordSalt = objHashedPassword.Salt,
                        Password     = objHashedPassword.Password
                    };



                    objNewUserViewModel = objUserRepository.Update(UserFlags.UpdatePasswordByID.GetHashCode(), objNewUserViewModel);
                    result = objNewUserViewModel.Result;
                }
            }


            return(result);
        }
Пример #2
0
        public ActionResult Register(RegistrationViewModel objEntity)
        {
            RegistrationRepository objRegistrationRepository = new RegistrationRepository();
            string fileName = string.Empty;

            if (ModelState.IsValid)
            {
                #region FileUpload

                if (objEntity.UploadPhoto != null)
                {
                    fileName            = Guid.NewGuid().ToString() + Path.GetExtension(objEntity.UploadPhoto.FileName);
                    objEntity.PhotoName = fileName;
                }
                else
                {
                    objEntity.PhotoName = string.Empty;
                }



                #endregion

                objEntity.RoleId = (Int16)RoleUserDefinedEnum.User.GetHashCode();


                PasswordHelpers.HashedPassword objHashedPassword = PasswordHelpers.Generate(objEntity.Password);

                objEntity.Password = objHashedPassword.Password;

                objEntity.PasswordSalt = objHashedPassword.Salt;


                objEntity.Status = StatusEnum.Active.GetHashCode();


                objRegistrationRepository.Insert(objEntity);

                if (objEntity.Result == ResultFlags.Success.GetHashCode())
                {
                    this.Flash("success", "Registration created successfully ");

                    #region FileUpload

                    //file name
                    if (objEntity.PhotoName != null)
                    {
                        string path = Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_USER_PHOTO_PATH), fileName);
                        // WebImage.Save()
                        objEntity.UploadPhoto.SaveAs(path);
                    }



                    #endregion
                    //return RedirectToAction("Index");
                    return(RedirectToAction("Login", "User"));
                }
                else if (objEntity.Result == ResultFlags.Failure.GetHashCode())
                {
                    this.Flash("Error", "Failed to create account");

                    return(RedirectToAction("Index"));
                }
                else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode())
                {
                    this.Flash("Warning", "It already exist");
                }
            }



            return(View(objEntity));
        }