public ActionResult Active(ActiveModels model, string captch) { if (string.IsNullOrWhiteSpace(captch)) { model.ErrMessages = "Nhập đúng mã xác thực."; return(View(model)); } bool cv = CaptchaController.IsValidCaptchaValue(captch); if (!cv) { model.ErrMessages = "Nhập đúng mã xác thực."; return(View(model)); } try { if (string.IsNullOrWhiteSpace(model.username)) { model.ErrMessages = "Không tồn tại tài khoản trong hệ thống."; return(View(model)); } if (model.username != System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(model.code))) { model.ErrMessages = "Không tồn tại tài khoản trong hệ thống."; return(View(model)); } Company currentComp = ((EInvoiceContext)FXContext.Current).CurrentCompany; IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>(); if (_MemberShipProvider.GetUser(model.username, true) != null) { model.ErrMessages = "Tài khoản đã được kích hoạt trước đó, liên hệ để được hỗ trợ."; return(View("Active", model)); } if (!model.password.Equals(model.comfirmpassword)) { model.ErrMessages = "Nhập đúng mật khẩu xác thực."; return(View("Active", model)); } string status = ""; user tmp = _MemberShipProvider.CreateUser(model.username, model.password, currentComp.Email, null, null, true, null, currentComp.id.ToString(), out status); if (status != "Success" || tmp == null) { model.ErrMessages = "Chưa kích hoạt được tài khoản, liên hệ để được hỗ trợ."; return(View("Active", model)); } IRBACRoleProvider _RoleProvider = IoC.Resolve <IRBACRoleProvider>(); if (_RoleProvider.RoleExists("Admin")) { _RoleProvider.UpdateUsersToRoles(tmp.userid, new string[] { "Admin" }); } return(Redirect("/Account/Logon")); } catch (Exception ex) { log.Error(ex); model.ErrMessages = "Chưa kích hoạt được tài khoản, liên hệ để được hỗ trợ."; return(View()); } }
public ActionResult CreateNewServiceRole(user _model, string RetypePassword) { if (string.IsNullOrWhiteSpace(_model.username)) { Messages.AddErrorMessage("Cần nhập tên tài khoản người dùng."); ViewData["RetypePassword"] = _model.password; return(View("NewServiceRole", _model)); } Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IRBACRoleProvider _RoleProvider = IoC.Resolve <IRBACRoleProvider>(); IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>(); try { string status = ""; if (!_model.password.Equals(RetypePassword)) { Messages.AddErrorMessage(Resources.Message.User_MesConfirmPass); ViewData["RetypePassword"] = _model.password; return(View("NewServiceRole", _model)); } else { _model.GroupName = currentCom.id.ToString(); _MemberShipProvider.CreateUser(_model.username, _model.password, _model.email, _model.PasswordQuestion, _model.PasswordAnswer, _model.IsApproved, _model.userid, _model.GroupName, out status); if (status != "Success") { Messages.AddErrorMessage("Dữ liệu không hợp lệ hoặc tài khoản đã có trên hệ thống."); ViewData["RetypePassword"] = _model.password; return(View("NewServiceRole", _model)); } string[] roleservice = new string[] { "ServiceRole" }; _RoleProvider.UpdateUsersToRoles(_model.username, roleservice); Messages.AddFlashMessage(Resources.Message.User_IMesSuccess); log.Info("CreateNewServiceRole by:" + HttpContext.User.Identity.Name + " Info-- tai khoan " + _model.username); return(RedirectToAction("ServiceRoleIndex")); } } catch (Exception ex) { Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); log.Error("CreateNewServiceRole-" + ex.Message); ViewData["RetypePassword"] = _model.password; return(View("NewServiceRole", _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 Create(user _model, string RetypePassword, string[] AssignRoles) { IRBACRoleProvider _RoleProvider = IoC.Resolve <IRBACRoleProvider>(); IuserService _userService = IoC.Resolve <IuserService>(); IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>(); AccountModels model = new AccountModels(); if (string.IsNullOrWhiteSpace(_model.username)) { Messages.AddErrorMessage("Cần nhập những thông tin bắt buộc."); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); model.RetypePassword = _model.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = AssignRoles ?? new string[] { }; model.tmpUser = _model; return(View("New", model)); } try { string status = ""; AssignRoles = AssignRoles ?? new string[] { }; if (!_model.password.Equals(RetypePassword)) { Messages.AddErrorMessage("Nhập đúng mật khẩu của bạn."); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); model.RetypePassword = _model.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = new string[] { }; model.tmpUser = _model; return(View("New", model)); } else { _MemberShipProvider.CreateUser(_model.username, _model.password, _model.email, _model.PasswordQuestion, _model.PasswordAnswer, _model.IsApproved, null, out status); if (status != "Success") { List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); model.RetypePassword = _model.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = new string[] { }; model.tmpUser = _model; Messages.AddErrorMessage("Tài khoản đã có trên hệ thống hoặc dữ liệu không hợp lệ."); return(View("New", model)); } if (AssignRoles == null) { Messages.AddFlashMessage("Bạn tạo tài khoản thành công nhưng chưa phân quyền!"); return(RedirectToAction("index")); } _RoleProvider.UpdateUsersToRoles(_model.username, AssignRoles); Messages.AddFlashMessage("Tạo tài khoản thành công."); logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "User - Create : " + string.Format("Create: {0} by {1}", _model.username, HttpContext.User.Identity.Name), "Create User Success ", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); return(RedirectToAction("index")); } } catch (Exception ex) { logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "User - Create ", "Create User Error: " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); Messages.AddErrorMessage("Chưa tạo được người dùng."); List <String> lst = new List <string>(_RoleProvider.GetAllRoles()); model.RetypePassword = _model.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = new string[] { }; model.tmpUser = _model; return(View("New", model)); } }
public ActionResult New(user temp, string RetypePassword, string[] UserRoles, string fullname) { IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>(); IRBACRoleProvider _RoleProvider = IoC.Resolve <IRBACRoleProvider>(); if (string.IsNullOrWhiteSpace(temp.username)) { AccountModel model = new AccountModel(); Messages.AddErrorMessage("Cần nhập những thông tin bắt buộc."); 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 = temp.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = UserRoles ?? new string[] { }; model.UserTmp = temp; return(View("Create", model)); } try { if (temp.password != RetypePassword) { AccountModel model = new AccountModel(); 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 = temp.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = UserRoles ?? new string[] { }; model.UserTmp = temp; return(View("Create", model)); } //Tao tai khoan string status = ""; Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; user u = _MemberShipProvider.CreateUser(temp.username, temp.password, temp.email, null, null, temp.IsApproved, null, currentCom.id.ToString(), out status); if (status != "Success") { AccountModel model = new AccountModel(); Messages.AddErrorMessage("Tài khoản đã có trên hệ thống hoặc dữ liệu không hợp lệ."); 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 = temp.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = UserRoles ?? new string[] { }; model.UserTmp = temp; return(View("Create", model)); } _RoleProvider.UpdateUsersToRoles(u.userid, UserRoles); Messages.AddFlashMessage(Resources.Message.User_UMesSuccess); log.Info("Create Account:" + HttpContext.User.Identity.Name + ", Date: " + DateTime.Now); Company currentComp = ((EInvoiceContext)FXContext.Current).CurrentCompany; IStaffService _staSrv = IoC.Resolve <IStaffService>(); Staff newStaff = new Staff { FullName = fullname, AccountName = u.username, ComID = currentComp.id, Email = u.email }; _staSrv.CreateNew(newStaff); _staSrv.CommitChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { log.Error("Create Error:", ex); AccountModel model = new AccountModel(); Messages.AddErrorMessage("Tài khoản đã có trên hệ thống hoặc dữ liệu không hợp lệ."); 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 = temp.password = ""; model.AllRoles = lst.ToArray(); model.UserRoles = new string[] { }; model.UserTmp = temp; return(View("Create", model)); } }