Beispiel #1
0
        public ActionResult Login(string userName)
        {
            try
            {
                LoginModel model = new LoginModel();
                TryUpdateModel(model);

                if (ModelState.IsValid)
                {
                    UserDa da = new UserDa();
                    model.USER_PASSWORD = SafePassword.GetSaltedPassword(model.USER_PASSWORD);
                    var exist = da.Login(model.USER_EMAIL, model.USER_PASSWORD);
                    if (exist)
                    {
                        CmnEntityModel session = new CmnEntityModel();
                        var            user    = da.getUserByEmail(model.USER_EMAIL);
                        session.UserName      = user.UserName;
                        session.Email         = user.Email;
                        session.ID            = user.ID;
                        session.IsAdmin       = user.IsAdmin;
                        session.Phone         = user.Phone;
                        session.Status        = user.Status;
                        session.USER_DISTRICT = user.Receive_District.HasValue ? user.Receive_District.Value : 0;
                        session.USER_ADDRESS  = user.Receive_Address;
                        Session.Add("CmnEntityModel", session);

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Email hoặc mật khẩu không đúng!");
                    }
                }

                return(View());
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
                System.Web.HttpContext.Current.Session["ERROR"] = ex;
                return(new EmptyResult());
            }
        }