Beispiel #1
0
 def post(self, **kwargs):
     """Creates next week crowd forecast"""
     if FLASK_ENV == 'development':
         try:
             return jsonify(
                 SuccessObject.create_response(
                     self, HTTPStatus.OK,
                     _ForecastService.create_next_week_prediction(
                         self,
                         start_date=request.args.get('start_date'),
                         number_of_weeks_to_use=request.args.get(
                             'number_of_weeks'),
                         use_start_of_the_week=request.args.get(
                             'use_start_of_the_week'))))
         except Exception as err:
             if (len(err.args) == 1):
                 return ErrorObject.create_response(self,
                                                    HTTPStatus.BAD_REQUEST,
                                                    str(err))
             else:
                 return ErrorObject.create_response(self, err.args[0],
                                                    err.args[1])
     else:
         return ErrorObject.create_response(self, HTTPStatus.NOT_FOUND,
                                            HTTPStatus.NOT_FOUND.phrase)
 def custom_unauthorized_loader(self):
     from api.helpers import ErrorObject
     if 'CSRF' in self:
         return ErrorObject.create_response(self, HTTPStatus.BAD_REQUEST,
                                            'CSRF token missing')
     else:
         return ErrorObject.create_response(self, HTTPStatus.UNAUTHORIZED,
                                            'Access token missing')
Beispiel #3
0
def handle_authorize(remote, token, user_info):
    user = None
    try:
        user = _UserService.get_user_by_email(_UserService, user_info['email'])
        user = dict_to_model(User, user)
        user.last_login_date = to_utc_datetime()
        user.save()
        user = model_to_dict(user)
    except BaseException:
        pass
    try:
        if user is None:
            user = _UserService.create_user(_UserService,
                                            email=user_info['email'])

        identity_object = {
            "is_user_token": True,
            "email": user_info['email'],
            "acces_token": token['access_token'],
            "user": user
        }
        access_token = create_access_token(identity=identity_object)
        response = make_response(redirect('/'))
        session["user"] = user
        print(session["user"])
        set_access_cookies(response, access_token)

        return response
    except Exception as err:
        return ErrorObject.create_response(_UserService, err.args[0],
                                           err.args[1])
Beispiel #4
0
 def post(self, token_id: int):
     """Deactivates a specific data source token"""
     token = get_jwt_identity()
     if token['user']['id'] == 1:
         try:
             return jsonify(
                 SuccessObject.create_response(
                     self, HTTPStatus.OK,
                     _DataSourceTokenService.admin_revoke_token(
                         self, token_id)))
         except Exception as err:
             return ErrorObject.create_response(self, err.args[0],
                                                err.args[1])
     else:
         return ErrorObject.create_response(
             self, HTTPStatus.FORBIDDEN,
             "You are unable to access this endpoint.")
Beispiel #5
0
 def get(self, name: str):
     """Retrieves user by username"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _UserService.get_user_by_username(self, name)))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
 def get(self):
     """Fetches all data sources"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _data_source_service.get_all_data_sources(self), True))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Beispiel #7
0
 def get(self, name: str):
     """Retrieves data sources created by user"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _UserService.get_data_source_by_user(self, username=name)))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Beispiel #8
0
 def get(self, data_id):
     """Fetch a single data point"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _DataSourceDataService.get_one_data_point(self, data_id)))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
 def get(self, data_source_id):
     """Fetch a single data source"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _data_source_service.get_data_source_by_id(
                     self, data_source_id)))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
 def post(self, **kwargs):
     """Creates a new data source"""
     token = get_jwt_identity()
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _data_source_service.add_data_source(
                     self, kwargs['tupled_output'], token['user']['id'])))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Beispiel #11
0
 def post(self, token_id: int):
     """Deactivates a specific data source token"""
     token = get_jwt_identity()
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _UserService.deactivate_token_of_user(
                     self, token['user']['id'], token_id)))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Beispiel #12
0
 def post(self):
     """Sets the username of the logged in user"""
     token = get_jwt_identity()
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _UserService.set_username(self, token['user']['id'],
                                           api.payload['username'])))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Beispiel #13
0
 def get(self):
     """Retrieves data source tokens created by the logged in user"""
     token = get_jwt_identity()
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _UserService.get_data_source_tokens_by_user(
                     self, token['user']['id'])))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Beispiel #14
0
 def get(self):
     """Retrieves the information of the logged in user"""
     token = get_jwt_identity()
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _UserService.get_user_by_id(self, token['user']['id'],
                                             True)))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Beispiel #15
0
 def post(self, **kwargs):
     """Creates new data"""
     token = get_jwt_identity()
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _DataSourceDataService.post_data(
                     self, token['data_source_token']['data_source'],
                     kwargs['tupled_output'])))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Beispiel #16
0
 def get(self, **kwargs):
     """Retrieves crowd forecast per week"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _ForecastService.get_crowd_forecast(
                     self,
                     start_date=request.args.get('start_date'),
                     end_date=request.args.get('end_date'),
                     return_data_frame=request.args.get('get_dataframe'))))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
 def post(self, data_source_id):
     """Creates a token for data source"""
     token = get_jwt_identity()
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _data_source_token_service.create_token_for_data_source(
                     self,
                     data_source_id=data_source_id,
                     user_id=token['user']['id'])))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Beispiel #18
0
 def get(self):
     """Fetches data from all sources"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _DataSourceDataService.get_all_data(
                     self,
                     limit=request.args.get('limit'),
                     start_date=request.args.get('start_date'),
                     end_date=request.args.get('end_date'),
                     sort=request.args.get('sort')), True))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Beispiel #19
0
 def get(self):
     """Fetches all weather data"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _WeatherService.retrieve_all_weather_data(
                     self,
                     limit=request.args.get('limit'),
                     start_date=request.args.get('start_date'),
                     end_date=request.args.get('end_date'),
                     order_by=request.args.get('order_by'),
                     sort=request.args.get('sort'),
                     forecast_type=request.args.get('forecast_type')),
                 True))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Beispiel #20
0
def custom_unauthorized_loader(self):
    from api.helpers import ErrorObject
    return ErrorObject.create_response(self, HTTPStatus.UNAUTHORIZED,
                                       'No access token provided')
Beispiel #21
0
def custom_expired_token_loader(callback):
    from api.helpers import ErrorObject
    token_type = callback['type']
    return ErrorObject.create_response(
        ErrorObject, HTTPStatus.UNAUTHORIZED,
        'The {} token has expired'.format(token_type))
Beispiel #22
0
def custom_invalid_token_loader(self):
    from api.helpers import ErrorObject
    return ErrorObject.create_response(self, HTTPStatus.UNAUTHORIZED,
                                       'Invalid token provided')