Пример #1
0
        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));
        }