Example #1
0
def customer_register():

    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = CustomerRegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')

        if int(form.gender.data) == 1:
            male = Gender.query.get(1)
            customer = Customer(username=form.username.data, email=form.email.data, password=hashed_password, gender=male.id)

            db.session.add(customer)
            db.session.commit()
        
        elif int(form.gender.data) == 2:
            female = Gender.query.get(2)
            customer = Customer(username=form.username.data, email=form.email.data, password=hashed_password, gender=female.id)

            db.session.add(customer)
            db.session.commit()

        flash(f"Welcome, You've Created Your Account {form.username.data}! You are now able to log in", 'success')
        return redirect(url_for('login'))
    return render_template('customer_register.html', title='Customer Register', form=form)
Example #2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('login'))
    form = RegistrationForm()
    if form.validate_on_submit():
        # KEITH: START
        conn = create_engine('sqlite:///flaskshop/site.db')
        c = conn.connect()
        length = c.execute('SELECT * FROM user')
        length = len(length.fetchall()) + 1
        # length = c.execute('SELECT COUNT(*) FROM user') + 1
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        conn.execute("INSERT INTO user VALUES ({}, '{}', '{}', '{}', '{}', {})".format(length, form.username.data, form.email.data,
                                                                         'default.jpg', hashed_password, 0))
        # db.session.commit()
        # KEITH: END
        # JQ: DISABLED
        # 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)
        # db.session.add(user)
        # db.session.commit()
        # JQ: END
        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)
Example #3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('login'))
    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)
        db.session.add(user)
        db.session.commit()
        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)
Example #4
0
def seller_register():
    form = SellerRegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        seller = Seller(username=form.username.data, email=form.email.data, password=hashed_password, address=form.address.data, phone=form.phone.data)

        db.session.add(seller)
        db.session.commit()

        flash(f"Welcome, You've Created Your Account {form.username.data}! You are now able to log in", 'success')
        return redirect(url_for('login_seller'))
  

    return render_template('seller_register.html', title='Seller Register', form=form)
Example #5
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('shop'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token', 'warning')
        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)
Example #6
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('login'))
    form = RegistrationForm()
    for item in [form.username.data, form.email.data, form.password.data, form.confirm_password.data]:
        for char in ['"', "'", "--", ';', '=']:
            if char in str(item):
                flash('Invalid Characters detected. Please check the fields again.', 'danger')
                return render_template('register.html', title='Register', form=form)
    if form.validate_on_submit():
        # passwordcheck edison
        print(check_password(form.password.data))
        if check_password(form.password.data):
            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)
            db.session.add(user)
            db.session.commit()
            flash('Your account has been created! You are now able to log in', 'success')
            return redirect(url_for('login'))
        else:
            flash('Password is too weak, You will need the following requirements, An upper,lowercase,integer and a special character while being at least 8 characters long', 'danger')
    return render_template('register.html', title='Register', form=form)