TG-33 gestion login cas
This commit is contained in:
parent
faebce28a2
commit
4223964b8a
@ -2,6 +2,7 @@ from flask import session
|
||||
from flask_restful import Resource
|
||||
from flask_restful.reqparse import RequestParser
|
||||
|
||||
from app.core import cas
|
||||
from app.model import *
|
||||
|
||||
|
||||
@ -10,13 +11,8 @@ class LoginAPI(Resource):
|
||||
Login Api Resource
|
||||
"""
|
||||
|
||||
def post(self):
|
||||
parser = RequestParser()
|
||||
parser.add_argument('login', required=True, help="Login cannot be blank!")
|
||||
parser.add_argument('password', required=True, help="Password cannot be blank!")
|
||||
args = parser.parse_args()
|
||||
|
||||
userInfo = self.getUserInfoFromCAS(args['login'], args['password'])
|
||||
def get(self):
|
||||
userInfo = self.getUserInfoFromCAS()
|
||||
|
||||
if userInfo is not None:
|
||||
user = getUser(login=userInfo['login'])
|
||||
@ -32,9 +28,8 @@ class LoginAPI(Resource):
|
||||
session['user'] = None
|
||||
return {'AUTH_RESULT': 'OK'}, 200
|
||||
|
||||
def getUserInfoFromCAS(self, login, password):
|
||||
# TODO : A implémenter
|
||||
if (login == "admin" or login == "toto") and password == login:
|
||||
return {"login": login}
|
||||
def getUserInfoFromCAS(self):
|
||||
if cas.username is not None:
|
||||
return {"login": cas.username}
|
||||
else:
|
||||
return None
|
||||
|
@ -26,6 +26,12 @@ class Config:
|
||||
BUNDLE_ERRORS = True
|
||||
SESSION_COOKIE_SECURE = True
|
||||
SESSION_VALIDITY_DURATION_WITHOUT_ACTIVITY_MIN = 20
|
||||
CAS_SERVER = "http://localhost:8088"
|
||||
CAS_AFTER_LOGIN = "after_login"
|
||||
CAS_LOGIN_ROUTE = "/login"
|
||||
CAS_LOGOUT_ROUTE = "/logout"
|
||||
CAS_VALIDATE_ROUTE = "/serviceValidate"
|
||||
|
||||
|
||||
|
||||
class Prod(Config):
|
||||
|
@ -1,8 +1,10 @@
|
||||
import importlib
|
||||
from datetime import timedelta
|
||||
|
||||
from flask_cas import CAS
|
||||
|
||||
from app.config import Config
|
||||
from flask import Flask, session
|
||||
from flask import Flask, session, redirect
|
||||
from flask_restful import Api
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from sqlalchemy import MetaData
|
||||
@ -32,5 +34,12 @@ meta = MetaData(engine, True)
|
||||
# RestFul Flask
|
||||
api = Api(app)
|
||||
|
||||
# Cas Flask
|
||||
cas = CAS(app)
|
||||
|
||||
@app.route('/redirect')
|
||||
def after_login():
|
||||
return redirect("/api/login")
|
||||
|
||||
# import api resources
|
||||
importlib.import_module("app.urls")
|
||||
|
@ -4,4 +4,4 @@ from app.core import api
|
||||
|
||||
# Some Api resource
|
||||
api.add_resource(SomeApi, '/api/someapi', '/api/someapi/<int:id>')
|
||||
api.add_resource(LoginAPI, '/api/login', '/api/login')
|
||||
api.add_resource(LoginAPI, '/api/login')
|
||||
|
Reference in New Issue
Block a user