Esempio n. 1
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            try
            {
                int countNOKLogin = 0;

                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                List <Account_Login> _Logins = new List <Account_Login>();
                _Logins = impAccount_Login.GetAccount_LoginNOKByUsername(model.Username);
                if (_Logins != null)
                {
                    countNOKLogin = _Logins.Count;
                }

                ViewBag.countNOKLogin = countNOKLogin;

                // kiểm tra số lần đăng nhập không thành công
                if (countNOKLogin < 3)
                {
                    string salt = SaltedHash.GetSHA512(model.Username + model.Password);
                    salt           = salt.Substring(0, 10);
                    model.Password = SaltedHash.GetSHA512(salt + model.Password);

                    List <cms_Account> accountInfo = impCms_Account.Getcms_Account(model.Username, model.Password);
                    if (accountInfo != null)
                    {
                        if (accountInfo.Count > 0)
                        {
                            //Login Success
                            //For Set Authentication in Cookie (Remeber ME Option)
                            SignInRemember(model.Username, model.RememberMe);
                            //Set A Unique ID in session
                            Session["UserInfo"] = accountInfo[0];
                            //Log account login
                            AddLogin(Common.Constant.StatusLoginOK, accountInfo[0].Username);
                            if (string.IsNullOrWhiteSpace(returnUrl))
                            {
                                return(RedirectToLocal("/Home/index"));
                            }
                            else if (returnUrl.Length < 5)
                            {
                                return(RedirectToLocal("/Home/index"));
                            }
                            else
                            {
                                return(RedirectToLocal(returnUrl));
                            }
                        }
                        else
                        {
                            AddLogin(Common.Constant.StatusLoginNOK, model.Username);
                            ModelState.AddModelError("", "Đăng nhập không thành công.");
                            TempData["ErrorMSG"] = "Đăng nhập không thành công. Mời bạn đăng nhập lại";
                            return(View(model));
                        }
                    }
                    else
                    {
                        AddLogin(Common.Constant.StatusLoginNOK, model.Username);
                        ModelState.AddModelError("", "Đăng nhập không thành công.");
                        TempData["ErrorMSG"] = "Đăng nhập không thành công. Mời bạn đăng nhập lại!";
                        return(View(model));
                    }
                }
                else if (countNOKLogin < 5)
                {
                    if (!this.IsCaptchaValid("Validate your captcha"))
                    {
                        ModelState.AddModelError("", "Captcha nhập không đúng.");
                        return(View(model));
                    }
                    else
                    {
                        string salt = SaltedHash.GetSHA512(model.Username + model.Password);
                        salt           = salt.Substring(0, 10);
                        model.Password = SaltedHash.GetSHA512(salt + model.Password);

                        List <cms_Account> accountInfo = impCms_Account.Getcms_Account(model.Username, model.Password);
                        if (accountInfo != null)
                        {
                            if (accountInfo.Count > 0)
                            {
                                //Login Success
                                //For Set Authentication in Cookie (Remeber ME Option)
                                SignInRemember(model.Username, model.RememberMe);
                                //Set A Unique ID in session
                                Session["UserInfo"] = accountInfo[0];
                                //Log account login
                                AddLogin(Common.Constant.StatusLoginOK, accountInfo[0].Username);
                                if (string.IsNullOrWhiteSpace(returnUrl))
                                {
                                    return(RedirectToLocal("/Home/index"));
                                }
                                else if (returnUrl.Length < 5)
                                {
                                    return(RedirectToLocal("/Home/index"));
                                }
                                else
                                {
                                    return(RedirectToLocal(returnUrl));
                                }
                            }
                            else
                            {
                                AddLogin(Common.Constant.StatusLoginNOK, model.Username);
                                ModelState.AddModelError("", "Đăng nhập không thành công.");
                                TempData["ErrorMSG"] = "Đăng nhập không thành công. Mời bạn đăng nhập lại";
                                return(View(model));
                            }
                        }
                        else
                        {
                            AddLogin(Common.Constant.StatusLoginNOK, model.Username);
                            ModelState.AddModelError("", "Đăng nhập không thành công.");
                            TempData["ErrorMSG"] = "Đăng nhập không thành công. Mời bạn đăng nhập lại!";
                            return(View(model));
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Số lần đăng nhập sai quá 5 lần, Xin đợi 15 phút đăng nhập lại!");
                    TempData["ErrorMSG"] = "Số lần đăng nhập sai quá 5 lần, Xin đợi 15 phút đăng nhập lại!";
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                AddLogin(Common.Constant.StatusLoginNOK, model.Username);
                logIn.Info("Login:"******"", "Có lỗi trong quá trình đăng nhập.");
                throw;
            }
        }
Esempio n. 2
0
        public ActionResult ChangePassword(ChangePasswordViewModel model)
        {
            AddPageHeader("Đổi mật khẩu", "");
            AddBreadcrumb("Hệ thống", "");
            AddBreadcrumb("Đổi mật khẩu", "/Account/ChangePassword");

            cms_Account _Account = new cms_Account();

            _Account = ((cms_Account)Session["UserInfo"]);


            try
            {
                if (ModelState.IsValid)
                {
                    if (model.OldPassword.Equals(model.Password))
                    {
                        ViewBag.TitleSuccsess = "Password new trùng với Password cũ, Mời bạn nhập lại";
                        ViewBag.TypeAlert     = CMSLIS.Common.Constant.typeError;
                    }
                    else if (!model.Password.Equals(model.ConfirmPassword))
                    {
                        ViewBag.TitleSuccsess = "Nhập password new không trùng với confirm password, Mời bạn nhập lại";
                        ViewBag.TypeAlert     = CMSLIS.Common.Constant.typeError;
                    }
                    else
                    {
                        string salt = SaltedHash.GetSHA512(_Account.Username + model.OldPassword);
                        salt = salt.Substring(0, 10);
                        model.OldPassword = SaltedHash.GetSHA512(salt + model.OldPassword);

                        List <cms_Account> accountInfo = impCms_Account.Getcms_Account(_Account.Username, model.OldPassword);


                        if (accountInfo != null)
                        {
                            if (accountInfo.Count > 0)
                            {
                                salt           = SaltedHash.GetSHA512(_Account.Username + model.Password);
                                salt           = salt.Substring(0, 10);
                                model.Password = SaltedHash.GetSHA512(salt + model.Password);

                                List <cms_Account> cms_Accounts = impCms_Account.ChangePasswordCms_Account(_Account.uid, model.Password);

                                if (!string.IsNullOrEmpty(cms_Accounts[0].Username))
                                {
                                    ViewBag.TitleSuccsess = Constant.ChangePasswordSuccess;
                                    ViewBag.TypeAlert     = CMSLIS.Common.Constant.typeError;
                                    AddLogAction(_Account.uid.ToString(), Constant.ActionChangePasswordOK.ToString());
                                }
                                else
                                {
                                    ViewBag.TitleSuccsess = Constant.ChangePasswordError;
                                    ViewBag.TypeAlert     = CMSLIS.Common.Constant.typeError;
                                    AddLogAction(_Account.uid.ToString(), Constant.ActionChangePasswordOK.ToString());
                                }
                            }
                            else
                            {
                                ViewBag.TitleSuccsess = Constant.NoFindAccount;
                                ViewBag.TypeAlert     = CMSLIS.Common.Constant.typeError;
                                AddLogAction(_Account.uid.ToString(), Constant.ActionChangePasswordOK.ToString());
                            }
                        }
                        else
                        {
                            ViewBag.TitleSuccsess = Constant.Error;
                            ViewBag.TypeAlert     = CMSLIS.Common.Constant.typeError;
                            AddLogAction(_Account.uid.ToString(), Constant.ActionChangePasswordOK.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AddLogAction(_Account.uid.ToString(), Constant.ActionChangePasswordOK.ToString());
                ViewBag.TitleSuccsess = Constant.Error;
                ViewBag.TypeAlert     = CMSLIS.Common.Constant.typeError;
                logIn.Info("ChangePassword: " + ex.ToString());
            }
            return(View());
        }