Beispiel #1
0
def delete_user(id):
    user = User.query.get(id)
    if user is None:
        abort(404, description="User not found")
    Calendar.query.filter_by(user_id=id).delete()
    Event.query.filter_by(author=id).delete()

    db.session.delete(user)
    db.session.commit()

    return user_schema.jsonify(user)
Beispiel #2
0
def update_user(user_id):
    user_data = request.args
    up_user = User.query.get(user_id)
    if User.query.filter_by(id=user_id).first() is None:
        abort(404, description="User not found")
    up_user.username = user_data.get('username')
    up_user.firstName = user_data.get('firstName')
    up_user.lastName = user_data.get('lastName')
    up_user.email = user_data.get('email')
    up_password = user_data.get('password')
    up_user.phone = user_data.get('phone')
    try:
        UserToCreate().load(user_data)
    except ValidationError:
        abort(400, description="Invalid Group")
    up_user.password = generate_password_hash(up_password)

    db.session.commit()
    return user_schema.jsonify(up_user)
Beispiel #3
0
def user_profile():
    return user_schema.jsonify(current_user)
Beispiel #4
0
def add_user():
    new_user = User()
    new_user.username = request.form['username']
    db.session.add(new_user)
    db.session.commit()
    return user_schema.jsonify(new_user)
def user_profile():
    return user_schema.jsonify(current_user)
Beispiel #6
0
def profile():
    if 'google_token' in session:
        me = google.get('userinfo')
        user = User.query.filter_by(email=me.data['email']).first_or_404()
        return user_schema.jsonify(user)
    return redirect(url_for('login'))
Beispiel #7
0
def get_user(id):
    if current_user.is_authenticated and current_user.id == id:
        return redirect(url_for('profile'))
    user = User.query.get_or_404(id)
    return user_schema.jsonify(user)