예제 #1
0
        public ActionResult Login(LoginModel model, string returnUrl = "~/")
        {
            if (ModelState.IsValid)
            {
                AccountModel account = null;
                try
                {
                    using (AccountContext context = new AccountContext())
                    {
                        account = context.Login(model.UserName, model.Password);
                    }
                }
                catch
                { }
                if (account == null)
                {
                    ModelState.AddModelError("", Resources.Account.Message_WrongLogin);
                    return(View(model));
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false);
                    xSession.AccountId = account.ActionId;
                    xConfig.SetCookieSettings(account.LanguageCode);

                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(Redirect("~/"));
                    }
                }
            }
            return(View());
        }