Пример #1
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data.lower(), department=form.department.data,\
         gender=form.gender.data, age=form.age.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'Account Created for {form.username.data}! You can now log in',
              'success')
        return redirect(url_for('login'))
    return render_template('re.html', title="Register", form=form)
Пример #2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password,
                firstname=form.firstname.data, lastname=form.lastname.data, date_of_birth=form.date_of_birth.data,
                zipcode=form.zipcode.data, phone=form.phone.data)
        db.session.add(user)
        db.session.commit()
        print("hello")
        print(user.id)

        flash('Your account has been created! You are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Пример #3
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token', 'danger')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('Your password has been updated! You are now able to log in',
              'success')
        return redirect(url_for('login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Пример #4
0
def load_users():
    """Load users from static/user_data.txt into database."""

    print("User")
    User.query.delete()

    file = open("seed_data/user_data.txt")
    for row in file:
        row = row.rstrip()
        row = row.split("|")

        user_id = row[0]
        fname = row[1]
        lname = row[2]
        email = row[3]
        user_name = row[4]
        password = row[5]
        date_of_birth = row[6]
        zipcode = row[7]
        phone = row[8]
        profile_picture = row[10]

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

        #insert user
        user = User(id=user_id,
                    firstname=fname,
                    lastname=lname,
                    email=email,
                    username=user_name,
                    password=hashed_password,
                    date_of_birth=date_of_birth,
                    city=zipcode,
                    phone=phone,
                    image_file=profile_picture)

        db.session.add(user)

    db.session.commit()