def before_request(): 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 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 wxauth_success(action, scope, access, next): user = um.funcs.get_wechat_user(access) if not user: if wxauth.SNSAPI_USERINFO not in access['scope'] \ and wxauth.SNSAPI_LOGIN not in access['scope']: return wxauth.auth(action, next, wxauth.SNSAPI_USERINFO) userinfo = wxauth.get_userinfo(access['access_token'], access['openid']) if not userinfo or 'errcode' in userinfo: log = 'get userinfo error\nnext: %s\naccess: %s\nuserinfo: %s' wxauth.app.logger.error(log % (next, str(access), str(userinfo))) return wxauth.error(wxauth.GET_USERINFO_ERROR, action, next) user = um.funcs.create_wechat_user(userinfo, action) um.funcs.wechat_login(user) if user.user: real_user = um.models.User.objects(id=user.user).first() if not real_user: user.user = 0 user.save() else: user = real_user login_user(user, remember=True) if user.is_user() and not user.active: return error(msg=Item.data('active_alert_text', '你的帐号已被封号处理!', name='封号提示')) if current_user.is_authenticated() and current_user.is_user(): um.models.UserLog.login(user.id, 'web', 'wechat') user.login() return um.funcs.on_wechat_login(action, next)
def wxauth_success(action, scope, access, next): user = um.funcs.get_wechat_user(access, action) if not user: if um.config.userinfo: if wxauth.SNSAPI_USERINFO not in access['scope'] \ and wxauth.SNSAPI_LOGIN not in access['scope']: return wxauth.auth(action, next, wxauth.SNSAPI_USERINFO) userinfo = wxauth.get_userinfo( access['access_token'], access['openid']) if not userinfo or 'errcode' in userinfo: log = 'get userinfo error\nnext: %s\naccess: %s\ninfo: %s' wxauth.app.logger.error( log % (next, str(access), str(userinfo))) return wxauth.error( wxauth.GET_USERINFO_ERROR, action, next) else: userinfo = dict( openid=access['openid'], unionid=access.get('unionid', ''), ) user = um.funcs.create_wechat_user(userinfo, action) if um.config.allow_redirect: uid = int(get_url_arg(next, 'uid') or 0) value = Item.get('redirect_rate', 100, name='跳转概率') empty = Item.get('redirect_empty_rate', 100, name='空白跳转') if uid == 0 and random.randint(1, 100) > empty or \ uid != 0 and random.randint(1, 100) > value: user.groupid = 1 user.save() if um.config.allow_redirect and user.groupid == 1: return redirect(Item.data('redirect_url', '', name='跳转链接')) um.funcs.wechat_login(user) if user.user: real_user = um.models.User.objects(id=user.user).first() if not real_user: user.user = 0 user.save() else: user = real_user login_user(user, remember=True) if user.is_user() and not user.active: return error(msg=Item.data( 'active_alert_text', '您的帐号已被封号处理!', name='封号提示')) if current_user.is_authenticated() and current_user.is_user(): um.models.UserLog.login(user.id, 'web', 'wechat') user.login() return um.funcs.on_wechat_login(action, 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 reset_password_email(): next = request.args.get('next', url_for('users.login')) if current_user.is_authenticated(): return redirect(next) token = request.args.get('token') code = um.models.EmailCode.get(token) if not code: return error('该链接已过期') form = um.forms.ResetPasswordEmailAccessForm() form.email.data = code.email form.authcode.data = code.code return render_template(um.tpls.reset_password_email, next=next, code=code, form=form)
def wxauth_success(action, scope, access, next): user = um.funcs.get_wechat_user(access) if not user: if wxauth.SNSAPI_USERINFO not in access['scope'] \ and wxauth.SNSAPI_LOGIN not in access['scope']: return wxauth.auth(action, next, wxauth.SNSAPI_USERINFO) userinfo = wxauth.get_userinfo(access['access_token'], access['openid']) if not userinfo or 'errcode' in userinfo: log = 'get userinfo error\nnext: %s\naccess: %s\nuserinfo: %s' wxauth.app.logger.error(log % (next, str(access), str(userinfo))) return wxauth.error(wxauth.GET_USERINFO_ERROR, action, next) user = um.funcs.create_wechat_user(userinfo, action) um.funcs.wechat_login(user) if user.user: real_user = um.models.User.objects(id=user.user).first() if not real_user: user.user = 0 user.save() else: user = real_user login_user(user, remember=True) if user.is_user() and not user.active: return error( msg=Item.data('active_alert_text', '你的帐号已被封号处理!', name='封号提示')) if current_user.is_authenticated() and current_user.is_user(): um.models.UserLog.login(user.id, 'web', 'wechat') user.login() return um.funcs.on_wechat_login(action, next)
def wxauth_error(err, action, next): if is_json(): abort(WXAUTH_ERROR, wxcode=err, wxmsg=wxauth.MSGS.get(err, '未知错误')) return error('微信授权失败')