Exemple #1
0
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            var manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>();
            var user          = new ApplicationUser()
            {
                UserName = Email.Text, Email = Email.Text
            };

            // add to account
            CustomerDB addNewCustomer = new CustomerDB();

            addNewCustomer.CreateAccount(txtFirstName.Text, txtFirstName.Text, txtPhone.Text, txtCity.Text, Email.Text);

            IdentityResult result = manager.Create(user, Password.Text);

            if (result.Succeeded)
            {
                // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                //string code = manager.GenerateEmailConfirmationToken(user.Id);
                //string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
                //manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");

                signInManager.SignIn(user, isPersistent: false, rememberBrowser: false);
                IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);

                Session["email"] = Email.Text;
            }
        }
Exemple #2
0
 public ActionResult Create(Customer cust)
 {
     if (ModelState.IsValid)
     {
         try
         {
             // add new user
             CustomerDB.CreateAccount(cust);
             return(RedirectToAction("Index"));
         }
         catch
         {
             return(View());
         }
     }
     else
     {
         return(View());
     }
 }