Пример #1
0
def new_user():
    form = NewUserForm()
    if form.validate_on_submit():
        username = form.username.data
        name = form.name.data
        email = form.email.data
        role_id = form.role.data
        company = form.company.data
        position = form.position.data
        phone = form.phone.data
        password = current_app.config['DEFAULT_PASSWORD']
        user = User(email=email,
                    username=username,
                    role_id=role_id,
                    company=company,
                    name=name,
                    position=position,
                    phone=phone,
                    confirmed=True)
        user.set_password(password)
        db.session.add(user)
        db.session.commit()
        send_notice_email(user)
        flash('邮件已发送', 'info')
        return redirect(url_for('.manage_user'))
    return render_template('admin/new_user.html', form=form)
Пример #2
0
    def init(password):
        """Initialize Blogs."""
        click.echo('Initializing the database...')
        db.create_all()

        click.echo('Initializing the roles and permissions...')
        Role.init_role()

        click.echo('Initializing the status...')
        Status.init_status()

        click.echo('Initializing the series...')
        Series.init_series()

        admin = User.query.first()
        if admin is not None:
            click.echo('The administrator already exists, updating...')
            admin.set_password(password)
        else:
            click.echo('Creating the temporary administrator account...')
            admin = User(email=app.config['ADMIN_EMAIL'], username='******', confirmed=True)
            admin.set_password(password)
            db.session.add(admin)

        db.session.commit()
        click.echo('Done.')
Пример #3
0
def fake_admin():
    admin = User(username='******',
                 confirmed=True,
                 name=fake.name(),
                 position=fake.job(),
                 phone=fake.phone_number(),
                 email='*****@*****.**')
    admin.set_password('12345678')
    db.session.add(admin)
    db.session.commit()
Пример #4
0
def fake_users(count=20):
    for i in range(count):
        user = User(name=fake.name(),
                    username=fake.user_name(),
                    confirmed=True,
                    email=fake.email(),
                    member_since=fake.date_this_decade(),
                    phone=fake.phone_number(),
                    position=fake.job(),
                    company=fake.company())
        user.set_password('12345678')
        db.session.add(user)
        try:
            db.session.commit()
        except IntegrityError:
            db.session.rollback()
Пример #5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = RegisterForm()
    if form.validate_on_submit():
        username = form.username.data
        name = form.name.data
        email = form.email.data.lower()  # 小写处理
        password = form.password.data
        company = form.company.data
        user = User(username=username, email=email, company=company, name=name)
        user.set_password(password)
        db.session.add(user)
        db.session.commit()
        send_confirm_email(user=user)
        flash('确认邮件已发送给系统管理员,请等待管理员确认', 'info')
        return redirect(url_for('.login'))
    return render_template('auth/register.html', form=form)