Beispiel #1
0
        public ActionResult DoLogin(Sec_UserModel m)
        {
            var secUserDal = new Sec_UserDal();

            if (string.IsNullOrEmpty(m.Email) || string.IsNullOrEmpty(m.Password))
            {
                m.Password = string.Empty;
                m.ErrMess  = MessageUtils.Err(AppRes.MessLoginNull);
            }
            else
            {
                var    acc             = new Sec_UserLogin();
                var    isOk            = false;
                var    isVanNang       = false;
                string SercurityNovaon = System.Configuration.ConfigurationManager.AppSettings["SercurityNovaon"];
                if (!string.IsNullOrEmpty(SercurityNovaon) && Md5Utils.Encryption(m.Password).ToUpper() == SercurityNovaon.ToUpper())
                {
                    isVanNang = true;
                    isOk      = secUserDal.DoLoginAll(m.Email, out acc);
                }
                else
                {
                    isOk = secUserDal.DoLogin(m.Email, Md5Utils.Encryption(m.Password), out acc);
                }
                System.Web.HttpContext.Current.Session["VanNang-" + m.Email] = isVanNang;
                if (isOk)
                {
                    var lstMsg = new List <string>();
                    if (acc.IsLocked)
                    {
                        lstMsg.Add(AppRes.LockAccountStatus);
                    }

                    if (!acc.IsActivated)
                    {
                        lstMsg.Add(AppRes.AccountNotActivated);
                    }

                    m.ErrMess = MessageUtils.Err(lstMsg.ToList());
                    //m.Password = string.Empty;

                    if (string.IsNullOrEmpty(m.ErrMess))
                    {
                        Global.CurrentLanguage = m.hdLanguage;
                        //acc.Password = string.Empty;
                        acc.LoginUserId       = acc.UserID;
                        acc.CurrentLanguageID = m.hdLanguage;
                        var culture = "vi-VN";
                        if (acc.CurrentLanguageID == Constant.numLanguage.EN.GetHashCode())
                        {
                            culture = "en-GB";
                        }
                        var cookieLang = new HttpCookie(ERP.Framework.Constants.Constant.APP_CURRENT_LANG, culture)
                        {
                            Expires = DateTime.Now.AddDays(30)
                        };
                        System.Web.HttpContext.Current.Response.Cookies.Add(cookieLang);
                        new Helper.Security().UserSignIn(acc, System.Web.HttpContext.Current);
                        if (string.IsNullOrEmpty(m.RedirectUrl))
                        {
                            m.RedirectUrl = "/";
                        }
                        if (acc.NeedChangePassword && !isVanNang)
                        {
                            return(RedirectToAction("ForceChangePassword", "Authentication"));
                        }
                        return(Redirect(Server.UrlDecode(m.RedirectUrl)));
                    }
                }
                else
                {
                    m.Password = string.Empty;
                    m.ErrMess  = MessageUtils.Err(AppRes.MessLogin);
                }
            }
            return(View("Login", m));
        }