Exemplo n.º 1
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            try
            {
                // Verification.
                if (ModelState.IsValid)
                {
                    // Initialization.
                    var loginInfo = _iAccountDAL.TryLogin(model.Username, Encryptor.MD5Hash(model.Password));
                    // Verification.
                    if (loginInfo != null)
                    {
                        // Login In.
                        this.SignInUser(loginInfo.UserName, loginInfo.ID, model.Remember);

                        ViewBag.ThongBao    = "Login Successfull!";
                        Session["username"] = loginInfo.UserName;
                        //Session["imageUSer"] = info.Image;

                        //if (model.Remember)
                        //{
                        //    HttpCookie ckUserName = new HttpCookie("username");
                        //    ckUserName.Expires = DateTime.Now.AddSeconds(3600);
                        //    ckUserName.Value = loginInfo.UserName;
                        //    Response.Cookies.Add(ckUserName);

                        //    HttpCookie ckPassword = new HttpCookie("password");
                        //    ckPassword.Expires = DateTime.Now.AddSeconds(3600);
                        //    ckPassword.Value = loginInfo.Password;
                        //    Response.Cookies.Add(ckPassword);
                        //}
                        // Info.
                        return(this.RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        // Setting.
                        ModelState.AddModelError(string.Empty, "Invalid username or password.");
                    }
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                // Info
                Console.WriteLine(ex);
            }
            // If we got this far, something failed, redisplay form
            return(this.View(model));
        }