Пример #1
0
 protected void LogIn(object sender, EventArgs e)
 {
     if (IsValid)
     {
         // Validate the user password
         IAuthenticationManager manager = new AuthenticationIdentityManager(new IdentityStore()).Authentication;
         IdentityResult         result  = manager.CheckPasswordAndSignIn(Context.GetOwinContext().Authentication, UserName.Text, Password.Text, RememberMe.Checked);
         if (result.Success)
         {
             OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
         }
         else
         {
             FailureText.Text     = result.Errors.FirstOrDefault();
             ErrorMessage.Visible = true;
         }
     }
 }
        private void CreateAndLoginUser()
        {
            if (!IsValid)
            {
                return;
            }
            var user = new User(userName.Text);
            IAuthenticationManager manager = new AuthenticationIdentityManager(new IdentityStore()).Authentication;
            IdentityResult         result  = manager.CreateAndSignInExternalUser(Context.GetOwinContext().Authentication, user);

            if (result.Success)
            {
                OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            }
            else
            {
                AddErrors(result);
                return;
            }
        }
Пример #3
0
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            string userName = UserName.Text;
            var    manager  = new AuthenticationIdentityManager(new IdentityStore());
            User   u        = new User(userName)
            {
                UserName = userName
            };
            IdentityResult result = manager.Users.CreateLocalUser(u, Password.Text);

            if (result.Success)
            {
                manager.Authentication.SignIn(Context.GetOwinContext().Authentication, u.Id, isPersistent: false);
                OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            }
            else
            {
                ErrorMessage.Text = result.Errors.FirstOrDefault();
            }
        }
 protected void Page_Load()
 {
     // Process the result from an auth provider in the request
     ProviderName = OpenAuthProviders.GetProviderNameFromRequest(Request);
     if (String.IsNullOrEmpty(ProviderName))
     {
         Response.Redirect("~/Account/Login");
     }
     if (!IsPostBack)
     {
         IAuthenticationManager manager = new AuthenticationIdentityManager(new IdentityStore()).Authentication;
         var            auth            = Context.GetOwinContext().Authentication;
         ClaimsIdentity id     = manager.GetExternalIdentity(auth);
         IdentityResult result = manager.SignInExternalIdentity(auth, id);
         if (result.Success)
         {
             OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
         }
         else if (User.Identity.IsAuthenticated)
         {
             result = manager.LinkExternalIdentity(id, User.Identity.GetUserId());
             if (result.Success)
             {
                 OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
             }
             else
             {
                 AddErrors(result);
                 return;
             }
         }
         else
         {
             userName.Text = id.Name;
         }
     }
 }