コード例 #1
0
ファイル: routes.py プロジェクト: maan-git/tts
def register_users(request):
    users = request.json_body.get("users", "user was not provided")

    _user_controller = UserController.user_controller()
    _user_controller.register_users(users)

    return {"data": request.json_body.get("users", "user was not provided")}
コード例 #2
0
class UserCollection(Resource):
    def __init__(self, api=None, *args, **kwargs):
        super(UserCollection, self).__init__(api, args, kwargs)
        self.user = UserController()

    @api.expect(user_serializer)
    def post(self):
        data = request.json
        return self.user.add_user(email=data.get("email"),
                                  password=data.get("password"),
                                  cpf=data.get("cpf"))
コード例 #3
0
def decode_auth_token(auth_token):
    try:
        payload = jwt.decode(auth_token, key)
        valid_token = UserController().check_auth_token(auth_token=auth_token)
        if valid_token:
            return payload["sub"]
        else:
            return "Token invalid, please log in again"
    except jwt.ExpiredSignatureError:
        return "Signatue invalid, please log in again"
    except jwt.InvalidTokenError:
        return "Invalid token, please log in again"
コード例 #4
0
 def __init__(self, api=None, *args, **kwargs):
     super(UserCollection, self).__init__(api, args, kwargs)
     self.user = UserController()
コード例 #5
0
def init_app(config) -> web.Application:
    # db pool
    db_config = {
        'database': config['db']['database'],
        'user': config['db']['user'],
        'password': config['db']['password'],
        'host': config['db']['host'],
        'port': config['db']['port'],
    }
    time.sleep(10)
    pool = Pool(db_config)

    # components
    repos = {
        'article_repository': ArticleRepository(pool),
        'user_repository': UserRepository(pool)
    }

    # To make sure that we are connected to db
    repos['article_repository'].now()

    searcher = HackerNewsSearcher()
    services = {
        'user_service': UserService(repos['user_repository']),
        'hacker_news_searcher': searcher,
        'article_service': ArticleService(repos['article_repository'],
                                          searcher),
        'token_service': TokenService(config, repos['user_repository'])
    }

    controllers = {
        'auth_controller':
        AuthController(services['user_service'], services['token_service'],
                       config['fe_redirect']),
        'article_controller':
        ArticleController(services['article_service']),
        'user_controller':
        UserController()
    }

    # web configuration
    app = web.Application(middlewares=[auth_middleware])
    app['config'] = config

    # setup routes
    app.add_routes([
        web.post('/users/authenticate', controllers['auth_controller'].auth),
        web.post('/users/register', controllers['auth_controller'].signin),
        web.get('/users/githubsso', controllers['auth_controller'].githubsso),
        web.get('/articles', controllers['article_controller'].get_all),
        web.post('/articles', controllers['article_controller'].find_article),
        web.delete('/articles',
                   controllers['article_controller'].remove_article_by_id)
    ])
    # cors
    cors = aiohttp_cors.setup(app,
                              defaults={
                                  '*':
                                  aiohttp_cors.ResourceOptions(
                                      allow_credentials=True,
                                      expose_headers="*",
                                      allow_headers="*",
                                  )
                              })

    # Configure CORS on all routes.
    for route in list(app.router.routes()):
        cors.add(route)

    # security
    setup_security(app, JWTIdentityPolicy(secret=config['secret']),
                   PyFeedsAuthorizationPolicy(services['user_service']))

    return app
コード例 #6
0
""" Routes file."""
from flask import Flask
from flask_jwt_extended import create_access_token, JWTManager, jwt_required, get_jwt_identity
from app.controller.incident_controller import IncidentController
from app.controller.user_controller import UserController

# create app
app = Flask(__name__)
jwt = JWTManager(app)

# app.config['JWT_SECRET_KEY'] = 'IAM-the-Greatest-Coder-Ever!'
app.config['JWT_SECRET_KEY'] = 'Zoe'

incendent_controller = IncidentController()
my_user = UserController()


@app.route('/api/v1/')
def home():
    """ This is the index route."""
    return incendent_controller.index()


@app.route('/api/v1/red-flags', methods=['POST'])
# @jwt_required
def create_redflag():
    """ Route to create an incident. Specifically for now
        a red flag. """
    return incendent_controller.add_incident()

コード例 #7
0
ファイル: routes.py プロジェクト: maan-git/tts
def pic_user(request):
    _user_controller = UserController.user_controller()
    res = _user_controller.pic_user()

    return {"data": res}