Esempio n. 1
0
        public async Task <LoginResponse> RegistrationAsync([FromBody] RegistrationRequest request)
        {
            var user = await _userService.GetByEmailAsync(request.Email);

            if (user != null)
            {
                throw new AppErrorException(new AppError(ErrorCode.UserAlreadyExist));
            }

            user = new User
            {
                Email        = request.Email,
                PasswordHash = HashUtils.CreateHash(request.Password),
                FirstName    = request.FirstName,
                LastName     = request.LastName,
                InviteLink   = CreateInviteLink(8)
            };

            await _userService.AddAsync(user);

            var token = _mailTokenService.EncryptToken(user.Email);

            var model = new ConfirmRegisterEmailModel {
                UserId = user.Id, Email = user.Email, Token = token
            };

            await _queueProvider.SendMessageAsync(model.ToJson());

            return(new LoginResponse
            {
                AccessToken = _authService.GenerateAccessToken(user),
                RefreshToken = _authService.GenerateRefreshToken(user)
            });
        }
Esempio n. 2
0
        public async Task ReSendEmail([FromBody] ResendEmailRequest request)
        {
            var userId = _authService.GetUserIdByToken(request.Token);
            var user   = await _userService.GetByIdAsync(userId.Value);

            if (user == null)
            {
                throw new AppErrorException(new AppError(ErrorCode.UserNotFound));
            }

            if (user.IsEmailConfirm)
            {
                throw new AppErrorException(new AppError(ErrorCode.RegistrationIsAlreadyConfirmed));
            }

            var token = _mailTokenService.EncryptToken(user.Email);

            var model = new ConfirmRegisterEmailModel {
                UserId = user.Id, Email = user.Email, Token = token
            };

            await _queueProvider.SendMessageAsync(model.ToJson());
        }