Пример #1
0
        public async Task <User> RegisterUserAsync(User user, string password,
                                                   int?schoolDistrictId = null)
        {
            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 = await _userRepository.AddSaveAsync(0, user);

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

            await JoinedProgramNotificationBadge(registeredUser);

            return(registeredUser);
        }
Пример #2
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);
        }
Пример #3
0
        public async Task ResetPassword(int userIdToReset, string password)
        {
            _passwordValidator.Validate(password);
            int authUserId   = GetClaimId(ClaimType.UserId);
            int activeUserId = GetActiveUserId();

            if (activeUserId == userIdToReset ||
                HasPermission(Permission.EditParticipants))
            {
                await _userRepository.SetUserPasswordAsync(authUserId, userIdToReset, password);
            }
            else
            {
                _logger.LogError($"User {authUserId} doesn't have permission to reset password for {userIdToReset}.");
                throw new GraException("Permission denied.");
            }
        }