private void SaveSourceURL(string userId)
        {
            var sUrl = Request.QueryString["surl"];

            if (String.IsNullOrEmpty(sUrl) == false)
            {
                EFDBLibrary.EntityProfile ep = new EFDBLibrary.EntityProfile();
                ep.SaveEntityFromURL(Guid.Parse(userId), sUrl);
            }
        }
Esempio n. 2
0
        protected void LogIn(object sender, EventArgs e)
        {
            if (IsValid)
            {
                var backUrl = HttpUtility.UrlEncode(Request.QueryString["surl"]);

                // Validate the user password
                var manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
                var signinManager = Context.GetOwinContext().GetUserManager <ApplicationSignInManager>();

                // This doen't count login failures towards account lockout
                // To enable password failures to trigger lockout, change to shouldLockout: true
                var result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout: false);

                switch (result)
                {
                case SignInStatus.Success:
                    // In case this login is from third party url, we need save the original url and move back once service or task finish.
                    if (!String.IsNullOrEmpty(backUrl))
                    {
                        ApplicationUser           u  = signinManager.UserManager.Find(Email.Text, Password.Text);
                        EFDBLibrary.EntityProfile ep = new EFDBLibrary.EntityProfile();
                        ep.SaveEntityFromURL(Guid.Parse(u.Id), backUrl);
                    }
                    IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
                    break;

                case SignInStatus.LockedOut:
                    Response.Redirect("/Account/Lockout");
                    break;

                case SignInStatus.RequiresVerification:
                    Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",
                                                    Request.QueryString["ReturnUrl"],
                                                    RememberMe.Checked),
                                      true);
                    break;

                case SignInStatus.Failure:
                default:
                    FailureText.Text     = "Invalid login attempt";
                    ErrorMessage.Visible = true;
                    break;
                }
            }
        }