Last active
February 15, 2022 16:37
-
-
Save sairamkrish/5760e3f8d388ec4dac6be05e0e9a6b42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import redirect, g, flash, request | |
from flask_appbuilder.security.views import UserDBModelView,AuthDBView | |
from superset.security import SupersetSecurityManager | |
from flask_appbuilder.security.views import expose | |
from flask_appbuilder.security.manager import BaseSecurityManager | |
from flask_login import login_user, logout_user | |
class CustomAuthDBView(AuthDBView): | |
login_template = 'appbuilder/general/security/login_db.html' | |
@expose('/login/', methods=['GET', 'POST']) | |
def login(self): | |
redirect_url = self.appbuilder.get_url_for_index | |
if request.args.get('redirect') is not None: | |
redirect_url = request.args.get('redirect') | |
if request.args.get('username') is not None: | |
user = self.appbuilder.sm.find_user(username=request.args.get('username')) | |
login_user(user, remember=False) | |
return redirect(redirect_url) | |
elif g.user is not None and g.user.is_authenticated(): | |
return redirect(redirect_url) | |
else: | |
flash('Unable to auto login', 'warning') | |
return super(CustomAuthDBView,self).login() | |
class CustomSecurityManager(SupersetSecurityManager): | |
authdbview = CustomAuthDBView | |
def __init__(self, appbuilder): | |
super(CustomSecurityManager, self).__init__(appbuilder) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why we are not checking 'password' in this code?