public ActionResult SaveServiceRole(int userid, string RetypePassword) { if (userid <= 0) { throw new HttpRequestValidationException(); } IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>(); IRBACRoleProvider _RoleProvider = IoC.Resolve <IRBACRoleProvider>(); Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; user model = _MemberShipProvider.GetUser(userid, false); if (HttpContext.User.Identity.Name == model.username) { Messages.AddErrorFlashMessage(Resources.Message.User_UMesCantEdit); return(RedirectToAction("ServiceRoleIndex")); } string oldpassHash = model.password; string username = model.username; string email = model.email; try { TryUpdateModel(model); model.username = username; if (model.password != RetypePassword) { ViewData["RetypePassword"] = model.password; Messages.AddErrorFlashMessage(Resources.Message.User_MesConfirmPass); return(View("ServiceRoleEdit", model)); } if (RetypePassword != oldpassHash) { model.password = GeneratorPassword.EncodePassword(RetypePassword, model.PasswordFormat, model.PasswordSalt);//FormsAuthentication.HashPasswordForStoringInConfigFile(RetypePassword, "MD5"); } model.FailedPasswordAttemptCount = 0; _MemberShipProvider.UpdateUser(model); _RoleProvider.UpdateUsersToRoles(model.username, new string[] { "ServiceRole" }); Messages.AddFlashMessage(Resources.Message.User_UMesSuccess); log.Info("ServiceRoleUpdate by: " + HttpContext.User.Identity.Name + "Info-- tai khoan " + model.username); return(RedirectToAction("ServiceRoleIndex")); } catch (Exception ex) { ViewData["RetypePassword"] = model.password; log.Error("ServiceRoleUpdate-" + ex.Message); Messages.AddFlashException(ex); return(View("ServiceRoleEdit", model)); } }
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)); } }
public IHttpActionResult UserdataInfo(UserdataInfo data) { IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>(); IRBACRoleProvider _RoleProvider = IoC.Resolve <IRBACRoleProvider>(); if (string.IsNullOrWhiteSpace(data.username) || string.IsNullOrWhiteSpace(data.password)) { return(Ok <string>("ERROR:1"));//Cần nhập đủ thông tin } try { //Tao tai khoan string status = ""; user u = _MemberShipProvider.GetUser(data.username, false); if (u != null) { u.email = data.email; if (data.ChangePass) { u.password = GeneratorPassword.EncodePassword(data.password, u.PasswordFormat, u.PasswordSalt); } u.FailedPasswordAttemptCount = 0; //update lai tai khoan _MemberShipProvider.UpdateUser(u); return(Ok <string>("OK")); } Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; _MemberShipProvider.CreateUser(data.username, data.password, data.email, null, null, data.IsApproved, null, currentCom.id.ToString(), out status); if (status != "Success") { return(Ok <string>("ERROR:2"));//Status != Success } return(Ok <string>("OK")); } catch (Exception ex) { return(Ok <string>("ERROR:3")); } }
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)); } }
public ActionResult Reset(string username) { ResetModel mm = new ResetModel(); try { IuserService _userService = IoC.Resolve <IuserService>(); Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; user model = _userService.Query.Where(u => u.GroupName.Equals(_currentCompany.id.ToString()) && u.username == username).FirstOrDefault(); if (model != null) { string randompass = IdentityManagement.WebProviders.RBACMembershipProvider.CreateRandomPassword(8); IService.IRegisterEmailService emailSrv = FX.Core.IoC.Resolve <IService.IRegisterEmailService>(); Dictionary <string, string> subjectParams = new Dictionary <string, string>(1); subjectParams.Add("$subject", ""); Dictionary <string, string> bodyParams = new Dictionary <string, string>(3); bodyParams.Add("$password", randompass); bodyParams.Add("$site", FX.Utils.UrlUtil.GetSiteUrl()); emailSrv.ProcessEmail("*****@*****.**", model.email, "ResetPassword", subjectParams, bodyParams); model.password = GeneratorPassword.EncodePassword(randompass, model.PasswordFormat, model.PasswordSalt);//FormsAuthentication.HashPasswordForStoringInConfigFile(randompass, "MD5"); model.LastPasswordChangedDate = DateTime.Now; _userService.Save(model); _userService.CommitChanges(); mm.lblErrorMessage = "Kiểm tra email để lấy mật khẩu của bạn."; return(View("ResetPassword", mm)); } mm.lblErrorMessage = "Tài khoản không tồn tại trên hệ thống"; return(View("ResetPassword", mm)); } catch (Exception ex) { log.Error(ex); ResetModel model = new ResetModel(); model.lblErrorMessage = "Tài khoản không tồn tại trên hệ thống"; return(View("ResetPassword", mm)); } }
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)); } }