Example #1
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>();
            user _oUser = _MemberShipProvider.GetUser(model.username, true);

            try
            {
                if (_oUser.password == GeneratorPassword.EncodePassword(model.OldPassword, _oUser.PasswordFormat, _oUser.PasswordSalt))
                {
                    if (model.NewPassword != model.OldPassword && model.NewPassword == model.ConfirmPassword)
                    {
                        _oUser.PasswordSalt = GeneratorPassword.GenerateSalt();
                        _oUser.password     = GeneratorPassword.EncodePassword(model.NewPassword, _oUser.PasswordFormat, _oUser.PasswordSalt);
                        _MemberShipProvider.UpdateUser(_oUser);
                        log.Info("Change Password By: " + HttpContext.User.Identity.Name + " Info-- UserName: "******"  ID: " + _oUser.userid + "------");
                        Messages.AddFlashMessage(Resources.Message.User_MesChangePasswordSuccess);
                    }
                    else if (model.NewPassword == model.OldPassword)
                    {
                        Messages.AddErrorMessage(Resources.Message.User_MesNewPassLikeOldPass);
                        return(View(model));
                    }
                    else if (model.NewPassword != model.ConfirmPassword)
                    {
                        Messages.AddErrorMessage(Resources.Message.User_MesErrConfirmPass);
                        return(View(model));
                    }
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    Messages.AddErrorMessage(Resources.Message.User_MesWrongPass);
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                log.Error("Error ChangePassword:"******"Có lỗi xảy ra, vui lòng thực hiện lại!");
                return(View(model));
            }
        }
Example #2
0
        public ActionResult UpdatePasswordCustomer(string username, string newPassword, string confirmPassword)
        {
            IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>();
            user userCustomer = _MemberShipProvider.GetUser(username, true);

            if (userCustomer == null)
            {
                Messages.AddErrorFlashMessage("Tài khoản không có trên hệ thống.");
                return(RedirectToAction("Index", "Customer"));
            }
            try
            {
                if (newPassword == confirmPassword)
                {
                    userCustomer.PasswordSalt = GeneratorPassword.GenerateSalt();
                    userCustomer.password     = GeneratorPassword.EncodePassword(newPassword, userCustomer.PasswordFormat, userCustomer.PasswordSalt);
                    _MemberShipProvider.UpdateUser(userCustomer);
                    Messages.AddFlashMessage(Resources.Message.User_MesChangePasswordSuccess);
                }
                else
                {
                    Messages.AddErrorMessage(Resources.Message.User_MesErrConfirmPass);
                    ChangePasswordModel model = new ChangePasswordModel();
                    model.username = username;
                    return(View(model));
                }
                return(RedirectToAction("Index", "Customer"));
            }
            catch (Exception ex)
            {
                log.Error("Error", ex);
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!");
                ChangePasswordModel model = new ChangePasswordModel();
                model.username = username;
                return(View("ChangePasswordCustomer", model));
            }
        }
Example #3
0
        public ActionResult Update(int id, string RetypePassword, string[] UserRoles, string fullname)
        {
            if (id <= 0)
            {
                throw new HttpRequestValidationException();
            }
            IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>();
            IRBACRoleProvider       _RoleProvider       = IoC.Resolve <IRBACRoleProvider>();
            user Ouser = _MemberShipProvider.GetUser(id, false);

            if (HttpContext.User.Identity.Name == Ouser.username)
            {
                Messages.AddErrorFlashMessage(Resources.Message.User_UMesCantEdit);
                return(RedirectToAction("index"));
            }
            //lay doi tuong tai khoan cu
            string       OldPassword = Ouser.password;
            string       Oldusername = Ouser.username;
            AccountModel model       = new AccountModel();

            try
            {
                TryUpdateModel <user>(Ouser);
                if (Ouser.password != RetypePassword)
                {
                    Messages.AddErrorMessage(Resources.Message.User_MesConfirmPass);
                    List <String> lst = new List <string>(_RoleProvider.GetAllRoles());
                    if (lst.IndexOf("ServiceRole") >= 0)
                    {
                        lst.RemoveAt(lst.IndexOf("ServiceRole"));
                    }
                    if (lst.IndexOf("Root") >= 0)
                    {
                        lst.RemoveAt(lst.IndexOf("Root"));
                    }
                    model.RetypePassword = Ouser.password = OldPassword;
                    model.AllRoles       = lst.ToArray();
                    model.UserRoles      = _RoleProvider.GetRolesForUser(Ouser.userid);
                    model.UserTmp        = Ouser;
                    return(View("Edit", model));
                }
                if (Ouser.password != OldPassword)
                {
                    Ouser.PasswordSalt = GeneratorPassword.GenerateSalt();
                    Ouser.password     = GeneratorPassword.EncodePassword(Ouser.password, Ouser.PasswordFormat, Ouser.PasswordSalt);//FormsAuthentication.HashPasswordForStoringInConfigFile(RetypePassword, "MD5");
                }
                Ouser.FailedPasswordAttemptCount = 0;
                //update lai tai khoan
                _MemberShipProvider.UpdateUser(Ouser);
                model.UserRoles = UserRoles ?? new string[] { };
                _RoleProvider.UpdateUsersToRoles(Ouser.userid, model.UserRoles);
                Messages.AddFlashMessage(Resources.Message.User_UMesSuccess);
                log.Info("Update Account:" + HttpContext.User.Identity.Name + ", Date: " + DateTime.Now);

                Company       currentComp = ((EInvoiceContext)FXContext.Current).CurrentCompany;
                IStaffService _staSrv     = IoC.Resolve <IStaffService>();
                Staff         sta         = _staSrv.SearchByAccountName(Ouser.username, currentComp.id);
                sta.FullName = fullname;
                _staSrv.UpdateStaff(sta);

                return(RedirectToAction("index"));
            }
            catch (Exception ex)
            {
                log.Error("Error Update:", ex);
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!");
                List <String> lst = new List <string>(_RoleProvider.GetAllRoles());
                if (lst.IndexOf("ServiceRole") >= 0)
                {
                    lst.RemoveAt(lst.IndexOf("ServiceRole"));
                }
                if (lst.IndexOf("Root") >= 0)
                {
                    lst.RemoveAt(lst.IndexOf("Root"));
                }
                model.RetypePassword = Ouser.password = OldPassword;
                model.AllRoles       = lst.ToArray();
                model.UserRoles      = _RoleProvider.GetRolesForUser(Ouser.userid);
                model.UserTmp        = Ouser;
                return(View("Edit", model));
            }
        }