Example #1
0
def get_token():
    token_schema = Token.from_json(json.loads(request.data.decode('utf-8')))
    app = App.verify_auth_token(token_schema.data['secret'])

    if not app or app.secret != token_schema.data['secret']:
        return {}, 400

    user = User.query.filter_by(email=token_schema.data['email']).first()
    if user and user.verify_password(token_schema.data['password']):
        token = Token.query.filter(Token.app_id == app.id,
                                   Token.user_id == user.id).first()
        if not token:
            token = Token(app_id=app.id, user_id=user.id)

        db.session.add(token)
        db.session.commit()

        token.token = token.generate_auth_token()

        db.session.add(token)
        db.session.commit()

        return {'token': token.token}, 200

    return {}, 400
Example #2
0
    def get_token(self, app, user, expires_in=60):
        token = Token(app=app, user=user)

        db.session.add(token)
        db.session.commit()

        token.token = token.generate_auth_token(expires_in=expires_in)

        db.session.add(token)
        db.session.commit()

        return token.token
Example #3
0
def get_token():
    token_schema = Token.from_json(json.loads(request.data.decode('utf-8')))
    app = App.verify_auth_token(token_schema.data['secret'])

    if not app or app.secret != token_schema.data['secret']:
        return {}, 400

    user = User.query.filter_by(email=token_schema.data['email']).first()
    if user and user.verify_password(token_schema.data['password']):
        token = Token.query.filter(Token.app_id == app.id, Token.user_id == user.id).first()
        if not token:
            token = Token(app_id=app.id, user_id=user.id)

        db.session.add(token)
        db.session.commit()

        token.token = token.generate_auth_token()

        db.session.add(token)
        db.session.commit()

        return {'token': token.token}, 200

    return {}, 400