示例#1
0
def register():
    form = RegistrationForm()

    if request.method == "POST" and form.validate_on_submit():

        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')

        new_user = User(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            user_name=form.user_name.data,
            email=form.email.data,
            password=hashed_password,
        )
        new_user.save()

        flash(
            f"Welcome, {form.user_name.data}! You have been successfully registered as a user of Short It :)",
            "success")
        return redirect(url_for("index"))

    return render_template("register.html", title="Register", form=form)
示例#2
0
from short_it.models import URL, User
from datetime import datetime

test_URL = URL(
    shortened="test1",
    URL="www.test_url.com",
)
test_URL.save()

test_user_one = User(
    user_name="nisarg42",
    email="*****@*****.**",
    first_name="Nisarg0",
    last_name="Shah0",
)
test_user_one.save()

test_user_two = User(
    user_name="nisarg123",
    email="*****@*****.**",
    first_name="Nisarg1",
    last_name="Shah1",
)
test_user_two.save()

for document in URL.objects:
    # print(document.to_json()) # to_json() converts the docuemnt object to a readable json format
    print(document.shortened)
    print(document.URL)
    print(document.date_defined)
    print(document.counter)