public virtual ActionResult SignIn(SignInRequest request, string returnUrl)
        {
            // I think it should be obvious why we don't want the current URL to be the return URL here ;)
            ViewData[Constants.ReturnUrlViewDataKey] = returnUrl;

            if (User != null && User.Identity != null && User.Identity.IsAuthenticated)
            {
                ModelState.AddModelError(String.Empty, "You are already logged in!");
                return View();
            }

            if (!ModelState.IsValid)
            {
                return View();
            }

            var user = UserService.FindByUsernameOrEmailAddressAndPassword(
                request.UserNameOrEmail,
                request.Password);

            if (user == null)
            {
                ModelState.AddModelError(
                    String.Empty,
                    Strings.UserNotFound);

                return View();
            }

            SetAuthenticationCookie(user);
            return SafeRedirect(returnUrl);
        }
        public virtual ActionResult SignIn(SignInRequest request, string returnUrl)
        {
            // I think it should be obvious why we don't want the current URL to be the return URL here ;)
            ViewData[Constants.ReturnUrlViewDataKey] = returnUrl;

            if (User != null && User.Identity != null && User.Identity.IsAuthenticated)
            {
                ModelState.AddModelError(String.Empty, "You are already logged in!");
                return(View());
            }

            if (!ModelState.IsValid)
            {
                return(View());
            }

            var user = UserService.FindByUsernameOrEmailAddressAndPassword(
                request.UserNameOrEmail,
                request.Password);

            if (user == null)
            {
                ModelState.AddModelError(
                    String.Empty,
                    Strings.UsernameAndPasswordNotFound);

                return(View());
            }

            SetAuthenticationCookie(user);
            return(SafeRedirect(returnUrl));
        }
        public virtual ActionResult LogOn(SignInRequest request, string returnUrl)
        {
            // TODO: modify the Object.cshtml partial to make the first text box autofocus, or use additional metadata

            ViewData[Constants.ReturnUrlViewDataKey] = returnUrl;

            if (!ModelState.IsValid) return View();

            var user = userSvc.FindByUsernameOrEmailAddressAndPassword(request.UserNameOrEmail, request.Password);

            if (user == null)
            {
                ModelState.AddModelError(String.Empty, Strings.UserNotFound);

                return View();
            }

            if (!user.Confirmed)
            {
                ViewBag.ConfirmationRequired = true;
                return View();
            }

            IEnumerable<string> roles = null;
            if (user.Roles.AnySafe()) roles = user.Roles.Select(r => r.Name);

            formsAuthSvc.SetAuthCookie(user.Username, true, roles);

            return SafeRedirect(returnUrl);
        }
Esempio n. 4
0
        public virtual ActionResult SignIn(SignInRequest request, string returnUrl)
        {
            // I think it should be obvious why we don't want the current URL to be the return URL here ;)
            ViewData[Constants.ReturnUrlViewDataKey] = returnUrl;

            if (Request.IsAuthenticated)
            {
                ModelState.AddModelError(String.Empty, "You are already logged in!");
                return(View());
            }

            if (!ModelState.IsValid)
            {
                return(View());
            }

            var user = AuthService.Authenticate(request.UserNameOrEmail, request.Password);

            if (user == null)
            {
                ModelState.AddModelError(
                    String.Empty,
                    Strings.UsernameAndPasswordNotFound);

                return(View());
            }

            AuthService.CreateSession(OwinContext, user.User, AuthenticationTypes.Password);
            return(SafeRedirect(returnUrl));
        }
        public virtual ActionResult LogOn(SignInRequest request, string returnUrl)
        {
            // I think it should be obvious why we don't want the current URL to be the return URL here ;)
            ViewData[Constants.ReturnUrlViewDataKey] = returnUrl;

            // TODO: improve the styling of the validation summary
            // TODO: modify the Object.cshtml partial to make the first text box autofocus, or use additional metadata

            if (!ModelState.IsValid)
            {
                return(View());
            }

            var user = Users.FindByUsernameOrEmailAddressAndPassword(
                request.UserNameOrEmail,
                request.Password);

            if (user == null)
            {
                ModelState.AddModelError(
                    String.Empty,
                    Strings.UserNotFound);

                return(View());
            }

            if (!user.Confirmed)
            {
                ViewBag.ConfirmationRequired = true;
                return(View());
            }

            IEnumerable <string> roles = null;

            if (user.Roles.AnySafe())
            {
                roles = user.Roles.Select(r => r.Name);
            }

            FormsAuth.SetAuthCookie(
                user.Username,
                true,
                roles);

            return(SafeRedirect(returnUrl));
        }
        public virtual ActionResult LogOn(SignInRequest request, string returnUrl)
        {
            // I think it should be obvious why we don't want the current URL to be the return URL here ;)
            ViewData[Constants.ReturnUrlViewDataKey] = returnUrl;

            // TODO: improve the styling of the validation summary
            // TODO: modify the Object.cshtml partial to make the first text box autofocus, or use additional metadata

            if (!ModelState.IsValid)
            {
                return View();
            }

            var user = Users.FindByUsernameOrEmailAddressAndPassword(
                request.UserNameOrEmail,
                request.Password);

            if (user == null)
            {
                ModelState.AddModelError(
                    String.Empty,
                    Strings.UserNotFound);

                return View();
            }

            if (!user.Confirmed)
            {
                ViewBag.ConfirmationRequired = true;
                return View();
            }

            IEnumerable<string> roles = null;
            if (user.Roles.AnySafe())
            {
                roles = user.Roles.Select(r => r.Name);
            }

            FormsAuth.SetAuthCookie(
                user.Username,
                true,
                roles);

            return SafeRedirect(returnUrl);
        }
        public virtual ActionResult LogOn(SignInRequest request, string returnUrl)
        {
            // TODO: modify the Object.cshtml partial to make the first text box autofocus, or use additional metadata

            ViewData[Constants.ReturnUrlViewDataKey] = returnUrl;

            if (!ModelState.IsValid)
            {
                return(View());
            }

            var user = userSvc.FindByUsernameOrEmailAddressAndPassword(
                request.UserNameOrEmail,
                request.Password);

            if (user == null)
            {
                ModelState.AddModelError(
                    String.Empty,
                    Strings.UserNotFound);

                return(View());
            }

            if (!user.Confirmed)
            {
                ViewBag.ConfirmationRequired = true;
                return(View());
            }

            IEnumerable <string> roles = null;

            if (user.Roles.AnySafe())
            {
                roles = user.Roles.Select(r => r.Name);
            }

            formsAuthSvc.SetAuthCookie(
                user.Username,
                true,
                roles);

            return(SafeRedirect(returnUrl));
        }
        public virtual ActionResult LogOn(SignInRequest request, string returnUrl)
        {
            // TODO: improve the styling of the validation summary
            // TODO: modify the Object.cshtml partial to make the first text box autofocus, or use additional metadata

            if (!ModelState.IsValid)
                return View();

            // TODO: allow users to sign in with email address in addition to user name
            var user = userSvc.FindByUsernameAndPassword(
                request.UserNameOrEmail,
                request.Password);

            if (user == null)
            {
                ModelState.AddModelError(
                    String.Empty,
                    Strings.UserNotFound);

                return View();
            }

            if (!user.Confirmed)
            {
                ViewBag.ConfirmationRequired = true;
                return View();
            }

            IEnumerable<string> roles = null;
            if (user.Roles.AnySafe())
            {
                roles = user.Roles.Select(r => r.Name);
            }

            formsAuthSvc.SetAuthCookie(
                user.Username,
                true,
                roles);

            return SafeRedirect(returnUrl);
        }