def get_favorites(request): user = is_auth(request) response = {} if user is None: return auth_required_response() profile = user.get_profile() response['status_code'] = 200 response['response'] = [profile.favorites_to_dict()] return HttpResponse(simplejson.dumps(response), mimetype='application/json')
def authenticate_user(request): user = is_auth(request) response = {} if user is not None: if user.is_active: response['status_code'] = 200 response['response'] = "Successful authentication" else: response['status_code'] = 401 response['response'] = "Your account has been disabled" return HttpResponse(simplejson.dumps(response),mimetype="application/json") else: return auth_required_response()
def remove_user(request): user = is_auth(request) response = {} if user is not None: if user.is_active: user.delete() response['status_code'] = 200 response["response"] = "Successful account removal" else: response['status_code'] = 0 response["response"] = "Your account has been disabled" else: return auth_required_response() return HttpResponse(simplejson.dumps(response), mimetype="application/json")
def set_device(request): user = is_auth(request) if user is None: return auth_required_response() response = {} type = request.GET['type'] registration_id = request.GET['rid'] device = user.get_profile().device if device is None: user.get_profile().device = AndroidDevice.objects.create(registration_id=registration_id, collapse_key="") user.get_profile().save() else: device.registration_id = registration_id device.save() response['status_code'] = 200 response['response'] = "Device set successful" return HttpResponse(simplejson.dumps(response), mimetype='application/json')
def add_favorite_team(request): user = is_auth(request) response = {} if user is None: return auth_required_response() tid = request.GET['id'] try: team = Team.objects.get(pk=tid) except Team.DoesNotExist: response['status_code'] = 404 response["response"] = "Team id does not exist!" return HttpResponse(simplejson.dumps(response), mimetype="application/json") profile = user.get_profile() profile.favorite_teams.add(team) profile.save() response['status_code'] = 200 response["response"] = "Add favorite team successful!" return HttpResponse(simplejson.dumps(response), mimetype="application/json")
def add_favorite_player(request): user = is_auth(request) response = {} if user is None: return auth_required_response() pid = request.GET['id'] try: player = Player.objects.get(pk=pid) except Player.DoesNotExist: response['status_code'] = 404 response["response"] = "Player id does not exist!" return HttpResponse(simplejson.dumps(response), mimetype="application/json") profile = user.get_profile() profile.favorite_players.add(player) profile.save() response['status_code'] = 200 response["response"] = "Add favorite player successful!" return HttpResponse(simplejson.dumps(response), mimetype="application/json")
def add_favorite_event(request): user = is_auth(request) response = {} if user is None: return auth_required_response() eid = request.GET['id'] try: event = Event.objects.get(pk=eid) except Event.DoesNotExist: response['status_code'] = 404 response["response"] = "Event id does not exist!" return HttpResponse(simplejson.dumps(response), mimetype="application/json") profile = user.get_profile() profile.favorite_events.add(event) profile.save() response['status_code'] = 200 response["response"] = "Add favorite event successful!" return HttpResponse(simplejson.dumps(response), mimetype="application/json")