Пример #1
0
        public async Task <RegistrationRequest> RegisterUser(RegistrationRequest registrationRequest)
        {
            await ValidateForm(registrationRequest);

            var registrationType = await GetUserRegistrationType();

            await IsUserEnabled(registrationType);

            var userProfileUpdater = new UserProfileUpdater(Cache, BudgeterLock, UserContext);

            // Validate the profile first, we don't want to create the user, and then fail registration.
            // TODO: Thread safety. I think we have to wait until we can delete users to handle this property, check, register, then save profile, if profile fails delete user.
            var validatedProfile = await userProfileUpdater.ValidateUserProfilePropertyUpdates(registrationRequest.UserProfileProperties, IsAdmin, true);

            var user = await new UserLogic(Cache, UserContext).CreateUser(new BudgetUser {
                Username = registrationRequest.Username
            });

            registrationRequest.UserId = user.UserId;

            await SaveProfile(registrationRequest, validatedProfile, userProfileUpdater);

            await GiveUserRoles(registrationRequest.UserId);

            if (registrationRequest.CreateRegistrationToken)
            {
                registrationRequest.RegistrationToken = await CreateRegistrationToken(registrationRequest);
            }

            //await SendRegistrationEvent(registrationRequest, registrationType);

            return(registrationRequest);
        }
        public async Task <List <UserProfileProperty> > Put([FromBody] List <UserProfileProperty> userProfileProperties)
        {
            CheckNullBody(userProfileProperties);

            if (!IsAdmin && userProfileProperties.Any(c => c.UserId != UserId))
            {
                throw new CallerException("Users cannot update other Users profiles.");
            }

            var userProfileUpdater = new UserProfileUpdater(Cache, BudgeterLock, Context);

            return(await userProfileUpdater.UpdateUserProfileProperties(userProfileProperties, IsAdmin));
        }
Пример #3
0
        public async Task AddGoogleIdToProfileProperty(UserSearchResponse user, string googleId, bool isAdmin)
        {
            List <UserProfileProperty> googleIdPP = new List <UserProfileProperty>
            {
                new UserProfileProperty
                {
                    UserId = user.UserId,
                    Value  = googleId,
                    ProfilePropertyName = "GoogleId"
                }
            };

            UserProfileUpdater userProfileUpdater = new UserProfileUpdater(Cache, BudgeterLock, UserContext);

            await userProfileUpdater.UpdateUserProfileProperties(googleIdPP, isAdmin);
        }
Пример #4
0
        private async Task SaveProfile(RegistrationRequest registrationRequest, Dictionary <UserProfileProperty, ProfileProperty> validatedProfile, UserProfileUpdater userProfileUpdater)
        {
            if (registrationRequest.UserProfileProperties == null || registrationRequest.UserProfileProperties.Count == 0)
            {
                return;
            }

            foreach (var profileProperty in validatedProfile)
            {
                profileProperty.Key.UserId = registrationRequest.UserId;
            }

            registrationRequest.UserProfileProperties = await userProfileUpdater.SaveValidatedUserProfileProperties(validatedProfile, IsAdmin);
        }