public async Task <Google2FaResultModel <T> > Check2FaAsync <T>(string clientId, string code) { try { bool codeIsValid = await _confirmationCodesClient.Google2FaCheckCodeAsync(clientId, code); if (!codeIsValid) { return(Google2FaResultModel <T> .Fail( LykkeApiErrorCodes.Service.SecondFactorCodeIncorrect.Name, LykkeApiErrorCodes.Service.SecondFactorCodeIncorrect.DefaultMessage)); } return(null); } catch (ApiException e) { switch (e.StatusCode) { case HttpStatusCode.BadRequest: return(Google2FaResultModel <T> .Fail( LykkeApiErrorCodes.Service.TwoFactorRequired.Name, LykkeApiErrorCodes.Service.TwoFactorRequired.DefaultMessage)); case HttpStatusCode.Forbidden: return(Google2FaResultModel <T> .Fail( LykkeApiErrorCodes.Service.SecondFactorCheckForbiden.Name, LykkeApiErrorCodes.Service.SecondFactorCheckForbiden.DefaultMessage)); } throw; } }
public async Task <IActionResult> ConfirmTradingSession([FromBody] TradingSessionConfirmModel model) { var sessionId = _requestContext.SessionId; var tradingSession = await _clientSessionsClient.GetTradingSession(sessionId); if (tradingSession == null) { throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.InconsistentState); } if (tradingSession.Confirmed.HasValue && tradingSession.Confirmed.Value) { throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.InconsistentState); } try { var codeIsValid = await _confirmationCodesClient.Google2FaCheckCodeAsync(_requestContext.ClientId, model.Confirmation); if (codeIsValid) { var session = await _clientSessionsClient.GetAsync(sessionId); await _clientSessionsClient.ConfirmTradingSession(_requestContext.ClientId, session.AuthId.ToString()); await _clientSessionsClient.ConfirmSessionAsync(sessionId); } else { throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.SecondFactorCodeIncorrect); } return(Ok()); } catch (ApiException e) { switch (e.StatusCode) { case HttpStatusCode.BadRequest: throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.TwoFactorRequired); case HttpStatusCode.Forbidden: throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.SecondFactorCheckForbiden); } throw; } }