def add_user_to_database(): # data validation: username = request.form['username'] password = request.form['password'] confirm = request.form['confirm'] existing_usernames = data_manager.existing_users() if len(username) == 0: registration_error_message = 'Empty username field.' return render_template('registration.html', registration_error_message=registration_error_message) if username in existing_usernames: registration_error_message = 'This username is already exists. Write another one.' return render_template('registration.html', registration_error_message=registration_error_message) if len(password) == 0: registration_error_message = 'Empty password field.' return render_template('registration.html', registration_error_message=registration_error_message) if len(password) < 5: registration_error_message = 'Password must be at least five characters long.' return render_template('registration.html', registration_error_message=registration_error_message) if len(confirm) == 0: registration_error_message = 'Empty confirm field.' return render_template('registration.html', registration_error_message=registration_error_message) if password != confirm: registration_error_message = 'Password does not match the confirm password.' return render_template('registration.html', registration_error_message=registration_error_message) # salting password and save user: salted_password = generate_password_hash(password, method='pbkdf2:sha256', salt_length=8) data_manager.add_new_user(username, salted_password) return render_template('index.html', registration_succeeded='registration_succeeded')
def add_new_user(): if request.method == 'GET': return render_template('register.html') elif request.method == 'POST': user_data = request.form data_manager.add_new_user(user_data['user_name'], user_data['password']) return redirect('/login')
def registration(): if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') hashed_password = data_manager.hash_password(password) data_manager.add_new_user(username, hashed_password) return redirect(url_for('index')) return render_template('registration.html')
def registration_user_post(): email = dict(request.form) email['email'] = email['email'].lower() if data_manager.check_for_user(email): return redirect(url_for("registration_user", ver="exist")) else: email['submission_time'] = util.get_current_date_time() data_manager.add_new_user(email) return redirect(url_for("main_page"))
def save_new_user(): if request.method == 'POST': data_manager.add_new_user(create_user_data()) return redirect('/') nexturl = request.referrer return render_template('registration.html', reg_or_log='REGISTER', title='Create new account', nexturl=nexturl)
def registration(): if request.method == 'POST': new_data = request.form.to_dict() try: data_manager.add_new_user(new_data) except: return render_template('registration.html', username=request.form.get('username'), action_route='/registration') return redirect('/') return render_template('registration.html', action_route='/registration')
def save_new_user(message=None): action = request.args.get('action') if request.method == 'POST': if data_manager.check_registration_name( request.form.get('user_name')) is None: data_manager.add_new_user(create_user_data()) return redirect('/') else: message = 'Username already in use' return render_template('login.html', message=message, action=action)
def save_new_user(): form_action = url_for("save_new_user") user_action = "Sign up" dict_of_new_user = request.form.to_dict() try: data_manager.add_new_user(dict_of_new_user) except ValueError: return render_template("new_user.html", form_action=form_action, user_action=user_action, registration_failed=True) return redirect(url_for("index"))
def register(): form = RegistrationForm() if form.validate_on_submit(): user_data = { 'username': form.username.data, 'email': form.email.data, 'password': registration.hash_password(form.password.data), } add_new_user(user_data) flash( f'Account created for {form.username.data}! You are now able to log in', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def registration(): username = None password = None if request.method == "POST": username = request.form.get('username').lower() password = util.hash_password(request.form.get('password')) if data_manager.check_user_exists(username): flash( 'The user already exists. Please choose a different username') redirect(url_for('registration')) else: data_manager.add_new_user(username, password) flash('Succesulf registration. Login to continue.') return redirect(url_for('login')) return render_template('registration.html')
def route_register_user(): if request.method == 'GET': return render_template('user_registration.html') if data_manager.check_if_user_exists(request.form.get('username'), request.form.get('email')): user_already_exists = True return render_template('user_registration.html', user_already_exists=user_already_exists) new_user_data = request.form data_manager.add_new_user(new_user_data) return redirect('/')
def register_user(): if request.method == "POST": input_username = request.form['username'] input_password = request.form['password'] input_password_repeated = request.form['password_repeat'] if input_password != input_password_repeated: return redirect(url_for("register_user")) else: hashed_password = utility.hash_password(input_password) try: data_manager.add_new_user(input_username, hashed_password) return render_template('index.html', username=input_username) except psycopg2.IntegrityError: return redirect(url_for("register_user")) else: return render_template('registration.html')
def registration(): unsuccess_registration = False new_name = request.form.get("new_user") new_password = request.form.get("new_password") print(new_name, new_password) new_user = data_manager.add_new_user(new_name, new_password) if new_user == 1: return render_template('main.html', unsuccess_registration=True) else: return redirect('/main')
def registration(): if request.method == 'POST': req = request.form hashed_password = util.hash_password(req['password']) if data_manager.check_user_data('username', req['username']) is True: flash('This username is already taken!') return redirect(request.url) elif data_manager.check_user_data('email_address', req['email']) is True: flash('This email address is already taken!') return redirect(request.url) elif len(req['password']) < 7: flash('Too short password! (Min. 7 character.)') return redirect(request.url) elif not util.verify_password(req['password_again'], hashed_password): flash('The passwords are different!') return redirect(request.url) else: list_of_data = [req['username'], req['email'], util.hash_password(req['password'])] data_manager.add_new_user(list_of_data) session['id'] = data_manager.get_user_id(req['username'])[0]['id'] session['username'] = req['username'] return redirect(url_for('route_main')) return render_template('registration.html')
def add_new_user(username, password): hashed_password = pass_hash.hash_password(password) inputs = [username, hashed_password] data_manager.add_new_user(inputs)