コード例 #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,
                    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)
コード例 #2
0
def add_emp():
	form = AddEmpForm()
	if form.validate_on_submit():
		hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
		emp = Employee(fname=form.fname.data, lname=form.lname.data, email=form.email.data.lower(),
					 phone=form.phone.data, role=form.role.data
					 , password=hashed_password)
		if form.salary.data:
			emp.salary = form.salary.data
		if form.incentive.data:
			emp.incentive = form.incentive.data
		db.session.add(emp)
		db.session.commit()
		flash('A new Employee has been added successfully', 'success')
		return redirect(url_for('add_emp'))
	return render_template('add_employee.html', title='Add Employee', form=form)
コード例 #3
0
def reset_token(token):
	if current_user.is_authenticated:
		return redirect(url_for('home'))
	emp = Employee.verify_reset_token(token)	
	if emp 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')
		if emp:
			emp.password = hashed_password
		db.session.commit()
		flash('Your password has been updated! You are now able to login', 'success')
		return redirect(url_for('login'))
	return render_template('reset_token.html', title='Reset Password', form=form)
コード例 #4
0
ファイル: routes.py プロジェクト: isaacrivas10/fb_chatbot
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    ip = request.environ.get('HTTP_X_FORWARDED_FOR', request.remote_addr)
    print(ip)
    if form.validate_on_submit():
        hashed_pwd = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(first_name=form.firstName.data,
                    last_name=form.lastName.data,
                    email=form.email.data,
                    password=hashed_pwd,
                    phone_number=form.phone.data)
        db.session.add(user)
        db.session.commit()
        flash('Tu cuenta ha sido creada con exito. Por favor inicia sesión.')
        return redirect(url_for('users.login'))
    return render_template('register.html',
                           title='Register',
                           form=form,
                           geo=handler.getDetails(ip))
コード例 #5
0
from store import db

from store.models import Main_item, BoughtItem, SoldItem, Expenses, Employee

db.create_all()

from store import bcrypt

hp = bcrypt.generate_password_hash('admin').decode('utf-8')

admin = Employee(fname='super',
                 lname='admin',
                 email='*****@*****.**',
                 phone='01615487926',
                 password=hp,
                 role='admin')

db.session.add(admin)

db.session.commit()