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 import Resource
|
||||||
from flask_restful.reqparse import RequestParser
|
from flask_restful.reqparse import RequestParser
|
||||||
|
|
||||||
|
from app.core import cas
|
||||||
from app.model import *
|
from app.model import *
|
||||||
|
|
||||||
|
|
||||||
@ -10,13 +11,8 @@ class LoginAPI(Resource):
|
|||||||
Login Api Resource
|
Login Api Resource
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def post(self):
|
def get(self):
|
||||||
parser = RequestParser()
|
userInfo = self.getUserInfoFromCAS()
|
||||||
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'])
|
|
||||||
|
|
||||||
if userInfo is not None:
|
if userInfo is not None:
|
||||||
user = getUser(login=userInfo['login'])
|
user = getUser(login=userInfo['login'])
|
||||||
@ -32,9 +28,8 @@ class LoginAPI(Resource):
|
|||||||
session['user'] = None
|
session['user'] = None
|
||||||
return {'AUTH_RESULT': 'OK'}, 200
|
return {'AUTH_RESULT': 'OK'}, 200
|
||||||
|
|
||||||
def getUserInfoFromCAS(self, login, password):
|
def getUserInfoFromCAS(self):
|
||||||
# TODO : A implémenter
|
if cas.username is not None:
|
||||||
if (login == "admin" or login == "toto") and password == login:
|
return {"login": cas.username}
|
||||||
return {"login": login}
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
@ -26,6 +26,12 @@ class Config:
|
|||||||
BUNDLE_ERRORS = True
|
BUNDLE_ERRORS = True
|
||||||
SESSION_COOKIE_SECURE = True
|
SESSION_COOKIE_SECURE = True
|
||||||
SESSION_VALIDITY_DURATION_WITHOUT_ACTIVITY_MIN = 20
|
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):
|
class Prod(Config):
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import importlib
|
import importlib
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from flask_cas import CAS
|
||||||
|
|
||||||
from app.config import Config
|
from app.config import Config
|
||||||
from flask import Flask, session
|
from flask import Flask, session, redirect
|
||||||
from flask_restful import Api
|
from flask_restful import Api
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
from sqlalchemy import MetaData
|
from sqlalchemy import MetaData
|
||||||
@ -32,5 +34,12 @@ meta = MetaData(engine, True)
|
|||||||
# RestFul Flask
|
# RestFul Flask
|
||||||
api = Api(app)
|
api = Api(app)
|
||||||
|
|
||||||
|
# Cas Flask
|
||||||
|
cas = CAS(app)
|
||||||
|
|
||||||
|
@app.route('/redirect')
|
||||||
|
def after_login():
|
||||||
|
return redirect("/api/login")
|
||||||
|
|
||||||
# import api resources
|
# import api resources
|
||||||
importlib.import_module("app.urls")
|
importlib.import_module("app.urls")
|
||||||
|
@ -4,4 +4,4 @@ from app.core import api
|
|||||||
|
|
||||||
# Some Api resource
|
# Some Api resource
|
||||||
api.add_resource(SomeApi, '/api/someapi', '/api/someapi/<int:id>')
|
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