def login(): # YOUR SOLUTION HERE if request.method == 'GET': return render_template('login.html', error=request.args.get('error')) elif request.method == 'POST': username = request.form['username'] password = request.form['password'] users = get_users() # Check if username in database if username in users: password_encripted = hash_password(password) password_db = users[username] # Check if password matches if password_encripted == password_db: session['logged_in'] = username print ('Ok') return render_template('dashboard.html', title='Dashboard') else: print ('Nok') return redirect(url_for('login', error=True)) else: return redirect(url_for('login', error=True)) return render_template('login.html', title='Login')
def addplaylist(): sections = get_sections(session["plex_url"], session["plex_token"]) users = get_users(session["plex_url"], session["plex_token"]) data = {"sections": sections, "users": users} return render_template('addplaylist.html', data=data)
def get_users(): user_type = request.args.get('user_type') username = request.args.get('username') email = request.args.get('email') sort = request.args.get('sort') order = request.args.get('orderDir') return jsonify( message=helpers.get_users(user_type, username, email, sort, order))
def valid_login(username, password): # username = request.form['username'] # password = request.form['password'] user_db = get_users() hsd_enterd_pw = hash_password(password) # check if user in db result = False if username in list(user_db.keys()): # check if hashed pw matches with db_pw if user_db[username] == hsd_enterd_pw: result = True return result
def edit(request, group_id): param = {} if group_id: group = get_group(group_id) require = check_user(group) if require: return redirect("/redirect/?%s" % require) users = get_users(group) param.update({'group': group, 'users': users,}) errs = get_param(request, 'errs') if errs: errs = errs.split(',') for err in errs: param.update({"%s_error" % err: True,}) return respond('group_edit.html', param)
def login(): if request.method == "GET": print(request.args.get("error")) return render_template("login.html", error=request.args.get("error")) elif request.method == "POST": users = get_users() attempted_password = hash_password(request.form["password"]) try: username = request.form["username"] stored_password = users[username] except KeyError: return redirect(url_for("login", error=True)) if stored_password == attempted_password: session["username"] = request.form["username"] return redirect(url_for("dashboard")) else: return redirect(url_for("login", error=True))
def detail(request, group_id): group = get_group(group_id) if not group: raise Http404() require_privilege = check_user(group) summaries = [] +group.summaries summaries.sort() due_payer_index = group.summaries.index(summaries[0]) due_payer = get_user(group.members[due_payer_index]) params = {'fees': get_fees(group), 'members': get_users(group), 'is_valid_user': not require_privilege, 'group': group, 'due_payer': due_payer.name, 'due_amount': -summaries[0], } return respond('group_detail.html', params)
def save(request): password = post_param(request, 'password') name = post_param(request, 'name') members = post_param(request, 'members').split() group_id = post_param(request, 'group_id') owner_email = post_param(request, 'owner') group = None if group_id: try: group = get_group(long(group_id)) require = check_user(group) if require: return redirect("/redirect/?%s" % require) except: return redirect('/group/edit/?errs=group_id') for member in get_users(group): if member.name not in members: return redirect('/group/edit/%s?errs=members' % group.key().id()) members = save_users(members, group) owner = None try: owner = users.User(owner_email) except: owner = users.get_current_user() if group: group.members = members group.owner = owner else: group = Group(members = members, password = password, name = name, owner = owner) while len(group.summaries) < len(members): group.summaries.append(0.0) group.put() return redirect('/redirect/group/')
def server(): users = get_users(session["plex_url"], session["plex_token"]) return render_template("server.html.jinja", users=users)
def test_bad_token(username, password): payload = {"username": username, "password": password} res = requests.post(base_url + "auth", json=payload) if res.status_code != 401: print( f"FAILURE: received status code {res.status_code} invalid username and password" ) if __name__ == "__main__": tokens = { "Standard": get_token("hsimpson", "password"), "NonOwner": get_token("wsmithers", "password"), "Employee": get_token("rwiggum", "password"), "Admin": get_token("msimpson", "password"), } users = get_users(token=tokens['Admin']) users['hsimpson']['password'] = "******" users['hsimpson'] = check("PUT", "users/" + str(users['hsimpson']['accountholder_id']), expected_status=202, token=tokens["Admin"], json=users['hsimpson']) # return # test_bad_token("nflanders", "badentry") # test_bad_token("unknown", "password") # # 46 => hsimpson # # 58 => hsimpson owns # ID = {"users": "/46", "accounts": "/58"} # check("GET", "accounts/status/44", expected_status=200, token=tokens["Admin"]) # check("GET", "accounts/status/44", expected_status=200, token=tokens["Employee"]) # check("GET", "accounts/status/44", expected_status=403, token=tokens["Standard"])
import helpers users = helpers.get_users() print("run_videos | users | get", len(users)) videos = helpers.get_videos() print("run_videos | videos | before", len(videos)) videos.sort(key=lambda v: v['created_at'], reverse=False) videos = list({v['user_id']: v for v in videos}.values()) print("run_videos | videos | after", len(videos)) csv_twitch_user_ids = [u['twitch_user_id'] for u in users] existing_user_videos = [ v for v in videos if v['user_id'] in csv_twitch_user_ids ] print("run_videos | existing_user_videos", len(existing_user_videos)) new_user_videos = [ v for v in videos if v['user_id'] not in csv_twitch_user_ids ] print("run_videos | new_user_videos", len(new_user_videos)) for euv in existing_user_videos: for u in users: if u['twitch_user_id'] == euv['user_id']: u['twitch_user_name'] = euv['user_name'] u['latest_stream_id'] = euv['id'] u['latest_stream_view_count'] = euv['view_count'] u['latest_stream_duration'] = euv['duration'] u['latest_stream_date'] = euv['created_at'] for nuv in new_user_videos: