Пример #1
0
def seed_db():
    """ Seed the database with test data"""
    from manager.models import db
    from manager.models import OAuth2Client
    from manager.models import User, UserConsent, UserRole
    from manager.auth import hash_pwd
    import time

    client = OAuth2Client(
        client_tag='stock',
        client_id='3MEZIcvlhMPiTEcy46spogzg',
        client_secret='POac9Sd4h0mrHZeXN9MljGB6oQRVJenKRnltCyDU10pvfHiX',
        supported_roles='connect admin warehouse',
        client_id_issued_at=int(time.time()))
    client_metadata = {
        "client_name":
        'Test client',
        "client_uri":
        'http://stock.maxilia.cloud',
        "grant_types": ['authorization_code'],
        "redirect_uris": [
            'http://127.0.0.1:9031', 'http://127.0.0.1:9032',
            'http://127.0.0.1:9035/authorize', 'http://stock.maxilia.cloud',
            'http://warehouse.maxilia.cloud'
        ],
        "response_types": ['code'],
        "scope":
        'openid profile email roles',
        "token_endpoint_auth_method":
        'client_secret_basic'
    }
    client.set_client_metadata(client_metadata)
    db.session.add(client)

    user = User(uuid='8c4205ba-85df-4708-87d4-28589bc7f5e9',
                login_id='53d205ba-85df-4708-87d4-28589bc7f5e3',
                username='******',
                password=hash_pwd('secret'),
                given_name='Wouter A.',
                family_name='Jong',
                middle_name='de',
                nickname='Wouter',
                email='*****@*****.**',
                locale='nl_NL',
                server_roles='connect admin')
    db.session.add(user)

    scope = UserConsent(client=client,
                        user=user,
                        scope='openid profile email roles')
    db.session.add(scope)

    role = UserRole(client=client,
                    user=user,
                    client_roles='connect admin warehouse[CM]')
    db.session.add(role)
    db.session.commit()
Пример #2
0
def user_password(user_id, password):
    """ Change user password """
    user = _find_user(user_id)
    if user is None:
        return 1
    if len(password) < 5:
        click.echo('Failed: Password must be at least 5 characters!')
        return 1
    user.password = hash_pwd(password)
    user.login_id = str(uuid4())
    db.session.commit()
    click.echo('Password for user %s has been changed.' % user.username)
Пример #3
0
def change_password_user(user_id):
    user = User.query.filter_by(uuid=user_id).first()
    form = ChangePasswordUserForm()
    if form.validate_on_submit():
        user.password = hash_pwd(form.password.data)
        db.session.commit()
        flash('Password changed!')
        return redirect(url_for('admin.user_details', user_id=user.uuid))

    return render_template('admin/change_password_user.html',
                           page='users',
                           current_user=current_user,
                           user=user,
                           form=form)
Пример #4
0
def create_user():
    form = CreateUserForm()
    if form.validate_on_submit():
        user = User(uuid=str(uuid4()),
                    login_id=str(uuid4()),
                    username=form.username.data,
                    given_name=form.given_name.data,
                    family_name=form.family_name.data,
                    middle_name=form.middle_name.data,
                    nickname=form.nickname.data,
                    email=form.email.data,
                    locale=form.locale.data,
                    password=hash_pwd(form.password.data),
                    server_roles='connect')
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('.list_users'))
    return render_template('admin/create_user.html',
                           current_user=current_user,
                           form=form)
Пример #5
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        user = current_user
        if user.is_active and verify_pwd(user.password,
                                         form.current_password.data):
            user.password = hash_pwd(form.password.data)
            db.session.commit()
            if 'next' in session:
                next_uri = session['next']
                del session['next']
            else:
                next_uri = url_for('.user_profile')
            flash('Password changed.')
            return redirect(next_uri)
        error = 'Invalid credentials'
        flash(error)
    return render_template('auth/change_pwd.html',
                           user=current_user,
                           form=form)