コード例 #1
0
        public override async Task <ActionResult <LoginAccountResponse> > HandleAsync(
            [FromBody] LoginAccountRequest request,
            CancellationToken cancellationToken = default)
        {
            var account = await _databaseContext.UserAccounts.SingleOrDefaultAsync(x =>
                                                                                   request.Email.ToLower() == x.Email.ToLower() &&
                                                                                   x.Password == request.Password, cancellationToken);

            if (account == null)
            {
                return(NotFound("Account not found"));
            }

            var finApiSession = await _finApiService.Login(account.Id.ToString(), request.Password, cancellationToken);

            var accessToken  = _tokenService.GenerateToken(account, finApiSession.RefreshToken);
            var refreshToken = _tokenService.GenerateRefreshToken();

            var session = new FinApiSession(finApiSession._AccessToken, finApiSession.RefreshToken);
            await _cachingService.SaveUserSession(account.Id, session, finApiSession.ExpiresIn);

            return(Ok(new LoginAccountResponse(accessToken, refreshToken)));
        }