Esempio n. 1
0
        protected override async Task <ResendConfirmationEmailResponseDto> ExecuteAsync(ResendConfirmationEmailRequestDto request, RequestContext context)
        {
            // Standardize mail
            var email = request.Email.StandardizeEmail();

            // Validate input
            _inputValidationService.ValidateEmail(email);

            // Get profile
            var profile = _uniwikiContext
                          .Profiles
                          .Select(p => new { p.Email, p.IsConfirmed, p.Id })
                          .First(p => p.Email == email);

            // Throw error if the user is already confirmed
            if (profile.IsConfirmed)
            {
                throw new RequestException(_textService.ResendConfirmation_ProfileIsAlreadyConfirmed(profile.Email));
            }

            // Send the new email confirmation secret
            await _emailConfirmationSenderService.SendConfirmationEmail(profile.Id, profile.Email);

            // Create the response
            var response = new ResendConfirmationEmailResponseDto();

            return(response);
        }
        protected override async Task <RegisterResponseDto> ExecuteAsync(RegisterRequestDto request, RequestContext context)
        {
            // Try to get profile
            var profile = _profileRepository.TryGetProfileByEmail(request.Email);

            // Email is already registered and confirmed
            if (profile != null && profile.IsConfirmed)
            {
                throw new RequestException(_textService.Error_EmailIsAlreadyUsed(request.Email));
            }

            // Register user if he is not registered yet
            if (profile == null)
            {
                // Get the name and surname
                var names = request.NameAndSurname.Split(new[] { ' ' }, 2);

                // Create url for the new profile
                var url = _stringStandardizationService.CreateUrl(request.NameAndSurname,
                                                                  u => _profileRepository.TryGetProfileByUrl(u) == null);

                // Get the hash from the password
                var password = _hashService.HashPassword(request.Password);

                // Create the profile
                profile = _profileRepository.AddProfile(request.Email, names[0], names[1], url, password.hashedPassword, password.salt, $"/img/profilePictures/no-profile-picture.jpg", _timeService.Now, false, AuthenticationLevel.PrimaryToken, request.HomeFacultyId);

                _uniwikiContext.SaveChanges();
            }

            // TODO: Set the recent courses
            // _recentCoursesService.SetAsRecentCourses(request.RecentCourses, profile.Id);

            // Send the confirmation email
            await _emailConfirmationSenderService.SendConfirmationEmail(profile.Id, profile.Email);

            return(new RegisterResponseDto(request.Email, profile.Id));
        }