Last active
April 1, 2020 22:57
-
-
Save Xarthisius/25b7c271b438ee5332be2c7618f94b3c to your computer and use it in GitHub Desktop.
[girder] Enforcing admin approval for OAuth
This file contains 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 girder.exceptions import AccessException | |
from girder.models.user import User | |
from girder import events | |
def enforce_policy(event): | |
user = event.info["user"] | |
# This has the same behavior as User.canLogin, but returns more | |
# detailed error messages | |
if user.get("status", "enabled") == "disabled": | |
raise AccessException("Account is disabled.", extra="disabled") | |
if User().emailVerificationRequired(user): | |
raise AccessException("Email verification required.", extra="emailVerification") | |
if User().adminApprovalRequired(user): | |
raise AccessException("Account approval required.", extra="accountApproval") | |
def load(info): | |
events.bind("oauth.auth_callback.after", "your_plugin_name", enforce_policy) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment