Exemplo n.º 1
0
        public ActionResult Delete(int id)
        {
            IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>();
            IRBACRoleProvider       _RoleProvider       = IoC.Resolve <IRBACRoleProvider>();

            try
            {
                user     model = _MemberShipProvider.GetUser(id, false);
                string[] roles = _RoleProvider.GetRolesForUser(model.userid);
                if (model.username.ToUpper() == HttpContext.User.Identity.Name.ToUpper() || roles.Contains("ServiceRole"))
                {
                    Messages.AddErrorFlashMessage("Không được xóa tài khoản đang sử dụng.");
                    return(RedirectToAction("index"));
                }
                if (!_MemberShipProvider.DeleteUser(model.userid, true))
                {
                    Messages.AddErrorFlashMessage("Chưa xóa được tài khoản.");
                }
                else
                {
                    Messages.AddFlashMessage("Xóa tài khoản thành công!");
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                Messages.AddErrorFlashMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
            }
            return(RedirectToAction("index"));
        }
Exemplo n.º 2
0
        public ActionResult Delete(int id)
        {
            if (id <= 0)
            {
                throw new HttpRequestValidationException();
            }
            IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>();
            user model = _MemberShipProvider.GetUser(id, false);

            if (HttpContext.User.Identity.Name.ToUpper() == model.username.ToUpper())
            {
                Messages.AddErrorFlashMessage("Không thể xóa tài khoản đang sử dụng!");
                return(RedirectToAction("index"));
            }
            if (!_MemberShipProvider.DeleteUser(id, true))
            {
                Messages.AddErrorFlashMessage("Chưa xóa được tài khoản.");
            }
            else
            {
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "User - Delete : " + string.Format("Delete: {0} by {1}", model.username, HttpContext.User.Identity.Name), "Delete User Success ", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);


                Messages.AddFlashMessage("Xóa tài khoản thành công!");
            }
            return(RedirectToAction("index"));
        }
Exemplo n.º 3
0
        public ActionResult Update(int userid, string RetypePassword, string[] AssignRoles)
        {
            if (userid <= 0)
            {
                throw new HttpRequestValidationException();
            }
            IRBACRoleProvider       _RoleProvider       = IoC.Resolve <IRBACRoleProvider>();
            IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>();
            AccountModels           model = new AccountModels();
            user   _model      = _MemberShipProvider.GetUser(userid, false);
            string oldpassHash = _model.password;

            //giu lai username khong cho sua
            string username = _model.username;

            try
            {
                TryUpdateModel(_model);
                if (_model.username != username)
                {
                    throw new HttpRequestValidationException();
                }
                AssignRoles = AssignRoles ?? new string[] { };
                if (_model.password != RetypePassword)
                {
                    List <String> lst = new List <string>(_RoleProvider.GetAllRoles());
                    model.RetypePassword = _model.password = oldpassHash;
                    model.AllRoles       = lst.ToArray();
                    model.UserRoles      = _RoleProvider.GetRolesForUser(_model.username);
                    model.tmpUser        = _model;
                    Messages.AddErrorMessage("Nhập đúng mật khẩu của bạn.");
                    return(View("Edit", model));
                }
                if (RetypePassword != oldpassHash)
                {
                    _model.password = FormsAuthentication.HashPasswordForStoringInConfigFile(RetypePassword, "MD5");
                }
                _model.FailedPasswordAttemptCount = 0;
                _MemberShipProvider.UpdateUser(_model);
                _RoleProvider.UpdateUsersToRoles(_model.username, AssignRoles);
                Messages.AddFlashMessage("Cập nhật thông tin thành công.");

                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "User - Update : " + string.Format("Update: {0} by {1}", _model.username, HttpContext.User.Identity.Name), "Update User Success ", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);

                return(RedirectToAction("index"));
            }
            catch (Exception ex)
            {
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "User - Update ", "Update User Error " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);

                List <String> lst = new List <string>(_RoleProvider.GetAllRoles());
                model.RetypePassword = _model.password = oldpassHash;
                model.AllRoles       = lst.ToArray();
                model.UserRoles      = _RoleProvider.GetRolesForUser(_model.username);
                model.tmpUser        = _model;
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!");
                return(View("Edit", model));
            }
        }
Exemplo n.º 4
0
        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());
            }
        }
Exemplo n.º 5
0
        public ActionResult Edit(int id)
        {
            IRBACRoleProvider       _RoleProvider       = IoC.Resolve <IRBACRoleProvider>();
            IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>();
            user _model = _MemberShipProvider.GetUser(id, false);

            if (HttpContext.User.Identity.Name == _model.username)
            {
                Messages.AddErrorFlashMessage("Không được sửa tài khoản này.");
                return(RedirectToAction("index"));
            }
            AccountModels model = new AccountModels();
            user          muser = _MemberShipProvider.GetUser(id, false);
            List <String> lst   = new List <string>(_RoleProvider.GetAllRoles());

            model.RetypePassword = muser.password;
            model.AllRoles       = lst.ToArray();
            model.UserRoles      = _RoleProvider.GetRolesForUser(muser.username);
            model.tmpUser        = _model;
            return(View(model));
        }
Exemplo n.º 6
0
        public ActionResult ServiceRoleEdit(int id)
        {
            IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>();
            user model = _MemberShipProvider.GetUser(id, false);

            if (HttpContext.User.Identity.Name == model.username)
            {
                Messages.AddErrorFlashMessage(Resources.Message.User_UMesCantEdit);
                return(RedirectToAction("ServiceRoleIndex"));
            }
            ViewData["RetypePassword"] = model.password;
            return(View(model));
        }
Exemplo n.º 7
0
        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));
            }
        }
Exemplo n.º 8
0
        public ActionResult Edit(int id)
        {
            IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>();
            IRBACRoleProvider       _RoleProvider       = IoC.Resolve <IRBACRoleProvider>();
            Company currentComp = ((EInvoiceContext)FXContext.Current).CurrentCompany;


            user oUser = _MemberShipProvider.GetUser(id, false);

            if (HttpContext.User.Identity.Name == oUser.username)
            {
                Messages.AddErrorFlashMessage(Resources.Message.User_UMesCantEdit);
                return(RedirectToAction("index"));
            }

            IStaffService _staSrv = IoC.Resolve <IStaffService>();

            ViewData["fullname"] = _staSrv.SearchByAccountName(oUser.username, currentComp.id).FullName;

            AccountModel model = new AccountModel();

            model.UserTmp = oUser;
            try
            {
                model.UserRoles = _RoleProvider.GetRolesForUser(oUser.userid);
                if (model.UserRoles.Contains("ServiceRole"))
                {
                    Messages.AddErrorFlashMessage(Resources.Message.User_UMesCantEdit);
                    return(RedirectToAction("index"));
                }
                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;
                model.AllRoles       = lst.ToArray();
            }
            catch (Exception ex)
            {
                log.Error("edit: " + id, ex);
                throw ex;
            }
            return(View(model));
        }
Exemplo n.º 9
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (model.UserName != HttpContext.User.Identity.Name)
            {
                throw new HttpRequestValidationException();
            }
            IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>();
            user oUser = _MemberShipProvider.GetUser(model.UserName, true);

            try
            {
                if (oUser.password == FormsAuthentication.HashPasswordForStoringInConfigFile(model.oldPassword, "MD5"))
                {
                    //kiem tra va luu vao csdl
                    if (model.NewPassword != model.oldPassword && model.NewPassword == model.RetypePassword)
                    {
                        oUser.password = FormsAuthentication.HashPasswordForStoringInConfigFile(model.NewPassword, "MD5");
                        _MemberShipProvider.UpdateUser(oUser);
                        Messages.AddFlashMessage("Thay đổi mật khẩu thành công!");
                    }
                    //truong hop pass moi va pass cu bang nhau
                    else if (model.NewPassword == model.oldPassword)
                    {
                        Messages.AddErrorMessage("Mật khẩu mới và mật khẩu cũ giống nhau");
                        return(View(model));
                    }
                    //truong hop pass moi va pass go lai khong bang nhau
                    else if (model.NewPassword != model.RetypePassword)
                    {
                        Messages.AddErrorMessage("Mật khẩu mới và mật khẩu mới nhập lại không giống nhau");
                        return(View(model));
                    }
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    Messages.AddErrorMessage("Nhập sai mật khẩu cũ !");
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "User - ChangePassword", " User ChangePasword Error " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);

                Messages.AddErrorMessage("Có lỗi trong quá trình xử lý!");
                return(View(model));
            }
        }
Exemplo n.º 10
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));
            }
        }
Exemplo n.º 11
0
 public string ResetTem(string username, string password)
 {
     try
     {
         IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>();
         user model = _MemberShipProvider.GetUser(username, true);
         if (model.password == FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5"))
         {
             string name = (from e in model.Roles where e.name.Contains("Root") select e.name).FirstOrDefault();
             if (name == "Root")
             {
                 InvServiceFactory.Initial();
                 return("Reset thanh cong!");
             }
         }
         return("Reset khong thanh cong!");
     }
     catch (Exception ex)
     {
         return("Reset khong thanh cong!");
     }
 }
Exemplo n.º 12
0
        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"));
            }
        }
Exemplo n.º 13
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));
            }
        }
Exemplo n.º 14
0
        public ActionResult Create(Customer tmp, CustomerModel model, string[] DeliverMethod)
        {
            if (string.IsNullOrWhiteSpace(tmp.Name) || string.IsNullOrWhiteSpace(tmp.Code))
            {
                Messages.AddErrorMessage("Cần nhập các thông tin bắt buộc.");
                model.tmpCustomer = tmp;
                return(View(model));
            }
            IRBACMembershipProvider _MemberShipProvider = FX.Core.IoC.Resolve <IRBACMembershipProvider>();
            // kiểm tra tài khoản được sử dụng chưa
            user us = _MemberShipProvider.GetUser(tmp.AccountName, true);

            if (us != null)
            {
                Messages.AddErrorMessage("Tài khoản có trong hệ thống.");
                model.tmpCustomer = tmp;
                return(View(model));
            }
            Company          _currentCom  = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            ICustomerService cusSrv       = IoC.Resolve <ICustomerService>();
            string           ErrorMessage = "";
            var qr = cusSrv.Query.Where(p => p.ComID == _currentCom.id);

            if (!string.IsNullOrWhiteSpace(tmp.TaxCode))
            {
                qr = qr.Where(p => p.TaxCode.ToUpper() == tmp.TaxCode.ToUpper() || p.Code.ToUpper() == tmp.Code.Trim().ToUpper());
            }
            else
            {
                qr = qr.Where(p => p.Code.ToUpper() == tmp.Code.Trim().ToUpper());
            }
            if (qr.Count() > 0)
            {
                model.tmpCustomer = tmp;
                Messages.AddErrorMessage("Mã số thuế hoặc mã khách hàng đã tồn tại trên hệ thống!");
                return(View(model));
            }
            Certificate cer = model.UpdateCertificate(new Certificate());

            // user user = new user();
            //add delivermethod
            if (DeliverMethod == null)
            {
                tmp.DeliverMethod = -1;
            }
            else if (DeliverMethod.Length == 1)
            {
                if (DeliverMethod[0] == "0")
                {
                    tmp.DeliverMethod = 0;
                }
                else if (DeliverMethod[0] == "1")
                {
                    tmp.DeliverMethod = 1;
                }
            }
            else if (DeliverMethod.Length == 2)
            {
                tmp.DeliverMethod = 2;
            }

            tmp.TaxCode = Utils.formatTaxcode(tmp.TaxCode);
            //end delivermethod
            if (cusSrv.CreateCus(tmp, cer, _currentCom.id, out ErrorMessage))
            {
                log.Info("Create Customer by: " + HttpContext.User.Identity.Name + " Info-- TenKhachHang: " + tmp.Name + " TaiKhoanKhachHang: " + tmp.AccountName + " Email: " + tmp.Email);
                Messages.AddFlashMessage(Resources.Message.Cus_IMesSuccess);
                // send Mail--
                try
                {
                    if (!string.IsNullOrEmpty(tmp.Email))
                    {
                        string randompass = (_currentCom.Config.Keys.Contains("SetDefaultCusPass")) ? _currentCom.Config["SetDefaultCusPass"] : "******";
                        string labelEmail = _currentCom.Config.Keys.Contains("LabelMail") ? _currentCom.Config["LabelMail"] : "*****@*****.**";
                        string portalLink = _currentCom.Config.Keys.Contains("PortalLink") ? _currentCom.Config["PortalLink"] : "http://hddt.vinvoice.vn";
                        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("$company", _currentCom.Name);
                        bodyParams.Add("$cusname", tmp.Name);
                        bodyParams.Add("$username", tmp.AccountName);
                        bodyParams.Add("$password", randompass);
                        bodyParams.Add("$portalLink", portalLink);
                        emailSrv.ProcessEmail(labelEmail, tmp.Email, "RegisterCustomer", subjectParams, bodyParams);
                    }
                }
                catch (Exception ex)
                { log.Error(ex); }
                return(RedirectToAction("Index"));
            }
            else
            {
                model.tmpCustomer = tmp;
                Messages.AddErrorMessage(ErrorMessage);
                log.Error(" Create  -:" + ErrorMessage);
                return(View(model));
            }
        }
Exemplo n.º 15
0
        public ActionResult LogOn(LogOnModel _model, string captch)
        {
            string ip = Request.UserHostAddress == "::1"? "127.0.0.1" : Request.UserHostAddress;

            //if (!string.IsNullOrWhiteSpace(ipSecurity) && !ipSecurity.Contains(ip))
            //{
            //    _model.lblErrorMessage = "Địa chỉ của bạn không được truy cập vào trang web.";
            //    _model.Password = "";
            //    return View(_model);
            //}
            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));
            }
            FanxiAuthenticationBase _authenticationService = IoC.Resolve <FanxiAuthenticationBase>();

            try
            {
                if (_model.UserName.Trim() != null && _model.Password != null)
                {
                    if (_authenticationService.LogOn(_model.UserName.Trim(), _model.Password.Trim()) == true)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>();
                        user TempUser = _MemberShipProvider.GetUser(_model.UserName, true);
                        if (TempUser != null)
                        {
                            if (TempUser.FailedPasswordAttemptCount >= 5)
                            {
                                _model.lblErrorMessage = "Tài khoản đã bị khóa.";
                            }
                            else
                            {
                                TempUser.FailedPasswordAttemptCount++;
                                if (TempUser.FailedPasswordAttemptCount == 5)
                                {
                                    TempUser.IsLockedOut = true;
                                }
                                _model.lblErrorMessage = "Tài khoản hoặc mật khẩu đăng nhập không đúng";
                                _MemberShipProvider.UpdateUser(TempUser);
                            }
                            return(View(_model));
                        }
                        _model.lblErrorMessage = "Tài khoản hoặc mật khẩu đăng nhập không đúng";
                        _model.Password        = "";
                        return(View(_model));
                    }
                }
                else
                {
                    _model.Password = "";
                    return(View("LogOn", _model));
                }
            }
            catch (Exception ex)
            {
                _model.lblErrorMessage = "Tài khoản hoặc mật khẩu đăng nhập không đúng";
                _model.Password        = "";
                return(View("LogOn", _model));
            }
        }
Exemplo n.º 16
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));
            }
        }