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))
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))
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))
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)
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))
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)
def before_request(): if current_app.is_admin: return if current_user.is_authenticated(): if 'channel' in str(current_user.get_id()): return um = current_app.user_manager if current_user.is_user() and not current_user.inviter: try: uid = request.cookies.get('inviter', 0, int) or request.args.get('uid', 0, int) um.funcs.on_invite(current_user, uid) except: current_app.logger.error(traceback.format_exc()) if current_user.is_user() and not current_user.active: logout_user() return error(msg=Item.data( 'active_alert_text', '您的帐号已被封号处理!', name='封号提示')) if current_user.is_user() and current_user.complaint: return error(msg=Item.data( 'complaint_alert_text', '网络异常,加载中!', name='封号提示')) config = current_app.user_manager.config if request.endpoint and request.endpoint not in config.allow_oauth_urls and 'static' not in request.endpoint: 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 if is_json(): abort(NEED_BIND) query = urlencode(dict(next=request.url)) return redirect('%s?%s' % (config.bind_url, query)) elif current_user.phone or current_user.email or model == 'auto': return
def success(self, action, scope, access, next, config=None): if next and 'redirect=true' in next: return redirect(add_args(next, mp_openid=access['openid'])) callback = self.success_callback if not callback: return '授权成功,请设置回调' if type(callback) == functools.partial or \ 'config' in inspect.getargspec(callback)[0]: res = callback(action, scope, access, next, config=config) else: 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)
def auth(self, action='', next='', scope=SNSAPI_BASE, state='STATE', config=None, **kwargs): """发起微信登录,在需要的地方带用即可。 :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() \ and (next is None or next.find('redirect=true') == -1): return abort(WXAUTH_REQUIRED) if config is None: config = self.load_config() return redirect( self.get_auth_url(action, next, scope, state, config, **kwargs))
def wxauth_error(err, action, next): if is_json(): abort(WXAUTH_ERROR, wxcode=err, wxmsg=wxauth.MSGS.get(err, '未知错误')) return error('微信授权失败')
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))