Example #1
0
    def before_request():
        if current_user.is_authenticated() and "channel" in str(current_user.get_id()):
            return

        if current_user.is_authenticated() and current_user.is_user() and not current_user.active:
            logout_user()
            error(msg=Item.data("active_alert_text", "你的帐号已被封号处理!", name="封号提示"))

        if (
            current_user.is_authenticated()
            and request.endpoint not in current_app.user_manager.config.allow_oauth_urls
            and not request.path.startswith("/admin")
        ):

            um = current_app.user_manager
            model = um.config.oauth_model
            remember = um.config.oauth_remember

            um.models.User.heart()
            if not current_user.is_user():
                if model == "auto":
                    user = um.models.User.from_oauth(current_user)
                    login_user(user, remember=remember)
                    return
            elif current_user.phone or current_user.email or model == "auto":
                return

            if is_json():
                abort(NEED_BIND)

            query = urlencode(dict(next=request.url))
            return redirect("%s?%s" % (current_app.user_manager.config.bind_url, query))
Example #2
0
    def success(self, action, scope, access, next):
        callback = self.success_callback
        if not callback:
            return '授权成功,请设置回调'

        res = callback(action, scope, access, next)
        return res if res else (success() if is_json() else redirect(next))
Example #3
0
 def error(self, err, action, next):
     if self.error_callback:
         res = self.error_callback(err, action, next)
         if res:
             return res
     if is_json():
         return error(msg='授权失败(%s): %s' % (action, err))
     return '授权失败(%s): %s' % (action, err)
Example #4
0
    def auth(self, action='', next='', scope=SNSAPI_BASE, state='STATE'):
        """发起微信登录,在需要的地方带用即可。

        :param action: 公众号授权登录(mp)、扫码登录(qrcode)
        :param next: 授权后下一步链接
        :param scope: snsapi_base|snsapi_userinfo
        :param state: STATE
        """
        action = self.get_action(action)
        if action == 'mobile' or is_json():
            return abort(WXAUTH_REQUIRED)

        return redirect(self.get_auth_url(action, next, scope, state))
Example #5
0
    def success(self, action, scope, access, next):
        callback = self.success_callback
        if not callback:
            return '授权成功,请设置回调'

        res = callback(action, scope, access, next)
        if res:
            return res

        if is_json():
            if current_user.is_authenticated():
                return success()
            return error(msg='登录出错')
        return redirect(next)
Example #6
0
    def auth(self, action='', next='', scope=SNSAPI_BASE, state='STATE'):
        action = self.get_action(action)
        if action == 'mobile' or is_json():
            return abort(WXAUTH_REQUIRED)

        return redirect(self.get_auth_url(action, next, scope, state))
Example #7
0
    def wxauth_error(err, action, next):
        if is_json():
            abort(WXAUTH_ERROR, wxcode=err, wxmsg=wxauth.MSGS.get(err, '未知错误'))

        return error('微信授权失败')