def regist_validate(): print("Got Post Info") print(request.form) data = { "first_name": request.form["first_name"], "last_name": request.form["last_name"], "email": request.form["email"], "password": request.form["password"], "confirm_password": request.form["confirm_password"] } account = Account.get_account_by_email(data) if len(account) > 0: flash("Email has been used for registration already.", 'email') return redirect('/') if not Account.validate_regist(account, data): return redirect("/") pw_hash = bcrypt.generate_password_hash(data["password"]) data["password"] = pw_hash new_account_id = Account.insert_one(data) print(new_account_id) session["user_id"] = new_account_id session["first_name"] = data["first_name"] return redirect("/login")
def regist_validate(): print("Got Post Info") print(request.form) data = { "first_name": request.form["first_name"], "last_name": request.form["last_name"], "username": request.form["username"], "email": request.form["email"], "password": request.form["password"], "confirm_password": request.form["confirm_password"] } account = Account.get_account_by_username(data) if len(account) > 0: flash( "Username has been used for registration already, please choose a unique one." ) return redirect('/regist') if not Account.validate_regist(data): return redirect("/regist") pw_hash = bcrypt.generate_password_hash(data["password"]) data["password"] = pw_hash new_account_id = Account.insert_one(data) print(new_account_id) session["user_id"] = new_account_id session["username"] = data["username"] return redirect("/dashboard")
def email_check(): find = False data = {"email": request.form["email"]} result = Account.get_account_by_email(data) if result: find = True return render_template("partial_emailcheck.html", find=find)
def login_validate(): data = {"email": request.form["email"]} account = Account.get_account_by_email(data) print(account) if len(account) < 1: flash("Email or password invalid." 'login') return redirect("/") if not bcrypt.check_password_hash(account[0]["password"], request.form["password"]): flash("Email or password invalid." 'login') return redirect("/") session["id"] = account[0]["id"] return redirect("/login")
def login_validate(): data = {"username": request.form["username"]} account = Account.get_account_by_username(data) print(account) if len(account) < 1: flash("Username or password invalid.") return redirect("/login") if not bcrypt.check_password_hash(account[0]["password"], request.form["password"]): flash("Username or password invalid." 'login') return redirect("/login") session["user_id"] = account[0]["id"] session["username"] = account[0]["username"] return redirect("/dashboard")
def validate_message(sent_to_id): data = { "sent_to": request.form["sent_to"], "content": request.form["content"], "title": request.form["title"], "account_id": session["user_id"] } data1 = {"username": request.form["sent_to"]} if not Message.validate_message(data): return redirect(f"/send_message/{sent_to_id}") elif len(Account.get_account_by_username(data1)) != 1: flash("username is invalid or doesn't exist.") return redirect(f"/send_message/{sent_to_id}") else: Message.send_message(data) return redirect("/dashboard")
def login_successs(): if "user_id" not in session: return redirect("/") else: data = {"id": session["user_id"]} messages = Message.get_message_to_account(data) print(messages) account_list = Account.get_account_exclude_id(data) print(account_list) total_sent = Message.total_message_sent(data) print(total_sent) total_received = Message.total_message_received(data) print(total_received) return render_template("private_wall.html", messages=messages, account_list=account_list, first_name=session["first_name"], total_sent=total_sent, total_received=total_received)
def send_message(sent_to_id): data = {"id": sent_to_id} sent_to_username = Account.get_username_by_id(data) return render_template("send_message.html", sent_to_username=sent_to_username, sent_to_id=sent_to_id)