Exemplo n.º 1
0
def user_del(id):
    try:
        user = User.get_by_id(id)
        user.delete()
    except Exception as e:
        return ApiResult({"r": 1, "msg": str(e)})
    return ApiResult(dict())
Exemplo n.º 2
0
    def test_get_by_id(self):
        """Get user by ID."""
        user = User("foo", "*****@*****.**", "123")
        user.save()

        retrieved = User.get_by_id(user.id)
        assert retrieved == user
Exemplo n.º 3
0
def load_user_from_request(request):
    token = request.headers.get("Authorization")
    try:
        user_id = verify_token(token)
        user = User.get_by_id(user_id)
        if user:
            return user
    except:
        return None
Exemplo n.º 4
0
def user_edit(user_id):
    user = User.get_by_id(user_id)
    form = UserForm(obj=user)
    if form.validate_on_submit():
        if not form.password.data:
            del form.password
        form.populate_obj(user)
        user.save()
        return redirect(url_for("dashboard.user", user_id=user_id))
    return render_template("user/edit.html", form=form)
Exemplo n.º 5
0
def user_edit(user_id):
    user = User.get_by_id(user_id)
    form = UserForm(obj=user)
    if form.validate_on_submit():
        if not form.password.data:
            del form.password

        form.populate_obj(user)
        user.save()
        selected_role = request.form.get(form.role.label.text)
        if selected_role != '0':
            selected_role = Role.query.filter(
                Role.name == selected_role).first()
            user_role = UserRole.query.filter(
                UserRole.user_id == current_user.id,
                UserRole.role_id >= selected_role.id).first()
            user_role = Role.query.filter(Role.id == user_role.role_id).first()
            if selected_role.permissions > user_role.permissions:
                flash('You have no access rights', "warning")
            else:
                UserRole.query.filter(UserRole.user_id == user.id).delete()
                UserRole.create(user_id=user.id, role_id=selected_role.id)
        return redirect(url_for("dashboard.user", user_id=user_id))
    return render_template("user/edit.html", form=form)
Exemplo n.º 6
0
 def user(self):
     return User.get_by_id(self.user_id)
Exemplo n.º 7
0
def user(user_id):
    user = User.get_by_id(user_id)
    addresses = user.addresses
    orders = Order.get_user_orders(user_id)
    context = {"user": user, "addresses": addresses, "orders": orders}
    return render_template("user/detail.html", **context)
Exemplo n.º 8
0
def load_user(user_id):
    """Load user by ID."""
    return User.get_by_id(int(user_id))