adding apns token catching
This commit is contained in:
parent
a23d797f90
commit
c770ac5c7d
@ -7,7 +7,7 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
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
|
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 import queue_run_user_playlist, offload_or_run_user_playlist
|
||||||
from music.cloud.tasks import update_all_user_playlists, update_playlists
|
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
|
return jsonify({"message": 'playlist updated', "status": "success"}), 200
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/user', methods=['GET', 'POST'])
|
@blueprint.route('/user', methods=['GET', 'POST'])
|
||||||
@login_or_jwt
|
@login_or_jwt
|
||||||
@no_locked_users
|
@no_locked_users
|
||||||
def user_route(auth=None, user=None):
|
def user_route(auth=None, user: User=None):
|
||||||
assert user is not None
|
assert user is not None
|
||||||
|
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
@ -222,6 +223,18 @@ def user_route(auth=None, user=None):
|
|||||||
if user.lastfm_username is None:
|
if user.lastfm_username is None:
|
||||||
user.lastfm_username = ""
|
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()
|
user.update()
|
||||||
|
|
||||||
logger.info(f'updated {user.username}')
|
logger.info(f'updated {user.username}')
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from fireo.models import Model
|
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
|
from music.model.playlist import Playlist
|
||||||
|
|
||||||
@ -32,6 +32,8 @@ class User(Model):
|
|||||||
|
|
||||||
lastfm_username = TextField()
|
lastfm_username = TextField()
|
||||||
|
|
||||||
|
apns_tokens = ListField(default=[])
|
||||||
|
|
||||||
def check_password(self, password):
|
def check_password(self, password):
|
||||||
return check_password_hash(self.password, password)
|
return check_password_hash(self.password, password)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user