Example #1
0
def edit_account(user_id):
    curr_user = current_user
    if curr_user.role == 'Admin':
        data = User.query.get_or_404(user_id)
        form = AccountForm()

        if form.validate_on_submit():
            hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
            data.username = form.username.data
            data.email = form.email.data
            data.password = hashed_password
            data.role = form.role.data
            data.is_active = form.is_active.data
            data.employee_id = form.employee.data
            db.session.commit()
            flash('User information has been updated.', 'success')
            return redirect(url_for('account', id=user_id))

        elif request.method == 'GET':
            form.username.data = data.username
            form.email.data = data.email
            form.role.data = data.role
            form.is_active.data = data.is_active
            form.employee.data = data.employee_id

        return render_template('edit_account.html',
                               title='Edit Account',
                               form=form,
                               data=data)
    else:
        return redirect(url_for('home'))
Example #2
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)
Example #3
0
 def create_admin(self):
     # check your .env file for admin username and password
     hashed_password = bcrypt.generate_password_hash(
         ADMIN_USER_PASS).decode('utf-8')
     exists = User.query.filter_by(username=ADMIN_USER).first()
     if exists:
         pass
     else:
         user = User(username=ADMIN_USER,
                     email='*****@*****.**',
                     password=hashed_password,
                     role='Admin',
                     is_active=True,
                     employee_id=1)
         db.session.add(user)
         db.session.commit()
Example #4
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'))
Example #5
0
from PIL import Image
import re
from sqlalchemy import exc, desc, text, or_
from faker import Faker
import random
from datetime import datetime

if __name__ == '__main__':
    db.create_all()
    user1 = User(
        id=1,
        username='******',
        email='*****@*****.**',
        is_manager=True,
        dept='Production',
        password=bcrypt.generate_password_hash('test').decode('utf-8'))
    db.session.add(user1)
    db.session.commit()
    num = 1000
    uid = [i for i in range(10001, 10001 + num)]
    fake = Faker(['en_US', 'en_UK'])
    names = []
    for _ in range(num):
        names.append(fake.name())
    emails = []
    for _ in range(num):
        emails.append(fake.email())
    x = int(num / 7)
    is_manager = [True] * (x) + [False] * (num - x + 1)
    random.shuffle(is_manager)
    choices = [('Production', 'Production'), ('RaD', 'Research & Development'),