Beispiel #1
0
def delete(id):
    user = User.get(id)
    user.delete()

    return redirect(
        url_for('user.users')
    )
Beispiel #2
0
def load_loged_in_user():
    try:
        user_id = session["user_id"]
    except KeyError:
        user_id = None

    if user_id is None:
        g.user = None
    else:
        g.user = User.get(user_id)
Beispiel #3
0
def update(id):
    user = User.get(id)
    user_heads = dict(
        username_head,
        salary="Salario"
    )
    if request.method == "POST":
        user.username = request.form["username"]
        user.salary = request.form['salary']
        checked_permissions = get_checked_permissions()
        user.update_permissions(checked_permissions)
        error = user.request.update()
        if not error:
            return redirect(
                url_for('user.users')
            )
        flash(error)

    return render_template(
        "user/update.html",
        user_heads=user_heads,
        user=user
    )
Beispiel #4
0
def update_password(id):
    user = User.get(id)
    if request.method == "POST":
        password = request.form["password"]
        password_confirm = request.form["password_confirm"]
        if password != password_confirm:
            error = "Las contraseñas no coinciden"
        else:
            user.password = password
            error = user.validation.validate()
        if not error:
            from werkzeug.security import generate_password_hash
            user.password = generate_password_hash(user.password)
            user.update()
            return redirect(
                url_for('user.update', id=id)
            )
        flash(error)
    
    return render_template(
        'user/auth/update-password.html',
        password_heads=password_heads,
        user=user
    )
Beispiel #5
0
    def test_should_return_none_given_invalid_id(self):
        user = User.get(2)

        self.assertEqual(user, None)
Beispiel #6
0
    def test_should_return_user_given_valid_id(self):
        user = User.get(1)

        self.assertEqual(user, self.user)