Python flask_login.current_user.role() Examples
The following are 22
code examples of flask_login.current_user.role().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_login.current_user
, or try the search function
.
Example #1
Source File: permissions.py From gitmark with GNU General Public License v2.0 | 8 votes |
def on_identity_loaded(sender, identity): # Set the identity user object identity.user = current_user # Add the UserNeed to the identity if hasattr(current_user, 'username'): identity.provides.add(UserNeed(current_user.username)) # Assuming the User model has a list of roles, update the # identity with the roles that the user provides if hasattr(current_user, 'role'): # for role in current_user.roles: identity.provides.add(RoleNeed(current_user.role)) # if current_user.is_superuser: if hasattr(current_user, 'is_superuser') and current_user.is_superuser: identity.provides.add(su_need) # return current_user.role identity.allow_su = su_permission.allows(identity) identity.allow_admin = admin_permission.allows(identity) identity.allow_edit = editor_permission.allows(identity) identity.allow_general = general_permission.allows(identity)
Example #2
Source File: test_admin.py From arch-security-tracker with MIT License | 6 votes |
def test_create_user(db, client): role = UserRole.security_team resp = client.post(url_for('tracker.create_user'), follow_redirects=True, data=dict(username=USERNAME, password=PASSWORD, email=EMAIL, active=True, role=role.name)) assert resp.status_code == 200 resp = client.post(url_for('tracker.logout'), follow_redirects=True) assert_not_logged_in(resp) resp = client.post(url_for('tracker.login'), follow_redirects=True, data=dict(username=USERNAME, password=PASSWORD)) assert_logged_in(resp) assert USERNAME == current_user.name assert EMAIL == current_user.email assert role == current_user.role
Example #3
Source File: test_admin.py From arch-security-tracker with MIT License | 6 votes |
def test_edit_user(db, client): new_password = random_string() new_email = '{}foo'.format(EMAIL) new_role = UserRole.security_team resp = client.post(url_for('tracker.edit_user', username=USERNAME), follow_redirects=True, data=dict(username=USERNAME, email=new_email, password=new_password, role=new_role.name, active=True)) assert resp.status_code == 200 resp = client.post(url_for('tracker.logout'), follow_redirects=True) assert_not_logged_in(resp) resp = client.post(url_for('tracker.login'), follow_redirects=True, data={'username': USERNAME, 'password': new_password}) assert_logged_in(resp) assert USERNAME == current_user.name assert new_email == current_user.email assert new_role == current_user.role
Example #4
Source File: decorators.py From job-web-demo with MIT License | 5 votes |
def role_required(role): def decorator(func): @wraps(func) def wrapper(*args, **kwargs): if not current_user.is_authenticated or current_user.role < role: abort(404) return func(*args, **kwargs) return wrapper return decorator
Example #5
Source File: views.py From flask-app-blueprint with MIT License | 5 votes |
def admin_dashboard(): if current_user.role != 'admin': abort(403) else: users = User.query.order_by(User.id).all() kpi_mau = User.query.filter(User.last_logged_in > (datetime.today() - timedelta(days=30))).count() kpi_total_confirmed = User.query.filter_by(email_confirmed=True).count() kpi_mau_percentage = (100 / kpi_total_confirmed) * kpi_mau return render_template('admin_dashboard.html', users=users, kpi_mau=kpi_mau, kpi_total_confirmed=kpi_total_confirmed, kpi_mau_percentage=kpi_mau_percentage)
Example #6
Source File: views.py From flask-app-blueprint with MIT License | 5 votes |
def admin_view_users(): if current_user.role != 'admin': abort(403) else: users = User.query.order_by(User.id).all() return render_template('admin_view_users.html', users=users)
Example #7
Source File: role.py From walle-web with Apache License 2.0 | 5 votes |
def compare_role(self, role_low, role_high): if not isinstance(role_high, (list, tuple)): role_high = [role_high] if role_low not in ROLE_ACCESS: return False for role in role_high: if role not in ROLE_ACCESS: continue if ROLE_ACCESS[role] > ROLE_ACCESS[role_low]: return True return False
Example #8
Source File: role.py From walle-web with Apache License 2.0 | 5 votes |
def role_upper(self, role_standard, role_upper=None): ''' 当前角色 > 数据项角色 :param role: :return: ''' if current_user.role == SUPER: return True current_role = session['space_info']['role'] return self.compare_role(role_standard, [current_role, role_upper])
Example #9
Source File: role.py From walle-web with Apache License 2.0 | 5 votes |
def role_upper_developer(self, role=None): ''' 项目project的角色role比developer级别更高, 传参, 不传则 空间space的角色role比developer级别更高, 不用传, 默认从session中取 :param role: :return: ''' return self.role_upper(DEVELOPER, role)
Example #10
Source File: role.py From walle-web with Apache License 2.0 | 5 votes |
def role_upper_master(self, role=None): ''' 项目project的角色role比developer级别更高, 传参, 不传则 空间space的角色role比developer级别更高, 不用传, 默认从session中取 :param role: :return: ''' return self.role_upper(MASTER, role)
Example #11
Source File: role.py From walle-web with Apache License 2.0 | 5 votes |
def role_upper_owner(self, role=None): ''' 项目project的角色role比developer级别更高, 传参, 不传则 空间space的角色role比developer级别更高, 不用传, 默认从session中取 :param role: :return: ''' return self.role_upper(OWNER, role)
Example #12
Source File: api.py From walle-web with Apache License 2.0 | 5 votes |
def get(self): """ fetch role list or one role :return: """ return 'walle-web 2.0'
Example #13
Source File: api.py From walle-web with Apache License 2.0 | 5 votes |
def __init__(self): if current_user.is_authenticated: current_user.fresh_session() self.space_id = None if current_user.role == SUPER else session['space_id'] # @login_required
Example #14
Source File: web.py From calibre-web with GNU General Public License v3.0 | 5 votes |
def admin_required(f): """ Checks if current_user.role == 1 """ @wraps(f) def inner(*args, **kwargs): if current_user.role_admin(): return f(*args, **kwargs) abort(403) return inner
Example #15
Source File: user.py From arch-security-tracker with MIT License | 5 votes |
def user_can_watch_user_log(): return current_user.role.is_reporter
Example #16
Source File: user.py From arch-security-tracker with MIT License | 5 votes |
def user_can_delete_issue(advisories=[]): role = current_user.role if not role.is_reporter: return False return 0 == len(advisories)
Example #17
Source File: user.py From arch-security-tracker with MIT License | 5 votes |
def user_can_edit_issue(advisories=[]): role = current_user.role if not role.is_reporter: return False if role.is_security_team: return True return 0 == len(advisories)
Example #18
Source File: user.py From arch-security-tracker with MIT License | 5 votes |
def permission_required(permission): def decorator(func): @wraps(func) def decorated_view(*args, **kwargs): if not permission.fget(current_user.role): from tracker.view.error import forbidden return forbidden() return func(*args, **kwargs) return login_required(decorated_view) return decorator
Example #19
Source File: views.py From incepiton-mysql with MIT License | 5 votes |
def dashboard(): if current_user.role == 'dev': return redirect(url_for('dev.dev_chart', days=7)) else: return render_template('main/dashboard.html')
Example #20
Source File: web.py From calibre-web with GNU General Public License v3.0 | 5 votes |
def unconfigured(f): """ Checks if current_user.role == 1 """ @wraps(f) def inner(*args, **kwargs): if not config.db_configured: return f(*args, **kwargs) abort(403) return inner
Example #21
Source File: __init__.py From incepiton-mysql with MIT License | 4 votes |
def create_app(config_name): """ application initialization :param config_name: :return: """ app = Flask(__name__) app.config.from_object(config[config_name]) mail.init_app(app) db.init_app(app) login_manager.init_app(app) ldap.init_app(app) # flask_principal principals.init_app(app) @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): identity.user = current_user if hasattr(current_user, 'id'): identity.provides.add(UserNeed(current_user.id)) if hasattr(current_user, 'role'): identity.provides.add(RoleNeed(current_user.role)) # celery celery.init_app(app) # register blue_print from .auth import auth as auth_blueprint app.register_blueprint(auth_blueprint, url_prefix='/auth') from .main import main as main_blueprint app.register_blueprint(main_blueprint) from .admin import admin as admin_blueprint app.register_blueprint(admin_blueprint) from .audit import audit as audit_blueprint app.register_blueprint(audit_blueprint) from .dev import dev as dev_blueprint app.register_blueprint(dev_blueprint) return app
Example #22
Source File: web.py From calibre-web with GNU General Public License v3.0 | 4 votes |
def register(): if not config.config_public_reg: abort(404) if current_user is not None and current_user.is_authenticated: return redirect(url_for('web.index')) if not config.get_mail_server_configured(): flash(_(u"E-Mail server is not configured, please contact your administrator!"), category="error") return render_title_template('register.html', title=_(u"register"), page="register") if request.method == "POST": to_save = request.form.to_dict() if config.config_register_email: nickname = to_save["email"] else: nickname = to_save["nickname"] if not nickname or not to_save["email"]: flash(_(u"Please fill out all fields!"), category="error") return render_title_template('register.html', title=_(u"register"), page="register") existing_user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == nickname .lower()).first() existing_email = ub.session.query(ub.User).filter(ub.User.email == to_save["email"].lower()).first() if not existing_user and not existing_email: content = ub.User() if check_valid_domain(to_save["email"]): content.nickname = nickname content.email = to_save["email"] password = generate_random_password() content.password = generate_password_hash(password) content.role = config.config_default_role content.sidebar_view = config.config_default_show try: ub.session.add(content) ub.session.commit() if feature_support['oauth']: register_user_with_oauth(content) send_registration_mail(to_save["email"], nickname, password) except Exception: ub.session.rollback() flash(_(u"An unknown error occurred. Please try again later."), category="error") return render_title_template('register.html', title=_(u"register"), page="register") else: flash(_(u"Your e-mail is not allowed to register"), category="error") log.info('Registering failed for user "%s" e-mail adress: %s', to_save['nickname'], to_save["email"]) return render_title_template('register.html', title=_(u"register"), page="register") flash(_(u"Confirmation e-mail was send to your e-mail account."), category="success") return redirect(url_for('web.login')) else: flash(_(u"This username or e-mail address is already in use."), category="error") return render_title_template('register.html', title=_(u"register"), page="register") if feature_support['oauth']: register_user_with_oauth() return render_title_template('register.html', config=config, title=_(u"register"), page="register")