예제 #1
0
def register():
    if request.method == 'POST':
        name = request.form['name']
        email = request.form['email']
        validate_email = User.query.filter_by(email=email).first()
        if validate_email:
            flash(f'Account already exist for {email}. Sign-in instead',
                  'warning')
            return render_template('register.html')
        username = request.form['username']
        phone = request.form['phone']
        validate_username = User.query.filter_by(username=username).first()
        if validate_username:
            flash(
                f'Username {username} already exist please select another username',
                'warning')
            return render_template('register.html')
        password = request.form['password']
        hashed_pw = bcrypt.generate_password_hash(password).decode('utf-8')
        user = User(name=name,
                    email=email,
                    username=username,
                    password=hashed_pw,
                    phone=phone)
        db.session.add(user)
        db.session.commit()
        flash(f'Account created for {name}', 'success')
        return redirect(url_for('home'))
    return render_template('register.html')
예제 #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)
		db.session.add(user)
		db.session.commit()
		flash(f"Account created for {form.username.data}, Log in now!", "success")
		return redirect(url_for('login'))
	return render_template("register.html", title="Register", form = form)
예제 #3
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)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
예제 #4
0
def reset_token(token):
	if current_user.is_authenticated:
		flash(f'Please log out before reset the password')
		return redirect(url_for('home'))	
	user = User.verify_reset_token(token)
	if user is None:
		flash(f"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(f"Your password has been updated", "success")
		return redirect(url_for('login'))
	return render_template('reset_token.html', title='Reset Password', form=form)	
예제 #5
0
 def setUp(self):
     app.config['SECRET_KEY'] = '08424fa094ead1b004ff459bbd6e2750'
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
     self.app = app.test_client()
     db.create_all()
     hashed_password = bcrypt.generate_password_hash('12345').decode(
         'utf-8')
     u1 = User(username='******',
               email='*****@*****.**',
               password=hashed_password)
     u2 = User(username='******',
               email='*****@*****.**',
               password=hashed_password)
     db.session.add(u1)
     db.session.add(u2)
     db.session.commit()
예제 #6
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form = RegistrationForm()
    form.preference.choices = [(candidate.id, candidate.name)
                               for candidate in Candidate.query.all()]
    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,
                    preference=form.preference.data)
        db.session.add(user)
        db.session.commit()
        flash(f'Welcome {form.username.data}! You can Log in now!', 'success')
        return redirect(url_for('login'))
    return render_template('signup.html', form=form)
예제 #7
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('profile'))
    form = RegisterForm(request.form)
    if request.method == 'POST':
        email = request.form['email']
        username = request.form['username']
        fname = request.form['fname']
        lname = request.form['lname']
        password = request.form['password']
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(password).decode('utf-8')
        user = User(email=email,
                    username=username,
                    fname=fname,
                    lname=fname,
                    password=hashed_pw)
        db.session.add(user)
        db.session.commit()
        flash(f'Account Created for', 'sucess')
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
예제 #8
0
def hash_password(password):
  return bcrypt.generate_password_hash(password).decode('utf-8')