def register(): if 'user' in session: return redirect(url_for('home')) '''Adding users to the database''' if request.form.get("username") != None: r_username = request.form.get("username") r_num = request.form.get("number") check_num = request.form.get("check_number") all_usernames = db.get_all_users() if r_username in all_usernames: # If the hashes match print(r_username) if (r_num == str(db.get_users_num(r_username)[0][0])): # Log them in session['user'] = r_username print(r_num) # return redirect(url_for("register")) # Allow them to rechoose their text type flash('''<i>Account already made. Do you wish to choose a new text type? <a href="http://127.0.0.1:5000/register">Yes</a>! </i>''') if r_num != check_num: flash("Numbers do not match!") elif r_num.count(' ') != 0: flash("Numbers can not contain spaces") elif r_num.count('-') != 0: flash("Numbers can not contain '-' or anything other than numbers ") elif not r_username.isalnum(): flash("Username should be alphanumeric") else: session['user'] = r_username db.add_user(r_username, ("+1" + r_num)) flash("Account Created") return redirect(url_for("home")) return render_template('login.html', )
def register(): if 'user' in session: return redirect(url_for('home')) '''Adding users to the database''' if request.form.get("reg_username") != None: r_username = request.form.get("reg_username") r_password = request.form.get("reg_password") check_pass = request.form.get("check_password") r_question = request.form.get("reg_question") r_answer = request.form.get("reg_answer") if r_username in db.get_all_users(): flash("Username taken") elif r_password != check_pass: flash("Passwords do not match!") elif r_password.count(' ') != 0: flash("Password can not contain spaces") elif not r_username.isalnum(): flash("Username should be alphanumeric") else: if request.form.get("reg_question") != None: session['user'] = r_username db.add_userFull(r_username, md5_crypt.encrypt(r_password), r_question, md5_crypt.encrypt(r_answer)) return redirect(url_for("how")) else: session['user'] = r_username db.add_user(r_username, md5_crypt.encrypt(r_password)) return redirect(url_for("home")) return render_template('register.html')
def reset(): if 'user' in session: return redirect(url_for('home')) '''To reset user password''' if request.form.get("reg_username") != None: r_username = request.form.get("reg_username") r_answer = request.form.get("reg_answer") r_password = request.form.get("reg_password") check_pass = request.form.get("check_password") all_usernames = db.qaDict() #Returns dict {user:answer_to_question} if r_username not in db.get_all_users(): flash("Username not found") elif r_password != check_pass: flash("Passwords do not match!") elif r_password.count(' ') != 0: flash("Password can not contain spaces") elif not r_username.isalnum(): flash("Username should be alphanumeric") else: session['user'] = r_username # checks the question and answer in the db if r_username in all_usernames: # if the hashes match if md5_crypt.verify(r_answer, all_usernames[r_username]): # changes the user password db.update_pass(r_username, md5_crypt.encrypt(r_password)) return redirect(url_for('home')) else: flash("Error occurred") return render_template('reset.html')
def auth(): '''Intermediate to authenticate login by user''' if 'user' in session: return redirect(url_for('game')) # # # Authenticate username_input = request.form.get("username") password_input = request.form.get("password") all_usernames = db.get_all_users() if username_input in all_usernames: # If the hashes match if md5_crypt.verify(password_input, all_usernames[username_input]): # Log them in session['user'] = username_input return redirect(url_for("game")) # Failed password and username match else: flash("Invalid password") else: # Username doesnt exist flash("Invalid username") return redirect(url_for("login"))