Ejemplo n.º 1
0
def register():
	form = RegistrationForm()
	if current_user.is_authenticated:
		return redirect(url_for('main'))
	if form.validate_on_submit():
		hashed_pw = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
		user = User(username=form.username.data, email=form.email.data, password=hashed_pw)
		db.session.add(user)
		db.session.commit()		
		flash(f'Account created for {form.username.data}!', 'success')
		return redirect(url_for('login'))
	return render_template('register.html', title='Register', form=form)
Ejemplo n.º 2
0
def register_as_admin():
    curr_user = current_user
    if curr_user.role == 'Admin':
        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,
                role=form.role.data,
                employee_id=form.employee.data,
                password=hashed_password
            )
            db.session.add(user)
            db.session.commit()
            flash(f'Account created for {form.email.data}.', 'success')
            return redirect(url_for('account'))
        return render_template('register_as_admin.html',
                               title='Register New',
                               form=form)
    else:
        return redirect(url_for('home'))