Ejemplo n.º 1
0
        // Agency Registration Process
        public async Task <IdentityResult> ClaimAgencyAsync(AgencyRequest dhsmv)
        {
            if (AlreadyOnboard(dhsmv.agency)) // check that agency has an active account
            {
                // Account is active already send to login
                var           msg   = "This agency has already completed the onboarding process";
                IdentityError error = BuildError(msg);
                return(IdentityResult.Failed(error));
            }


            if (IsInProgress(dhsmv.agency, dhsmv.email)) // check that agency has an active account
            {
                // agency has registered s4sales identity
                // but not clicked the onboarded with stripe button and NOW is attempting to re-register with
                // a different email address
                var           msg   = "This agency has already begun onboarding with a different email";
                IdentityError error = BuildError(msg);
                return(IdentityResult.Failed(error));
            }


            int agencyId = await GetAgencyId(dhsmv.agency);

            S4LookupNormalizer normalizer = new S4LookupNormalizer();
            S4Identity         agency     = new S4Identity(agencyId.ToString())
            {
                email = dhsmv.email,
                normalized_user_name = normalizer.Normalize(agencyId.ToString()),
                normalized_email     = normalizer.Normalize(dhsmv.email)
            };

            IdentityResult creating = await _user_manager.CreateAsync(agency, dhsmv.password);

            if (creating != IdentityResult.Success)
            {
                var           msg   = "Error claiming agency";
                IdentityError error = BuildError(msg);
                return(IdentityResult.Failed(error));
            }

            IList <string> roles = new List <string>(); // add roles to account

            roles.Add("agency");
            foreach (var role in roles) // in case accounts ever need multiple roles
            {
                await _user_manager.AddToRoleAsync(agency, role);
            }

            if (!AddAgencyDetails(dhsmv, agency)) // writes details to agency table
            {
                var           msg   = "Error adding the agency details";
                IdentityError error = BuildError(msg);
                return(IdentityResult.Failed(error));
            }
            return(IdentityResult.Success);
        }
        public S4UserProfileStoreFixture()
        {
            Connection = new OracleConnection(connStr);
            Connection.Open();

            MembershipConnection = new OracleConnection(membershipConnStr);
            MembershipConnection.Open();

            var profileStore   = new S4UserProfileStore(appName, Connection);
            var passwordHasher = new S4PasswordHasher <S4IdentityUser <S4UserProfile> >();
            var userStore      = new S4UserStore <S4IdentityUser <S4UserProfile>, S4UserProfile>(
                appName, Connection, MembershipConnection, profileStore);
            var identityOptions = Options.Create(new IdentityOptions()
            {
                Password = new PasswordOptions()
                {
                    RequireDigit           = false,
                    RequireLowercase       = false,
                    RequireNonAlphanumeric = false,
                    RequireUppercase       = false,
                    RequiredLength         = 1
                }
            });
            var userValidator          = new UserValidator <S4IdentityUser <S4UserProfile> >();
            var passwordValidator      = new PasswordValidator <S4IdentityUser <S4UserProfile> >();
            var normalizer             = new S4LookupNormalizer();
            var identityErrorDescriber = new IdentityErrorDescriber();
            var mockLogger             = new MockLogger <UserManager <S4IdentityUser <S4UserProfile> > >();

            UserManager = new UserManager <S4IdentityUser <S4UserProfile> >(
                userStore,
                identityOptions,
                passwordHasher,
                new List <IUserValidator <S4IdentityUser <S4UserProfile> > >()
            {
                userValidator
            },
                new List <IPasswordValidator <S4IdentityUser <S4UserProfile> > >()
            {
                passwordValidator
            },
                normalizer,
                identityErrorDescriber,
                null,
                mockLogger
                );
        }