def login(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] user_data = data_handler.get_user_by_name(username) if user_data: hash_handler.verify_password(password, user_data['password']) session['user_id'] = user_data['id'] session['username'] = user_data['username'] session['name'] = user_data['name'] return redirect('/account_history') else: flash('Invalid username or password') return redirect('/login') else: return redirect('/login')
def login_page(): if request.method == 'POST': user_name = request.form['username'] user_info = data_handler.get_user_info_from_db(user_name) wrong_data_help = None if user_info is None: return render_template('login.html', wrong_data_help=wrong_data_help) if hash_handler.verify_password(request.form['password'], user_info['pwd_hash']): session['username'] = user_info['username'] session['user_id'] = user_info['user_id'] return redirect(url_for('index')) else: return render_template('login.html', wrong_data_help=wrong_data_help) return render_template('login.html')
def registration(): alert = "passwords do not match" if request.method == 'POST': user_values = request.form.to_dict() hash_password = hash_handler.hash_password(user_values['password']) hash_verified_password = hash_handler.verify_password( user_values['verify_password'], hash_password) if hash_verified_password is True: user_values['password'] = hash_password data_handler.insert_registration_data(user_values) return redirect(url_for('home')) else: return render_template('registration.html', alert=alert) return render_template('registration.html')
def login(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] user_data = data_handler.get_user_by_username(username) is_login_successful = False if user_data: is_login_successful = hash_handler.verify_password( password, user_data['password']) if is_login_successful: session['user_id'] = user_data['id'] session['username'] = user_data['username'] else: flash('Invalid username or password') return redirect(url_for('index'))
def signup(): if request.method == 'POST': user_values = request.form.to_dict() hash_password = hash_handler.hash_password(user_values['password']) hash_verified_password = hash_handler.verify_password( user_values['verify_password'], hash_password) if hash_verified_password is True: user_values['password'] = hash_password inserted_user = data_handler.insert_new_user(user_values) if inserted_user: session['user_id'] = inserted_user['id'] session['username'] = inserted_user['username'] return redirect(url_for('index')) else: return render_template('signup.html', alert="this username already exists") else: return render_template('signup.html', alert="passwords do not match") else: return render_template('signup.html')