示例#1
0
 def create_user(initial_users_list):
     for user in initial_users_list:
         if not user_datastore.get_user(user['email']):
             user_datastore.create_role(name=user['name'], description=user['description'])
             db.session.commit()
             role = Role.query.filter_by(name=user['name']).first()
             user_datastore.create_user(
                 email=user['email'], username=user['name'], password=hash_password(user['password']))
             user = User.query.filter_by(username=user['name']).first()
             user_datastore.add_role_to_user(user, role)
             db.session.commit()
示例#2
0
def oauth_callback(provider):
    if not current_user.is_anonymous:
        return redirect(url_for('index'))
    oauth = OAuthSignIn.get_provider(provider)
    social_id, username, email = oauth.callback()
    if social_id is None:
        flash('Authentication failed.')
        return redirect(url_for('index'))
    user = User.query.filter_by(social_id=social_id).first()
    if not user:
        user_datastore.create_user(social_id=social_id, username=username, email=email)
        user = User.query.filter_by(social_id=social_id).first()
        db.session.commit()
    login_user(user, True)
    return redirect(url_for('index'))
示例#3
0
    def run(self):
        username = input('Username: '******'Password: '******'Confirm password: '******'user created')
            except IntegrityError:
                print('Username already in use')
        else:
            print('Passwords did not match')
示例#4
0
def app():
    load_dotenv(
        dotenv_path=os.path.join(os.path.dirname(__file__), ".flaskenv"))

    db_fd, db_path = tempfile.mkstemp()
    os.environ['DATABASE_URI'] = f"sqlite:///{db_path}"

    from app import app, db
    from app.security import user_datastore
    with app.app_context():
        db.create_all()
        user_datastore.create_user(email="*****@*****.**",
                                   password="******")
        db.session.commit()
    yield app

    # close and remove the temporary database
    os.close(db_fd)
    os.unlink(db_path)
示例#5
0
    def run(self):
        clients = ['Client A', 'Client B', 'Client C']
        for client in clients:
            c = Client(name=client)
            db.session.add(c)
        products = ['Billing', 'Claims', 'Policies', 'Reports']
        for product in products:
            p = ProductArea(name=product)
            db.session.add(p)
        admin = user_datastore.create_user(username='******',
                                           password='******',
                                           email='*****@*****.**')
        admin_role = user_datastore.create_role(name='admin')
        user_datastore.add_role_to_user(admin, admin_role)

        developer1 = user_datastore.create_user(username='******',
                                                password='******',
                                                email='*****@*****.**')
        developer2 = user_datastore.create_user(username='******',
                                                password='******',
                                                email='*****@*****.**')
        db.session.commit()

        for i in range(12):
            ticket = Ticket(
                title='Sample Ticket {}'.format(i + 1),
                description='Sample Description {}'.format(i + 1),
                priority=[1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4][i],
                target=(datetime.datetime.now() +
                        datetime.timedelta(days=random.randint(-2, 4))).date(),
                ticket_url='http://ticket{}.example.com'.format(i + 1),
                client_id=(i % 3) + 1,
                product_area_id=(i % 4) + 1,
                assigned_to_id=(i % 2) + 2)
            db.session.add(ticket)
            db.session.commit()

        print('example data inserted into db')
示例#6
0
def create_user():
    if request.method == 'GET':
        return render_template('create_user.html')
    else:
        username = request.form['username']
        email = request.form['email']
        generate_password = False
        if request.form.get('generate_password'):
            generate_password = True if request.form[
                'generate_password'].lower() == 'on' else False
        if generate_password:
            password = confirm = gen_password(12)
        else:
            password = request.form['password']
            confirm = request.form['confirm']
        if len(password) < app.config['MIN_PASSWORD_LENGTH'] or len(
                confirm) < app.config['MIN_PASSWORD_LENGTH']:
            flash('Password must be at least {} characters'.format(
                app.config['MIN_PASSWORD_LENGTH']))
            return redirect(url_for('create_user'))
        if not password == confirm:
            flash('Passwords did not match each other, please try again')
            return redirect(url_for('create_user'))
        try:
            user_datastore.create_user(email=email,
                                       password=password,
                                       username=username)
            db.session.commit()
            if generate_password:
                flash('User created with password: {}'.format(password))
            else:
                flash('User created')
            return redirect(url_for('list_users'))
        except IntegrityError:
            flash('Email is already in use')
            return redirect(url_for('create_user'))
示例#7
0
def create_admin():
    admin_role = user_datastore.find_or_create_role(
        name='admin',
        description='Full Administrator Privliges'
    )

    admin_user = user_datastore.find_user(email='*****@*****.**')
    if admin_user is None:
        admin_user = user_datastore.create_user(
            email='*****@*****.**',
            password='******'
        )

    user_datastore.add_role_to_user(admin_user, admin_role)

    db.session.commit()
示例#8
0
from app.models.users import User
from app.security import user_datastore
from sys import argv

try:
    command = argv[1]
except IndexError:
    command = None

db.create_all()

if command == 'test':

    user_datastore.create_user(
        email='*****@*****.**',
        screen_name='player-one',
        # password: player-one
        password='******'
    )

    user_datastore.create_user(
        email='*****@*****.**',
        screen_name='player-two',
        # password: player-two
        password='******'
    )

    user_datastore.create_user(
        email='*****@*****.**',
        screen_name='player-three',
        # password: player-three
        password='******'
示例#9
0
def init_db():
    # try:
    #     roles = ["User", 'Shop', 'Admin']
    #     for r in roles:
    #         role = Role.query.filter_by(name = r).first()
    #         if role is None:
    #             user_datastore.create_role(name = r)
    #             db.session.commit()
    # except InterruptedError:
    #     db.session.rollback()

    user_datastore.find_or_create_role(name="User", description='Normal user')
    user_datastore.find_or_create_role(name="Shop", description='shop')
    user_datastore.find_or_create_role(name="Admin", description='admin')
    user_datastore.find_or_create_role(name="Super_admin",
                                       description='super admin')

    db.session.commit()

    if not user_datastore.get_user("*****@*****.**"):
        user_datastore.create_user(email="*****@*****.**", password="******")
        db.session.commit()
    if not user_datastore.get_user("*****@*****.**"):
        user_datastore.create_user(email="*****@*****.**", password="******")

    if not user_datastore.get_user('*****@*****.**'):
        user_datastore.create_user(email="*****@*****.**", password='******')
    #
    db.session.commit()

    user_datastore.add_role_to_user('*****@*****.**', 'User')
    user_datastore.add_role_to_user('*****@*****.**', 'Shop')
    user_datastore.add_role_to_user('*****@*****.**', 'Admin')
    #
    db.session.commit()
    try:
        category = {
            u"生物医药类": [u"生物类药物", u"疫苗", u"诊断试剂", u"医用材料", u"生物治疗"],
            u"生物能源类": [u"生物液体燃料", u"生物质气化固体燃料"],
            u"生物化工类": [u"生物基燃料", u"酶制剂", u"生物反应器"],
            u"生物农业类": [u"生物育种", u"生物农药", u"生物农制品", u"食品及化妆品添加剂"],
            u"生物环境类": [u"生物环保制品", u"污染检测", u"生物修复"]
        }
        for key, v in category.items():
            if Product_Category.query.filter_by(
                    category_name=key).first() == None:
                category_patent = Product_Category(category_name=key,
                                                   parent_id=0)
                db.session.add(category_patent)
                db.session.commit()
                for item in v:
                    if Product_Category.query.filter_by(
                            category_name=item).first() == None:
                        category_child = Product_Category(
                            category_name=item, parent_id=category_patent.id)
                        db.session.add(category_child)
                        db.session.commit()
            db.session.commit()
    except:
        db.session.rollback()
        current_app.logger.error(traceback.format_exc())
        abort(500, traceback.format_exc())