Exemplo n.º 1
0
        public ActionResult Index(FormLogin form)
        {
            var user = repository.LogIn(form.login, form.pass);

            if (user != null)
            {
                if (System.Web.HttpContext.Current.Response.AddUserInCookie(user, form.remembeMe))
                {
                    if (!string.IsNullOrEmpty(form.ReturnUrl))
                    {
                        return(new RedirectResult(form.ReturnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }

            if (NewSupplier(form))
            {
                form.errorMessage = "Введите ещё раз логин и пароль.";
                form.login        = null;
            }
            else
            {
                form.errorMessage = "Не верный логин и/или пароль";
            }

            form.pass = null;
            return(View(form));
        }
Exemplo n.º 2
0
        public HttpResponseMessage Login(FormLogin form)
        {
            var user = repository.LogIn(form.login, form.pass);

            if (user != null)
            {
                if (System.Web.HttpContext.Current.Response.AddUserInCookie(user, form.remembeMe))
                {
                    if (!string.IsNullOrEmpty(form.ReturnUrl))
                    {
                        var responce = new HttpResponseMessage(HttpStatusCode.Redirect);
                        responce.Headers.Add("user", Convert.ToString(user.Id));
                        responce.Headers.Location = new Uri(form.ReturnUrl, UriKind.RelativeOrAbsolute);
                        return(responce);
                    }
                    else
                    {
                        return(new HttpResponseMessage(HttpStatusCode.OK));
                    }
                }
            }

            return(new HttpResponseMessage(HttpStatusCode.Forbidden));
        }