import json

from flask import Blueprint, request
from flask.ext.login import current_user, logout_user, login_user
from flask.ext.restful import Api, Resource, abort

from server.models import Lecturer, db


auth = Blueprint('auth', __name__)
api = Api(auth)


class LoginResource(Resource):
    def get(self):
        if current_user.is_active:
            return {'username': current_user.full_name}
        else:
            abort(403, message="The user is not logged in")

    def post(self):
        email = request.form['email']
        password = request.form['password']
        user = (
            db.session.query(Lecturer)
            .filter(Lecturer.email == email)
            .filter(Lecturer.password == password)
            .first()
        )
        if not user:
            abort(403, message="Invalid credentials")
        login_user(user)
        return {'username': current_user.full_name}


class LogoutResource(Resource):
    def post(self):
        logout_user()
        return '', 204

api.add_resource(LoginResource, '/login')
api.add_resource(LogoutResource, '/logout')

@@ -159,16 +159,26 @@
 e, abort
+, reqparse
 %0A%0Afrom s
@@ -513,79 +513,256 @@
     
-email = request.form%5B'email'%5D%0A        password = request.form%5B'
+argparser = reqparse.RequestParser()%0A        argparser.add_argument('email', required=True)%0A        argparser.add_argument('password', required=True)%0A        args = argparser.parse_args()%0A%0A        email = args.email%0A        password = args.
 password
 '%5D%0A 
@@ -761,10 +761,8 @@
 word
-'%5D
 %0A   

Fix Login API implementation not parsing JSON POST data