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 LogOn(LogOnModel _model, string captch) { if (string.IsNullOrWhiteSpace(captch)) { _model.lblErrorMessage = "Nhập đúng mã xác thực."; _model.Password = ""; return(View(_model)); } bool cv = CaptchaController.IsValidCaptchaValue(captch); if (!cv) { _model.lblErrorMessage = "Nhập đúng mã xác thực."; _model.Password = ""; return(View(_model)); } log.Info("Login: "******"LogOn:" + HttpContext.User.Identity.Name + ", Date:" + DateTime.Now); if (!string.IsNullOrWhiteSpace(_model.ReturnUrl) && Url.IsLocalUrl(_model.ReturnUrl)) { return(Redirect(_model.ReturnUrl)); } return(Redirect("/")); } else { IuserService userSrv = IoC.Resolve <IuserService>(); var currComp = ((EInvoiceContext)FXContext.Current).CurrentCompany; user TempUser = userSrv.Query.Where(u => u.username == _model.UserName && u.GroupName.Equals(currComp.id.ToString())).FirstOrDefault(); if (TempUser != null) { if (TempUser.IsLockedOut) { _model.lblErrorMessage = "Tài khoản đã bị khóa."; } else { if (!_model.IsThread) { if (TempUser.FailedPasswordAttemptCount > 0) { TempUser.FailedPasswordAttemptCount = 0; userSrv.Save(TempUser); userSrv.CommitChanges(); } _model.lblErrorMessage = Resources.Message.User_MesWrongAccOrPass; _model.Password = ""; _model.IsThread = true; return(View(_model)); } if (TempUser.FailedPasswordAttemptCount == 4) { TempUser.IsLockedOut = true; } TempUser.FailedPasswordAttemptCount++; _model.lblErrorMessage = Resources.Message.User_MesWrongAccOrPass; userSrv.Save(TempUser); userSrv.CommitChanges(); } _model.Password = ""; return(View(_model)); } _model.lblErrorMessage = Resources.Message.User_MesWrongAccOrPass; _model.Password = ""; return(View(_model)); } } else { _model.Password = ""; return(View("LogOn", _model)); } } catch (Exception ex) { log.Error("Error", ex); _model.lblErrorMessage = Resources.Message.User_MesWrongAccOrPass; _model.Password = ""; return(View("LogOn", _model)); } }