Exemple #1
0
        public async Task <User> RegisterUserAsync(User user, string password,
                                                   bool MCRegistration = false, bool allowDuringCloseProgram = false)
        {
            if (allowDuringCloseProgram == false)
            {
                VerifyCanRegister();
            }

            var existingUser = await _userRepository.GetByUsernameAsync(user.Username);

            if (existingUser != null)
            {
                throw new GraException("Someone has already chosen that username, please try another.");
            }

            await ValidateUserFields(user);

            _passwordValidator.Validate(password);

            user.CanBeDeleted = true;
            user.IsLockedOut  = false;

            user.CardNumber  = user.CardNumber?.Trim();
            user.Email       = user.Email?.Trim();
            user.FirstName   = user.FirstName?.Trim();
            user.LastName    = user.LastName?.Trim();
            user.PhoneNumber = user.PhoneNumber?.Trim();
            user.PostalCode  = user.PostalCode?.Trim();
            user.Username    = user.Username?.Trim();

            var registeredUser = new User();

            if (MCRegistration)
            {
                registeredUser = await _userRepository.AddSaveAsync(
                    GetClaimId(ClaimType.UserId), user);
            }
            else
            {
                registeredUser = await _userRepository.AddSaveAsync(0, user);
            }

            await _userRepository
            .SetUserPasswordAsync(registeredUser.Id, registeredUser.Id, password);

            await JoinedProgramNotificationBadge(registeredUser);

            await _activityService.AwardUserTriggersAsync(registeredUser.Id, false);

            return(registeredUser);
        }
Exemple #2
0
        public async Task <User> RegisterUserAsync(User user, string password,
                                                   int?schoolDistrictId = null, bool MCRegistration = false)
        {
            VerifyCanRegister();
            var existingUser = await _userRepository.GetByUsernameAsync(user.Username);

            if (existingUser != null)
            {
                throw new GraException("Someone has already chosen that username, please try another.");
            }

            await ValidateUserFields(user);

            _passwordValidator.Validate(password);

            user.CanBeDeleted = true;
            user.IsLockedOut  = false;

            if (!string.IsNullOrWhiteSpace(user.EnteredSchoolName))
            {
                var enteredSchool = await _schoolService
                                    .AddEnteredSchool(user.EnteredSchoolName, schoolDistrictId.Value);

                user.EnteredSchoolId = enteredSchool.Id;
            }
            var registeredUser = new User();

            if (MCRegistration)
            {
                registeredUser = await _userRepository.AddSaveAsync(
                    GetClaimId(ClaimType.UserId), user);
            }
            else
            {
                registeredUser = await _userRepository.AddSaveAsync(0, user);
            }

            await _userRepository
            .SetUserPasswordAsync(registeredUser.Id, registeredUser.Id, password);

            await JoinedProgramNotificationBadge(registeredUser);

            await _activityService.AwardUserTriggersAsync(registeredUser.Id, false);

            return(registeredUser);
        }