Example #1
0
 public static async Task <RefreshToken> AddAsync(this IAsyncRefreshTokenRepository repository, OAuthToken oAuth, int userId, string deviceName = null)
 {
     return(await repository.AddAsync(new RefreshToken
     {
         Refresh = oAuth.RefreshToken,
         Access = oAuth.AccessToken,
         CreatedAt = oAuth.CreatedAt,
         UserId = userId,
         DeviceName = deviceName
     }));
 }
Example #2
0
        public async Task <OAuthToken> SignUpAsync(string username, string email, string password)
        {
            _logger.InitMethod(nameof(SignUpAsync), username, email, "pass");

            Validation.NotBlankString
            .Add(username, _localizer["Username is empty!"])
            .Add(email, _localizer["Email is empty!"])
            .AddAndThrow(password, _localizer["Password is empty!"]);

            var now         = DateTime.Now;
            var userAccount = new UserAccount {
                UserName = username, Email = email, RegisteredAt = now, LastOnlineAt = now
            };

            var result = await _userManager.CreateAsync(userAccount, password); //? check "already exist"?

            if (!result.Succeeded)
            {
                _logger.LogWarning("fail creating");
                throw new InvalidInputException(result.GetErrorDescriptions());
            }

            await _userProfileRep.AddAsync(new UserProfile
            {
                Id       = userAccount.Id,
                UserName = userAccount.UserName
            });

            var oAuth = await GetTokenAsync(userAccount);

            await _tokenRep.AddAsync(oAuth, userAccount.Id); //ToDo: DeviceName

            _logger.LogInformation($"successfully created new user with id: {userAccount.Id}, username: {username} and email: {email} | rTokenLength: {oAuth.RefreshToken.Length} | aToken: {oAuth.AccessToken.Length}");

            return(oAuth);
        }