adding apns token catching

This commit is contained in:
Andy Pack 2022-11-28 18:34:29 +00:00
parent a23d797f90
commit c770ac5c7d
Signed by: sarsoo
GPG Key ID: A55BA3536A5E0ED7
2 changed files with 18 additions and 3 deletions

View File

@ -7,7 +7,7 @@ import json
import logging
from datetime import datetime
from music.api.decorators import login_or_jwt, login_required, login_or_jwt, \
from music.api.decorators import login_or_jwt, login_required, \
admin_required, cloud_task, validate_json, validate_args, spotify_link_required, no_locked_users
from music.cloud import queue_run_user_playlist, offload_or_run_user_playlist
from music.cloud.tasks import update_all_user_playlists, update_playlists
@ -184,10 +184,11 @@ def playlist_post_put_route(auth=None, user=None):
return jsonify({"message": 'playlist updated', "status": "success"}), 200
@blueprint.route('/user', methods=['GET', 'POST'])
@login_or_jwt
@no_locked_users
def user_route(auth=None, user=None):
def user_route(auth=None, user: User=None):
assert user is not None
if request.method == 'GET':
@ -222,6 +223,18 @@ def user_route(auth=None, user=None):
if user.lastfm_username is None:
user.lastfm_username = ""
if 'apns_token' in request_json:
token = request_json['apns_token']
if user.apns_tokens is None:
user.apns_tokens = []
if token not in user.apns_tokens:
logger.info(f'adding apns token {user.username} -> {token}')
user.apns_tokens = user.apns_tokens + [token]
else:
logger.info(f'skipping duplicate apns token {user.username} -> {token}')
user.update()
logger.info(f'updated {user.username}')

View File

@ -1,7 +1,7 @@
import logging
from fireo.models import Model
from fireo.fields import TextField, BooleanField, DateTime, NumberField
from fireo.fields import TextField, BooleanField, DateTime, NumberField, ListField
from music.model.playlist import Playlist
@ -32,6 +32,8 @@ class User(Model):
lastfm_username = TextField()
apns_tokens = ListField(default=[])
def check_password(self, password):
return check_password_hash(self.password, password)