def has_perm(info_hash, perm): if not auth.is_authenticated(session): return False if not rc.exists("perm|%s" % info_hash): return False return rc.sismember("perm|%s" % info_hash, "user:%s:%s" % (auth.current_user(), perm))
def vote_poll(poll_id, choice_id): # check if the user is logged in if not auth.is_authenticated(): return json.dumps({ 'success': False, 'message': 'You are not logged in' }) data.change_poll_vote(auth.current_user_id(), poll_id, choice_id) return json.dumps({ 'success': True, })
def grant_admin(): # check if the user is logged in if not auth.is_authenticated(): return json.dumps({ 'success': False, 'message': 'You are not logged in' }) data.grant_admin(auth.current_user_id()) return json.dumps({ 'success': True, 'message': '' })
def new_comment(): # check if the user is logged in if not auth.is_authenticated(): return json.dumps({ 'success': False, 'message': 'You are not logged in' }) comment_body = flask.request.form.get('body') print('comment_body =', comment_body) poll_id = flask.request.form.get('poll') print('poll_id =', poll_id) data.create_comment(auth.current_user_id(), poll_id, comment_body) return flask.redirect('/poll/{}'.format(poll_id))
def toggle_favourite(movie_id): # check if the user is logged in if not auth.is_authenticated(): return json.dumps({ 'success': False, 'message': 'You are not logged in' }) # toggle favourite status and send the new status back favourite_status = data.toggle_favourite(flask.session['user_id'], movie_id) return json.dumps({ 'success': True, 'favourite': favourite_status, })
def create_poll(): # check if the user is logged in if not auth.is_authenticated(): return json.dumps({ 'success': False, 'message': 'You are not logged in' }) poll_title = flask.request.args.get('title') poll_desc = flask.request.args.get('description') poll_choices = [] for i in range(1, 25): pc = flask.request.args.get('choice' + str(i)) if not pc: break poll_choices.append(pc) # remove duplicates poll_choices = list(dict.fromkeys(poll_choices)) poll_id = data.create_poll(auth.current_user_id(), poll_title, poll_desc, poll_choices) return flask.redirect('/poll/{}'.format(poll_id))
def save_grant(client_id, code, r, *args, **kwargs): if not auth.is_authenticated(session): abort(400) return auth.save_grant(auth.current_user(), client_id, code, r, args, kwargs)
def login_get(): if auth.is_authenticated(): return redirect(request.args.get('next', None) or '/dashboard/') else: return render_template('login.html')
"^/api/update-pass/?$": auth.change_password, "^/api/meetings": meetings.meetings_actions, } def find_handler(routes, url): for route, handler in routes.items(): if re.match(route, url): return handler return False url = environ["REQUEST_URI"] handler = False authenticated = auth.is_authenticated() if authenticated: handler = find_handler(auth_routes, url) if not handler: handler = find_handler(unauth_routes, url) if handler: handler() else: response = request.Response() if authenticated: response.status = 404 response.data = "not found" else: response.status = 403