Esempio n. 1
0
from flakon import JsonBlueprint
from flask import request, jsonify
from beepbeep.authservice.database import db, User
from werkzeug.security import check_password_hash

login = JsonBlueprint('login', __name__)


@login.route('/login', methods=['POST'])
def _login():

    data = request.get_json()

    if data is not None:
        email = data['email']
        password = data['password']

        if email is not None and password is not None:
            user = db.session.query(User).filter(User.email == email).first()
            if(user is not None):
                if user.password == password:
                    return jsonify(user.to_json()), 200
                return "Bad credentials", 401

    return "", 400
Esempio n. 2
0
#Edoardo Baldini id: 566186
from flakon import JsonBlueprint
from flask import request, jsonify, abort
from myservice.classes.poll import Poll, NonExistingOptionException, UserAlreadyVotedException

doodles = JsonBlueprint('doodles', __name__)

_ACTIVEPOLLS = {}  # list of created polls
_POLLNUMBER = 0  # index of the last created poll


@doodles.route('/doodles', methods=['POST', 'GET'])  #TODO: completed
def all_polls():
    if request.method == 'POST':
        result = create_doodle(request)

    elif request.method == 'GET':
        result = get_all_doodles(request)
    return result


@doodles.route('/doodles/<int:id>', methods=['PUT', 'DELETE',
                                             'GET'])  #TODO: completed
def single_poll(id):
    global _ACTIVEPOLLS
    result = ""
    exist_poll(id)  # check if the Doodle is an existing one

    if request.method == 'GET':  # retrieve a poll
        result = jsonify(_ACTIVEPOLLS[id].serialize())
Esempio n. 3
0
from flakon import JsonBlueprint
from flask import request, jsonify, abort
from myservice.classes.quiz import Quiz, Question, Answer, NonExistingAnswerError, LostQuizError, CompletedQuizError

quizzes = JsonBlueprint('quizzes', __name__)

_LOADED_QUIZZES = {}  # list of available quizzes
_QUIZNUMBER = 0  # index of the last created quizzes


@quizzes.route("/quizzes", methods=['GET', 'POST'])
def all_quizzes():
    if 'POST' == request.method:
        # Create new quiz
        try:
            result = create_quiz(request)
        except:
            # error 422: Unprocessable Entity, i.e. well-formed json but semantic errors
            abort(422)
    elif 'GET' == request.method:
        # Retrieve all loaded quizzes
        result = get_all_quizzes(request)
    return result


@quizzes.route("/quizzes/loaded", methods=['GET'])
def loaded_quizzes(
):  # returns the number of quizzes currently loaded in the system
    return {"loaded_quizzes": len(_LOADED_QUIZZES)}

Esempio n. 4
0
import time
from hmac import compare_digest
from flask import request, current_app, abort, jsonify
from werkzeug.exceptions import HTTPException
from flakon import JsonBlueprint
from flakon.util import error_handling

import jwt

home = JsonBlueprint('home', __name__)


def _400(desc):
    exc = HTTPException()
    exc.code = 400
    exc.description = desc
    return error_handling(exc)


@home.route('/.well-known/jwks.json')
def _jwks():
    """Returns the public key in the Json Web Key (JWK) format
    """
    key = {
        "alg": "RS512",
        "e": "AQAB",
        "n": current_app.config['pub_key'],
        "kty": "RSA",
        "use": "sig"
    }