本文整理汇总了Python中flask_principal.identity_changed.send方法的典型用法代码示例。如果您正苦于以下问题:Python identity_changed.send方法的具体用法?Python identity_changed.send怎么用?Python identity_changed.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_principal.identity_changed
的用法示例。
在下文中一共展示了identity_changed.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: common_login
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def common_login(user_uuid, permanent_session=True):
"""
Performs login of the given user, with optional non-permanence on the session.
Returns a tuple with (success, headers to set on success).
"""
user = model.get_user(user_uuid)
if user is None:
return (False, None)
if login_user(LoginWrappedDBUser(user_uuid)):
logger.debug("Successfully signed in as user %s with uuid %s", user.username, user_uuid)
new_identity = QuayDeferredPermissionUser.for_id(user_uuid)
identity_changed.send(app, identity=new_identity)
session["login_time"] = datetime.datetime.now()
if permanent_session and features.PERMANENT_SESSIONS:
session_timeout_str = app.config.get("SESSION_TIMEOUT", "31d")
session.permanent = True
session.permanent_session_lifetime = convert_to_timedelta(session_timeout_str)
# Force a new CSRF token.
headers = {}
headers[QUAY_CSRF_UPDATED_HEADER_NAME] = generate_csrf_token(force=True)
return (True, headers)
logger.debug("User could not be logged in, inactive?")
return (False, None)
示例2: default_unauthn_handler
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def default_unauthn_handler(mechanisms, headers=None):
""" Default callback for failures to authenticate
If caller wants JSON - return 401
Otherwise - assume caller is html and redirect if possible to a login view.
We let Flask-Login handle this.
"""
msg = get_message("UNAUTHENTICATED")[0]
if config_value("BACKWARDS_COMPAT_UNAUTHN"):
return _get_unauthenticated_response(headers=headers)
if _security._want_json(request):
# Ignore headers since today, the only thing in there might be WWW-Authenticate
# and we never want to send that in a JSON response (browsers will intercept
# that and pop up their own login form).
payload = json_error_response(errors=msg)
return _security._render_json(payload, 401, None, None)
return _security.login_manager.unauthorized()
示例3: _check_token
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def _check_token():
# N.B. this isn't great Flask-Login 0.5.0 made this protected
# Issue https://github.com/maxcountryman/flask-login/issues/471
# was filed to restore public access. We want to call this via
# login_manager in case someone has overridden the login_manager which we
# allow.
if hasattr(_security.login_manager, "request_callback"):
# Pre 0.5.0
user = _security.login_manager.request_callback(request)
else:
user = _security.login_manager._request_callback(request)
if user and user.is_authenticated:
app = current_app._get_current_object()
_request_ctx_stack.top.user = user
identity_changed.send(app, identity=Identity(user.fs_uniquifier))
return True
return False
示例4: configure_auth
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def configure_auth():
from zou.app.services import persons_service
@jwt.token_in_blacklist_loader
def check_if_token_is_revoked(decrypted_token):
return auth_tokens_store.is_revoked(decrypted_token)
@jwt.user_loader_callback_loader
def add_permissions(callback):
try:
user = persons_service.get_current_user()
if user is not None:
identity_changed.send(
current_app._get_current_object(),
identity=Identity(user["id"]),
)
return user
except PersonNotFoundException:
return None
示例5: login
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def login():
"""GET|POST /login: login form handler
"""
form = LoginForm()
if form.validate_on_submit():
# login user
u = User.query.filter(User.email == form.email.data).first()
login_user(u, remember=form.remember_me.data)
# tell flask-principal the identity changed
identity_changed.send(current_app._get_current_object(),
identity=Identity(u.id))
return redirect(request.args.get('next') or url_for('content.home'))
return render_template('/auth/login.html', form=form)
示例6: create_account
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def create_account():
"""GET|POST /create-account: create account form handler
"""
form = CreateAccountForm()
if form.validate_on_submit():
# add user to database
u = User(email=form.email.data,
password=generate_password_hash(form.password.data))
db.session.add(u)
db.session.flush()
# send verification email
send_verification_email(u)
# login user
login_user(u, remember=True)
identity_changed.send(current_app._get_current_object(),
identity=Identity(u.id))
return redirect(request.args.get('next') or url_for('content.home'))
return render_template('/auth/create-account.html', form=form)
示例7: updateBoxrouterData
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def updateBoxrouterData(self, data):
if self.cloud_enabled():
try:
if data:
r = requests.put("%s/astrobox/%s/update-boxrouter-data" % (self.apiHost, self.boxId),
data=json.dumps(data),
auth=self.hmacAuth,
headers={'Content-Type': 'application/json'}
)
if r.status_code == 200:
return r.json()
if r.status_code == 400:
self._logger.error("Bad updateBoxrouterData request (400). Response: %s" % r.text)
if r.status_code == 404:
self._logger.error("Request updateBoxrouterData not found (404). Response: %s" % r.text)
except Exception as e:
self._logger.error("Failed to send updateBoxrouterData request: %s" % e)
return False
示例8: updateCancelReason
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def updateCancelReason(self, printJobId, reason):
if (self.cloud_enabled()):
try:
r = requests.put("%s/printjobs/%s/add-reason" % (self.apiHost, printJobId),
data=json.dumps(reason),
auth=self.hmacAuth,
headers={'Content-Type': 'application/json'}
)
if r.status_code == 200:
return True
if r.status_code == 400:
self._logger.error("Unable to do updateCancelReason (400). Response: %s" % r.text)
else:
self._logger.error("updateCancelReason request failed with status: %d" % r.status_code)
except Exception as e:
self._logger.error("Failed to send updateCancelReason request: %s" % e)
return False
示例9: change_password
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def change_password(self, user, password, send_email=None):
"""
Service method to change a user's password.
Sends signal `password_changed`.
:param user: The :class:`User`'s password to change.
:param password: The new password.
:param send_email: Whether or not to override the config option
``SECURITY_SEND_PASSWORD_CHANGED_EMAIL`` and force
either sending or not sending an email.
"""
user.password = password
self.user_manager.save(user)
if send_email or (app.config.SECURITY_SEND_PASSWORD_CHANGED_EMAIL
and send_email is None):
self.send_mail(
_('flask_unchained.bundles.security:email_subject.password_changed_notice'),
to=user.email,
template='security/email/password_changed_notice.html',
user=user)
password_changed.send(app._get_current_object(), user=user)
示例10: reset_password
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def reset_password(self, user, password):
"""
Service method to reset a user's password. The same as :meth:`change_password`
except we this method sends a different notification email.
Sends signal `password_reset`.
:param user:
:param password:
:return:
"""
user.password = password
self.user_manager.save(user)
if app.config.SECURITY_SEND_PASSWORD_RESET_NOTICE_EMAIL:
self.send_mail(
_('flask_unchained.bundles.security:email_subject.password_reset_notice'),
to=user.email,
template='security/email/password_reset_notice.html',
user=user)
password_reset.send(app._get_current_object(), user=user)
示例11: send_reset_password_instructions
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def send_reset_password_instructions(self, user):
"""
Sends the reset password instructions email for the specified user.
Sends signal `reset_password_instructions_sent`.
:param user: The user to send the instructions to.
"""
token = self.security_utils_service.generate_reset_password_token(user)
reset_link = url_for('security_controller.reset_password',
token=token, _external=True)
self.send_mail(
_('flask_unchained.bundles.security:email_subject.reset_password_instructions'),
to=user.email,
template='security/email/reset_password_instructions.html',
user=user,
reset_link=reset_link)
reset_password_instructions_sent.send(app._get_current_object(),
user=user, token=token)
示例12: post
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def post(self):
if request.form.get('login_github'):
session['oauth_callback_type'] = 'login'
return github_auth.github_auth()
# return 'login_github'
form = forms.LoginForm(obj=request.form)
if form.validate():
try:
user = models.User.objects.get(username=form.username.data)
except models.User.DoesNotExist:
user = None
if user and user.verify_password(form.password.data):
login_user(user, form.remember_me.data)
user.last_login = datetime.datetime.now
user.save()
identity_changed.send(current_app._get_current_object(), identity=Identity(user.username))
return redirect(request.args.get('next') or url_for('main.index'))
flash('Invalid username or password', 'danger')
return self.get(form=form)
示例13: logout
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def logout():
logout_user()
identity_changed.send(current_app._get_current_object(), identity=AnonymousIdentity())
return redirect(url_for('.login'))
示例14: api_auth_required
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def api_auth_required(f):
@wraps(f)
def wrapper(*args, **kwargs):
if request.authorization and request.authorization.type == "basic":
user = user_datastore.find_user(api_key=request.authorization.username)
if user and user.has_role("developer"):
_request_ctx_stack.top.user = user
identity_changed.send(
current_app._get_current_object(), identity=Identity(user.id)
)
return f(*args, **kwargs)
abort(401)
return wrapper
示例15: _check_http_auth
# 需要导入模块: from flask_principal import identity_changed [as 别名]
# 或者: from flask_principal.identity_changed import send [as 别名]
def _check_http_auth():
auth = request.authorization or BasicAuth(username=None, password=None)
if not auth.username:
return False
user = find_user(auth.username)
if user and user.verify_and_update_password(auth.password):
_security.datastore.commit()
app = current_app._get_current_object()
_request_ctx_stack.top.user = user
identity_changed.send(app, identity=Identity(user.fs_uniquifier))
return True
return False