Beispiel #1
0
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new ApplicationUser {
                    UserName    = model.Email, Email = model.Email,
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    CompanyName = model.CompanyName,
                    Title       = model.Title,
                    Website     = model.Website,
                    Phone       = model.Phone,
                    DesignRole  = model.DesignRole
                };


                RegistrationAllowmentProvider regProv   = new RegistrationAllowmentProvider();
                RegistrationAllowmentResult   regResult = regProv.RegistrationAllowed(user.Email);
                if (regResult.Denied || regResult.ApprovalRequired)
                {
                    var identResult = new IdentityResult(new string[] { "Registration is only available for Techmer employees." });
                    AddErrors(identResult);
                }
                else if (regResult.Allowed)
                {
                    var result = await UserManager.CreateAsync(user);

                    if (result.Succeeded)
                    {
                        GenerateDefaultWorkspace(user);

                        result = await UserManager.AddLoginAsync(user.Id, info.Login);

                        if (result.Succeeded)
                        {
                            await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                            return(RedirectToLocal(returnUrl));
                        }
                    }
                    AddErrors(result);
                }
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Beispiel #2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName    = model.Email,
                    Email       = model.Email,
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    CompanyName = model.CompanyName,
                    Website     = model.Website,
                    Title       = model.Title,
                    Phone       = model.Phone,
                    DesignRole  = model.DesignRole
                };
                var passwordValid = await UserManager.PasswordValidator.ValidateAsync(model.Password);


                RegistrationAllowmentProvider regProv   = new RegistrationAllowmentProvider();
                RegistrationAllowmentResult   regResult = regProv.RegistrationAllowed(user.Email);
                if (regResult.Denied)
                {
                    var result = new IdentityResult(new string[] { "Registration is only available for Techmer employees." });
                    AddErrors(result);
                }
                else if (!captchaValid())
                {
                    var result = new IdentityResult(new string[] { "reCaptcha validation failed." });
                    AddErrors(result);
                }
                else if (!passwordValid.Succeeded)
                {
                    AddErrors(passwordValid);
                }
                else if (regResult.ApprovalRequired)
                {
                    Invitation invite = new Invitation(model);

                    if (appDb.Invitations.Where(i => i.email == model.Email).Count() > 0)
                    {
                        var result = new IdentityResult(new String[] { "Request for access already exists for this email address." });
                        AddErrors(result);
                    }
                    else if (appDb.Users.Where(i => i.Email == model.Email).Count() > 0)
                    {
                        var result = new IdentityResult(new String[] { "A user account already exists for this email address." });
                        AddErrors(result);
                    }
                    else
                    {
                        appDb.Invitations.Add(invite);
                        appDb.SaveChanges();

                        return(View("InvitationReceived"));
                    }
                }
                else if (regResult.Allowed)
                {
                    var result = await AccountCreationProvider.Converter(this, UserManager, user, model);

                    if (result.Succeeded)
                    {
                        return(View("DisplayEmail"));
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }