Exemplo n.º 1
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationFormModel formModel)
        {
            var form = GetForm(formModel.Id);

            if (form != null)
            {
                var formErrors = GetFormErrors(ModelState);

                if (formErrors == null)
                {
                    form.PostedSuccessfully = true;

                    var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

                    if (loginInfo == null)
                    {
                        Context.ErrorMessage = "External login info was not found";

                        return View("error");
                    }

                    var user = new ApplicationUser { UserName = formModel.Email, Email = formModel.Email };
                    user.Logins = new List<UserLoginInfo>
                    {
                        new UserLoginInfo
                        {
                            LoginProvider = loginInfo.Login.LoginProvider,
                            ProviderKey = loginInfo.Login.ProviderKey
                        }
                    };

                    var result = await SecurityService.CreateUserAsync(user);

                    if (result.Succeeded)
                    {
                        form.PostedSuccessfully = true;

                        user = await SecurityService.GetUserByNameAsync(formModel.Email);

                        Context.Customer = await this.CustomerService.CreateCustomerAsync(
                            formModel.Email, formModel.Email, null, user.Id, null);

                        var identity = SecurityService.CreateClaimsIdentity(user.UserName);
                        AuthenticationManager.SignIn(identity);

                        return RedirectToLocal(formModel.ReturnUrl);
                    }
                    else
                    {
                        form.Errors = new SubmitFormErrors("form", result.Errors.First());
                        form.PostedSuccessfully = false;

                        return View("external_login_confirmation");
                    }
                }
                else
                {
                    form.Errors = formErrors;
                    form.PostedSuccessfully = false;

                    return View("external_login_confirmation");
                }
            }

            Context.ErrorMessage = "Liquid error: Form context was not found.";

            return View("error");
        }
Exemplo n.º 2
0
        public Task<IdentityResult> CreateUserAsync(ApplicationUser user)
        {
            var requestUri = CreateRequestUri(RelativePaths.Common);

            return SendAsync<ApplicationUser, IdentityResult>(requestUri, HttpMethod.Post, user);
        }
Exemplo n.º 3
0
        public async Task<ActionResult> Register(RegisterFormModel formModel)
        {
            var form = Service.GetForm(SiteContext.Current, formModel.Id);

            if (form != null)
            {
                var formErrors = GetFormErrors(ModelState);

                if (formErrors == null)
                {
                    form.PostedSuccessfully = true;

                    var user = new ApplicationUser
                    {
                        Email = formModel.Email,
                        Password = formModel.Password,
                        UserName = formModel.Email
                    };

                    var result = await SecurityService.CreateUserAsync(user);

                    if (result.Succeeded)
                    {
                        user = await SecurityService.GetUserByNameAsync(user.UserName);

                        Context.Customer = await this.CustomerService.CreateCustomerAsync(
                            formModel.Email, formModel.FirstName, formModel.LastName, user.Id, null);

                        await SecurityService.PasswordSingInAsync(formModel.Email, formModel.Password, false);

                        var identity = SecurityService.CreateClaimsIdentity(formModel.Email);
                        AuthenticationManager.SignIn(identity);

                        return RedirectToAction("Index", "Account");
                    }
                    else
                    {
                        form.Errors = new SubmitFormErrors("form", result.Errors.First());
                        form.PostedSuccessfully = false;
                    }
                }
                else
                {
                    form.Errors = formErrors;
                    form.PostedSuccessfully = false;
                }
            }
            else
            {
                return View("error");
            }

            return View("customers/register");
        }
Exemplo n.º 4
0
 public async Task<IdentityResult> CreateUserAsync(ApplicationUser user)
 {
     return await this.SecurityClient.CreateUserAsync(user);
 }