Exemple #1
0
def register():
    '''User registration routine'''
    
    if current_user.is_authenticated:
        return redirect(url_for('dashboard'))

    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        login_user(user)
        app.logger.info(repr(user) + ' registration successful')
        return redirect(url_for('dashboard'))

    return render_template('registration.html', form=form)
Exemple #2
0
def example_admin():
    admin = User()
    admin.first_name = "Example"
    admin.last_name = "Admin"
    admin.email_address = "*****@*****.**"
    admin.password = "******"
    admin.admin = True
    return admin
Exemple #3
0
def create():
    json = request.get_json()
    try:
        data = UserSchema().load(json)
    except ValidationError as e:
        return jsonify(error="validation failed", fields=e.messages), 422
    user = User(**data)
    db.session.add(user)
    db.session.commit()
    return jsonify(UserSchema().dump(user))
Exemple #4
0
def example_user():
    u1 = User()
    u1.first_name = "Example"
    u1.last_name = "User"
    u1.email_address = "*****@*****.**"
    u1.password = "******"
    return u1
Exemple #5
0
def read(user_id):
    # TODO: add user.is_self or user.is_manager
    user = User.get(user_id)
    if not user:
        return jsonify(error="user not found"), 404
    return jsonify(user=UserSchema().dump(user))
Exemple #6
0
def _list():
    users = User.query().all()
    return jsonify(users=UserSchema().dump(users, many=True))
Exemple #7
0
def john():
    user = User(first_name="John",
                last_name="Doe",
                email_address=u"*****@*****.**")
    user.password = "******"
    return user
Exemple #8
0
def test_user_find_by_credentials(db_session):
    user = data.example_user()
    db_session.add(user)
    db_session.commit()
    assert user is User.by_credentials(email="*****@*****.**",
                                       password="******")
Exemple #9
0
def test_hash_password():
    u_hash = User._hash_password("secret123", salt=b"abcdef")
    assert (u_hash ==
            "bef57ec7f53a6d40beb640a780a639c83bc29ac8a9816f1fc6c5c6dcd93c47212"
            "72b82aa344691fb4037f20617b1d19212042e7e6cb39f4ba0dad95d8137104a")
    assert isinstance(u_hash, str)