public async Task <ResultFlow <IEnumerable <ApiRoleResourceRouteEntity> > > List(QueryParamValueObject <ApiRoleResourceRouteEntity> model) { try { var sql = @"SELECT * FROM api_role_resource_route INNER JOIN api_resource_route ON api_resource_route.id = api_role_resource_route.api_resource_route_id INNER JOIN api_role ON api_role.id = api_role_resource_route.api_role_id WHERE api_role.status = 1 AND api_resource_route.status = 1 AND api_role_resource_route.status = 1"; var result = await _connection.QueryAsync <ApiRoleResourceRouteEntity, ApiResourceRouteEntity, ApiRoleEntity, ApiRoleResourceRouteEntity> ( sql, (apiRoleResourceRouteEntity, apiRouteResource, apiRole) => { apiRoleResourceRouteEntity.ApiRole = apiRole; apiRoleResourceRouteEntity.ApiResourceRoute = apiRouteResource; return(apiRoleResourceRouteEntity); } ); return(ResultFlowFactory.Success <IEnumerable <ApiRoleResourceRouteEntity> > (result)); } catch { throw; } }
public async Task <ResultFlow <ApiUserEntity> > Authenticate(string email, string encryptedPassword) { try { var sql = @"SELECT api_user.id, api_user.email, api_role.id FROM api_user INNER JOIN api_role ON api_role.id = api_user.api_role_id WHERE api_user.email = LOWER(@Email) AND api_user.password = @Password AND api_user.status = 1 LIMIT 1"; var result = await _connection.QueryAsync <ApiUserEntity, ApiRoleEntity, ApiUserEntity>( sql, map : (apiUser, apiRole) => { apiUser.ApiRole = apiRole; return(apiUser); }, param : new { Email = email, Password = encryptedPassword } ); return(ResultFlowFactory.Success <ApiUserEntity>(result.FirstOrDefault())); } catch { throw; } }
public async Task <ResultFlow <string> > GetJwtToken(string email, string password, string audience) { try { var encryptedPassword = _sha256Utility.Encrypt(password); email = email.ToLower(); var authenticateResultFlow = await _apiUserRepository.Authenticate(email, encryptedPassword); if (authenticateResultFlow.IsSuccess() && authenticateResultFlow.Result == null) { return(ResultFlowFactory.Exception <string>("Invalid credentials")); } var apiUser = authenticateResultFlow.Result; var token = _jwtUtility.EncodeJwt( Configuration.GetSection("Server:Jwt:SecretKey").Value, audience, apiUser.Id.ToString(), apiUser.ApiRole.Id.ToString(), apiUser.Email, Convert.ToInt32(Configuration.GetSection("Server:Jwt:DaysToExpire").Value) ); return(ResultFlowFactory.Success <string>(token.RawData)); } catch { throw; } }
public async Task <ResultFlow <ApiUserEntity> > Read(ApiUserEntity model) { try { var readResultFlow = await _apiUserLogic.Read(model); if (readResultFlow.IsException()) { return(ResultFlowFactory.Exception <ApiUserEntity>(readResultFlow.Message)); } return(ResultFlowFactory.Success <ApiUserEntity>(readResultFlow.Result)); } catch { throw; } }
public async Task <ResultFlow <string> > Authenticate(string email, string password, string audience) { try { var getJwtTokenResultFlow = await _apiUserLogic.GetJwtToken(email, password, audience); if (getJwtTokenResultFlow.IsException()) { return(ResultFlowFactory.Exception <string>(getJwtTokenResultFlow.Message)); } return(ResultFlowFactory.Success <string>(getJwtTokenResultFlow.Result)); } catch { throw; } }
public async Task <ResultFlow <ApiUserEntity> > Read(ApiUserEntity model) { try { var readResultFlow = await _apiUserRepository.Read(model); if (readResultFlow.IsSuccess() && readResultFlow.Result == null) { return(ResultFlowFactory.Exception <ApiUserEntity>("Api user not found")); } return(ResultFlowFactory.Success <ApiUserEntity>(readResultFlow.Result)); } catch { throw; } }
public async Task <ResultFlow <IEnumerable <ApiResourceRouteEntity> > > List(QueryParamValueObject <ApiResourceRouteEntity> model) { try { var listResultFlow = await _apiResourceRouteRepository.List(model); if (listResultFlow.IsException()) { return(ResultFlowFactory.Exception <IEnumerable <ApiResourceRouteEntity> >(listResultFlow.Message)); } return(ResultFlowFactory.Success <IEnumerable <ApiResourceRouteEntity> >(listResultFlow.Result)); } catch { throw; } }
public async Task <ResultFlow <ApiUserEntity> > Read(ApiUserEntity model) { try { var sql = @"SELECT * FROM api_user WHERE id = @Id"; var result = await _connection.QueryAsync <ApiUserEntity>( sql, param : new { Id = model.Id } ); return(ResultFlowFactory.Success <ApiUserEntity>(result.FirstOrDefault())); } catch { throw; } }