from django.shortcuts import render
from rest_framework import response
from rest_framework.serializers import Serializer
from . import serializers
from rest_framework.response import Response
from rest_framework.views import APIView
from django.views import View
from rest_framework import status
from . models import SaveList, User, Lyrics, SearchHistory, VerificationCode, SubmitLyrics
from rest_framework.permissions import BasePermission, IsAuthenticated, SAFE_METHODS, IsAdminUser
from rest_framework.authtoken.models import Token
from django.contrib.auth.hashers import make_password, check_password
from django.contrib.auth import login, authenticate
import requests
from django.db.models import Q
from bs4 import BeautifulSoup
import json
from datetime import datetime
import random
from django.core.mail import EmailMessage, EmailMultiAlternatives
from django.conf import settings
from django.template.loader import get_template
from django.urls import reverse
import jwt

from django.utils.encoding import force_bytes, force_text, DjangoUnicodeDecodeError
from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode
from django.contrib.sites.shortcuts import get_current_site
from .utils import Util
from rest_framework_simplejwt.tokens import RefreshToken
from django.template import Context
from django.http import HttpResponse, HttpResponseNotFound
import os
import re
import urllib

from datetime import datetime
import random
import time
now = datetime.now()

import json





class SignupView(APIView):
    now = datetime.now()
    def post(self, request, *args,**kwargs):
        user=User()
        try:

            User.objects.get(email=request.data['email'])
            return Response({"email":"already taken"})
        except:

            serializer=serializers.UserSerializer(data=request.data)
            if serializer.is_valid():
                password=make_password(request.data['password'])
                username=request.data['username']
                user.username=username
                user.first_name=request.data['first_name']
                user.last_name=request.data['last_name']
                user.email=request.data['email']
                user.email_username=request.data['email']
                user.password=password
                user.is_verified = False
                user.save()
                new_user=User.objects.get(id=user.id)
                token=Token.objects.create(user=new_user)
                verification = VerificationCode()
                code = random.randint(199999,999999)
                verification.code=code
                verification.user_id=new_user.id
                verification._year = now.year
                verification._month = now.month
                verification._day = now.day
                verification._hour = now.hour
                verification._minute = now.minute
                verification.save()
                from_e = settings.EMAIL_HOST_USER
                to=request.data['email']
                html = get_template('api/code.html')
                html_content = html.render({'username':new_user.username, 'code':code})
                text = 'Hi {username}, \n Please use {code} to continue with Lyriko.'
                subject = 'Confirm your email'
                email = EmailMultiAlternatives(
                    subject,
                    text,
                    from_e,
                    [to]
            )
                email.attach_alternative(html_content, 'text/html')
                try:
                    email.send()
                except:
                    pass
                token=Token.objects.get(user=user)
                response={'token':token.key, 'user':serializer.data}
                return Response(response)
            else:
                return Response(serializer.errors)


class SendCode(APIView):
    def post(self, request, *args, **kwargs):
        try:
            user = User.objects.get(email=request.data['email'])
            
        except:
            return Response({"error":"User not found."})
        try:
            v = VerificationCode.objects.get(user_id=user.id)
            v.delete()
        except:
            pass
        verification = VerificationCode()
        code = random.randint(199999,999999)
        verification.code=code
        verification.user_id=user.id
        verification._year = now.year
        verification._month = now.month
        verification._day = now.day
        verification._hour = now.hour
        verification._minute = now.minute
        verification.save()
        from_e = settings.EMAIL_HOST_USER
        to=request.data['email']
        html = get_template('api/code.html')
        html_content = html.render({'username':user.username, 'code':code})
        text = 'Hi {username}, \n Please use {code} to continue with Lyriko.'
        subject = 'Action Required'
        email = EmailMultiAlternatives(
            subject,
            text,
            from_e,
            [to]

        )
        email.attach_alternative(html_content, 'text/html')
        try:
            email.send()
        except:
            return Response({"error":"Error occured"})
        return Response({"success":"Success"})



class AccountActivation(APIView):
    permission_classes=[IsAuthenticated]
    def post(self, request, *args, **kwargs):
        user=User.objects.get(username=request.user.username)
        code=request.data['code']
        try:
            verification = VerificationCode.objects.get(user_id=user.id, code=int(code))
            user.is_verified=True
            user.save()
            verification.delete()
            return Response({'msg':'success'})
        except:
            return Response({'error':'Invalid code.'})

            
class VerifyUser(APIView):
    def post(self, request, *args, **kwargs):
        user = User.objects.get(email=request.data['email'])
        code = request.data['code']
        try:
            _code = VerificationCode.objects.get(code=int(code), user_id=user.id)
            _code.delete()
            return Response({"msg":"success"})
        except:
            return Response({"error":"invalid code"})
            

class CheckSaveList(APIView):
    permission_classes=[IsAuthenticated]
    def post(self, request, *args, **kwargs):
        try:
            if SaveList.objects.get(owner_username=request.user.username, lyrics_id=request.data['lyrics_id']):
                return Response({"watchlisted":'true'})
        except:
           return Response({"watchlisted":'false'}) 


class LyricsView(APIView):
    
    def get(self, request, *args, **kwargs):
        if request.method=='GET':
            lyrics_items=Lyrics.objects.all()
            serializer = serializers.LyricsSerializer(lyrics_items,many=True)
            response={'lyrics':serializer.data}
            return Response(response, status=status.HTTP_200_OK)
        else:
            response={'error':'Forbidden'}
            return Response(response, status=status.HTTP_400_BAD_REQUEST)


class AddLyricsView(APIView):
    permission_classes=[IsAuthenticated]
    def post(self, request, *args, **kwargs):
        if request.method=='POST':
            data=request.data
            lyrics=Lyrics()
            serializer=serializers.LyricsSerializer(data=data)
            if serializer.is_valid():
                lyrics.title=request.POST['title']
                lyrics.artist=request.POST['artist']
                lyrics.body=request.POST['body']
                lyrics.title_slug=request.POST['title'].replace(' ', '-').lower()
                lyrics.artist_slug=request.POST['artist'].replace(' ', '-').lower()
                response={'lyrics':serializer.data}
                return Response(response,status=status.HTTP_200_OK )
            else:
                return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class SingleLyricsView(APIView):
    def post(self, request, *args, **kwargs ):
        artist = request.data['artist'].strip().replace("-"," ").title()
        title=request.data['title'].strip().replace("-"," ").title()
        search_history=SearchHistory()
        title_clean1=request.data['title'].strip().replace("ain-t", "aint")
        title_clean2=title_clean1.replace('you-re', 'youre')
        title_cleean3 = title_clean2.replace('isn-t', 'isnt')
        title_clean4  =title_cleean3.replace('aren-t', 'arent')
        title_clean_5= title_clean4.replace("weren-t","werent")
        title_clean6 = title_clean_5.replace("can-t", "cant")
        title_clean7 = title_clean6.replace('don-t', 'dont')
        title_clean8 = title_clean7.replace('i-d', 'id').replace('i-ve', 'ive').replace('we-ve','weve',).replace('you-ve', 'youve').replace('he-s', 'hes').replace('she-s', 'shes').replace('it-s', 'its',).replace('you-d', 'youd').replace('i-ll', 'ill').replace("you-ll", "youll").replace('let-s', "lets").replace("amn't", "amnt").replace("haven-t","havent")
        try:
            lyrics_item=Lyrics.objects.get(artist_slug=request.data['artist'], title_slug__icontains=title_clean8)
            views = lyrics_item.views
            updt_views=views+1
            lyrics_item.views = updt_views
            lyrics_item.save()
            serializer=serializers.LyricsSerializer(lyrics_item, many=False)
            response={'lyrics':serializer.data}
            ### Record activities ###
            search_history.searcher_username = request.data['username']
            search_history.artist=artist.replace('-',' ')
            search_history.title=title.replace('-',' ')
            search_history.save()
            return Response(response,status=status.HTTP_200_OK)

        except Lyrics.DoesNotExist:
            return Response({"error":"Not Found"})



        
               

class SearchHistoryView(APIView):
    permission_classes=[IsAuthenticated]
    def get(self, request, *args, **kwargs ):
        search_history_items=SearchHistory.objects.filter(searcher_username=request.user.username).order_by('-moment').all()
        serializer=serializers.SearchHistorySerializer(search_history_items, many=True)
        response={"search_history":serializer.data}
        return Response(response,status=status.HTTP_200_OK)

class DeleteHistory(APIView):
    permission_classes=[IsAuthenticated]
    def post(self, request, *args, **kwargs):
        searcher_username = request.user.username
        history_item_id = request.data['id']
        try:
            SearchHistory.objects.get(searcher_username=searcher_username, id=history_item_id).delete()
            
            return Response({"msg":"OK"})
        except:
            return Response({"msg":"Something went wrong"})
        
        

class TrendingView(APIView):
    def get(self, request, *args, **kwargs):
        lyrics=Lyrics.objects.order_by('-views')[0:35]
        serializer=serializers.LyricsSerializer(lyrics, many=True)
        response={"top":serializer.data}
        return Response(response)


class RandomView(APIView):
    def get(self, request,*args, **kwargs, ):
        lyrics=Lyrics.objects.all()
        lyrics_items=[]
        for lyric in lyrics:
            lyrics_items.append(lyric)
        random_lyrics=random.choice(lyrics_items)
        serializer=serializers.LyricsSerializer(random_lyrics)
        resp={"lyrics":serializer.data}
        return Response(resp)

class RecentView(APIView):
    def get(self, request, *args, **kwargs):
        recent_items=SearchHistory.objects.order_by('-moment').all()[:20]
        recent = []
        for i in recent_items:
            recent.append(i)
        serializer=serializers.SearchHistorySerializer(recent, many=True)
        resp={"recent":serializer.data}
        return Response(resp)

class SuggestionView(APIView):
    def post(self, request, *args, **kwargs):
        _type=request.data['type']
        if _type=="title":
            lyrics=Lyrics.objects.filter(title__contains=request.data['title'])
            serializer=serializers.LyricsSerializer(lyrics, many=True)
            resp={'suggestions':serializer.data}
            return Response(resp)
        else:
            lyrics=Lyrics.objects.filter(artist__contains=request.data['artist'])
            serializer=serializers.LyricsSerializer(lyrics, many=True)
            resp={'suggestions':serializer.data}
            return Response(resp)


class ChangePassword(APIView):
    def post(self, request, *args, **kwargs):
        if request.data['access'] == "code":
            try:
                user = User.objects.get(email=request.data['email'])
            except:
                pass
            user.password = make_password(request.data['new_password'])
            user.save()
            return Response({"msg":"success"})
        else:
            user = User.objects.get(username=request.user.username)
            current_password  = request.data['current_password']
            if check_password(current_password, user.password):
                user.password = make_password(request.data['new_password'])
                user.save()
                return Response({"success":"Password changed"})
            else:
                return Response({"error":"Incorrect password"})


class modifyUser(APIView):
    permission_classes=[IsAuthenticated]
    def post(self, request, *args, **kwargs):
        user = User.objects.get(pk=request.user.id)
        new_email = request.data['email']
        old_email = user.email
        if new_email != old_email:
            user.is_verified = False
        user.username = request.data['username']
        user.email = new_email
        user.first_name = request.data['first_name']
        user.last_name = request.data['last_name']
        user.save()
        n_user = User.objects.get(id=request.user.id)
        serializer=serializers.UserSerializer(user, many=False)
        response={'user':serializer.data}
        return Response(response)



        



        


            
                    
''' class EditLyricsView(APIView):
    def post(self, request, pk, *args, **kwargs ):
        data=request.data
        lyrics=Lyrics.objects.get(pk=pk)
        lyrics.title=request.POST['title']
        lyrics.artist=request.POST['artist']
        lyrics.body=request.POST['body']
        Lyrics.objects.get(pk=pk)
        lyrics.save()
        lyrics_item=Lyrics.objects.get(pk=pk)
        serializer=serializers.LyricsSerializer(lyrics_item,many=False)
        response={'lyrics':serializer.data}
        return Response(response,status=status.HTTP_200_OK ) '''

class SaveListView(APIView):
    permission_classes=[IsAuthenticated]
    def get(self, request, *args, **kwargs):
        save_list_items=SaveList.objects.filter(owner_username=request.user.username)
        save_list=[]
        for i in save_list_items:
            lyrics = Lyrics.objects.get(pk=i.lyrics_id)
            save_list.append(lyrics)
        serializer = serializers.LyricsSerializer(save_list, many=True)
        
        return Response({'lyrics':serializer.data}, status=status.HTTP_200_OK)

class AddSaveListView(APIView):
    permission_classes=[IsAuthenticated]
    
    def post(self, request, *args, **kwargs):
        items=SaveList.objects.filter(owner_username=request.user.username)
        data=request.data
        username=request.user.username
        savelist=SaveList()
        try:
            if SaveList.objects.get(owner_username=request.user.username, lyrics_id=request.data['lyrics_id']):
                return Response({"Error":"Cannot add lyrics to Save List twice or more."})
        except:

            savelist.lyrics_id=request.data['lyrics_id']
            savelist.owner_username=username
            savelist.save()
            save_list_items=SaveList.objects.filter(owner_username=request.user.username)
            save_list = []
            for save_list_item in save_list_items:
                sl = Lyrics.objects.get(pk=save_list_item.lyrics_id)
                save_list.append(sl)

            serializer = serializers.LyricsSerializer(save_list, many=True)
            response={'save_list':serializer.data}
            return Response(response, status=status.HTTP_200_OK)


class RemoveSaveListView(APIView):
    permission_classes=[IsAuthenticated]
    def post(self, request, *args, **kwargs):
        owner_username=request.user.username
        lyrics_id=request.data['lyrics_id']
        save_list_item=SaveList.objects.get(owner_username=owner_username, lyrics_id=lyrics_id)
        save_list_item.delete()
        save_list_items=SaveList.objects.filter(owner_username=request.user.username)
        save_list = []
        for save_list_item in save_list_items:
            sl = Lyrics.objects.get(pk=save_list_item.lyrics_id)
            save_list.append(sl)

        serializer = serializers.LyricsSerializer(save_list, many=True)
        response={'save_list':serializer.data}
        return Response(response, status=status.HTTP_200_OK)

class CheckUserView(APIView):
    def post(self, request, *args, **kwargs):
        try:
            User.objects.get(username=request.data['username'])
            return Response({'true'}, status=status.HTTP_200_OK)
        except User.DoesNotExist:
            return Response({'false'})



""" class SignupView(APIView):
    def post(self, request, *args, **kwargs):
        user=User()
        serializer=serializers.UserSerializer(data=request.data)
        print(request.data)
        if serializer.is_valid():
            password=make_password(request.data['password'])
            username=request.data['username']
            user.username=username
            user.first_name=request.data['first_name']
            user.last_name=request.data['last_name']
            user.email=request.data['email']
            user.email_username=request.data['email']
            user.password=password
            user.save()
            new_user=User.objects.get(username=username)
            print(new_user)
            token=Token.objects.create(user=new_user)
            response={'token':token.key, 'user':serializer.data}
            return Response(response, status=status.HTTP_200_OK)
        else:
            return Response(serializer.errors) """

class UserDataView(APIView):
    permission_classes=[IsAuthenticated]
    def get(self, request, *args, **kwargs):
        user=User.objects.get(username=request.user.username)
        serializer=serializers.UserSerializer(user, many=False)
        response={'user':serializer.data}
        return Response(response, status=status.HTTP_200_OK)

class SigninView(APIView):
    def post(self, request, *args, **kwargs):
        password=request.data['password']
        username=request.data['username']
        try:
            if '@' not in username:
                user=User.objects.get(username=username)
            elif '@' in username:
                user=User.objects.get(email_username=username)
        except:
               return Response({'error':'User not found.'}) 
        if check_password(password, user.password):
            login(self.request, user)
            token=Token.objects.get(user=user)
            serializer=serializers.UserSerializer(user, many=False)
            response={'user':serializer.data, 'token':token.key}
            return Response(response, status=status.HTTP_200_OK)
        else:
            return Response({'error':'Incorrect password'})

class SubmitLyricsv(APIView):
    def post(self, request, *args, **kwargs):
        serializer = serializers.SubmitLyricsSerializer(data=request.data)
        if serializer.is_valid:
            sl=SubmitLyrics()
            sl.title=request.data['title']
            sl.artist=request.data['artist']
            sl.body=request.data['body']
            sl.save()
            response = {"msg":"OK"}
            return Response(response)
        else:
            return Response({serializers.errors})

class ApproveSubmitLyrics(APIView):
    permission_classes=[IsAuthenticated]
    def post(self, request, *args, **kwargs):
        user = request.user
        if user.is_lyrics_admin != True:
            return Response({"Error":"Forbidden"})
        else:
            lyrics = Lyrics()
            lyrics.artist = request.data['artist']
            lyrics.artist_slug = request.data['artist'].strip().replace(" ","-").lower()
            lyrics.title = request.data['title']
            lyrics.title_slug=request.data['title'].strip().replace(" ","-").lower()
            lyrics.body = request.data['body']
            lyrics.save()
            sl = SubmitLyrics.objects.get(id=request.data['id']).delete()
            return Response({"msg":"OK"})

class SubmitLyricsListView(APIView):
    permission_classes=[IsAuthenticated]
    def get(self, request, *args, **kwargs):
        user=request.user
        if user.is_lyrics_admin != True:
            return Response({"Error":"Forbidden"})
        else:
            sub = SubmitLyrics.objects.all()
            serializer = serializers.SubmitLyricsSerializer(sub, many=True)
            res = {"submit_lyrics_view":serializer.data}
            return Response(res)

class SubmitLyricsView(APIView):
    permission_classes=[IsAuthenticated]
    def post(self, request, *args, **kwargs):
        user = request.user
        if user.is_lyrics_admin != True:
            return Response({"Error":"Forbidden"})
        else:
            item = SubmitLyrics.objects.get(id=request.data['id'])
            serializer = serializers.SubmitLyricsSerializer(item, many=False)
            res = {"submit_lyrics_item":serializer.data}
            return Response(res)

class DeclineSubmitLyrics(APIView):
    def post(self, request, *args, **kwargs):
        user = request.user
        if user.is_lyrics_admin != True:
            return Response({"Error":"Forbidden"})
        else:
            item = SubmitLyrics.objects.get(id=request.data['id'])
            item.delete()
            return Response({"msg":"OK"})


class RelatedView(APIView):
    def post(self, request,  *args, **kwargs):
        lyrics = Lyrics.objects.filter(artist_slug=request.data['artist'])[0:10]
        serializer=serializers.LyricsSerializer(lyrics, many=True)
        response={"top":serializer.data}
        return Response(response) 
        
        

class SearchViewv(APIView):
    def post(self, request, *args, **kwargs):
        if request.data['term']:
            term=request.data['term']
            terms = term.split()
            results =[]
            for i in terms:
                if i!="by":
                    for j in Lyrics.objects.filter(title__icontains=i):
                        results.append(j)
                    for k in Lyrics.objects.filter(artist__icontains=i):
                        results.append(k)
            search_res = [i for j, i in enumerate(results) if i not in results[:j]]
            serializer=serializers.LyricsSerializer(search_res, many=True)
            response={"result":serializer.data}
            return Response(response)
        else:
            return Response({"error":"Unavailable"})




        




        

        
   
""" data = requests.get(f"https://api.lyrics.ovh/v1/{artistSlug}/{titleSlug}/")
                lyric =  data.json()
                if data.status_code == 200:
                    lyrics.title=title
                    lyrics.artist=artist
                    lyrics.title_slug=titleSlug
                    lyrics.artist_slug=artistSlug
                    lyrics.body=lyric['lyrics']
                    lyrics.save()
                    lyrics_item=Lyrics.objects.get(title_slug=title_slug, artist_slug=artist_slug)
                
                    searchHistory.lyrics_id = lyrics_item.id
                    searchHistory.searcher_username = request.user.username
                    searchHistory.moment=now.strftime('%Y-%m-%d %H:%M:%S')
                    searchHistory.save()

                    serializer=serializers.LyricsSerializer(lyrics_item, many=False)
                    response={'lyrics':serializer.data}
                    return Response(response,status=status.HTTP_200_OK ) """




[((40, 6, 40, 20), 'datetime.datetime.now', 'datetime.now', ({}, {}), '()', False, 'from datetime import datetime\n'), ((49, 10, 49, 24), 'datetime.datetime.now', 'datetime.now', ({}, {}), '()', False, 'from datetime import datetime\n'), ((119, 15, 119, 44), 'random.randint', 'random.randint', ({(119, 30, 119, 36): '199999', (119, 37, 119, 43): '999999'}, {}), '(199999, 999999)', False, 'import random\n'), ((130, 15, 130, 44), 'django.template.loader.get_template', 'get_template', ({(130, 28, 130, 43): '"""api/code.html"""'}, {}), "('api/code.html')", False, 'from django.template.loader import get_template\n'), ((134, 16, 140, 9), 'django.core.mail.EmailMultiAlternatives', 'EmailMultiAlternatives', ({(135, 12, 135, 19): 'subject', (136, 12, 136, 16): 'text', (137, 12, 137, 18): 'from_e', (138, 12, 138, 16): '[to]'}, {}), '(subject, text, from_e, [to])', False, 'from django.core.mail import EmailMessage, EmailMultiAlternatives\n'), ((146, 15, 146, 46), 'rest_framework.response.Response', 'Response', ({(146, 24, 146, 45): "{'success': 'Success'}"}, {}), "({'success': 'Success'})", False, 'from rest_framework.response import Response\n'), ((261, 15, 261, 59), 'rest_framework.response.Response', 'Response', (), '', False, 'from rest_framework.response import Response\n'), ((282, 15, 282, 33), 'rest_framework.response.Response', 'Response', ({(282, 24, 282, 32): 'response'}, {}), '(response)', False, 'from rest_framework.response import Response\n'), ((291, 22, 291, 49), 'random.choice', 'random.choice', ({(291, 36, 291, 48): 'lyrics_items'}, {}), '(lyrics_items)', False, 'import random\n'), ((294, 15, 294, 29), 'rest_framework.response.Response', 'Response', ({(294, 24, 294, 28): 'resp'}, {}), '(resp)', False, 'from rest_framework.response import Response\n'), ((304, 15, 304, 29), 'rest_framework.response.Response', 'Response', ({(304, 24, 304, 28): 'resp'}, {}), '(resp)', False, 'from rest_framework.response import Response\n'), ((358, 15, 358, 33), 'rest_framework.response.Response', 'Response', ({(358, 24, 358, 32): 'response'}, {}), '(response)', False, 'from rest_framework.response import Response\n'), ((395, 15, 395, 78), 'rest_framework.response.Response', 'Response', (), '', False, 'from rest_framework.response import Response\n'), ((439, 15, 439, 60), 'rest_framework.response.Response', 'Response', (), '', False, 'from rest_framework.response import Response\n'), ((480, 15, 480, 60), 'rest_framework.response.Response', 'Response', (), '', False, 'from rest_framework.response import Response\n'), ((493, 11, 493, 50), 'django.contrib.auth.hashers.check_password', 'check_password', ({(493, 26, 493, 34): 'password', (493, 36, 493, 49): 'user.password'}, {}), '(password, user.password)', False, 'from django.contrib.auth.hashers import make_password, check_password\n'), ((573, 15, 573, 33), 'rest_framework.response.Response', 'Response', ({(573, 24, 573, 32): 'response'}, {}), '(response)', False, 'from rest_framework.response import Response\n'), ((55, 19, 55, 54), 'rest_framework.response.Response', 'Response', ({(55, 28, 55, 53): "{'email': 'already taken'}"}, {}), "({'email': 'already taken'})", False, 'from rest_framework.response import Response\n'), ((160, 19, 160, 46), 'rest_framework.response.Response', 'Response', ({(160, 28, 160, 45): "{'msg': 'success'}"}, {}), "({'msg': 'success'})", False, 'from rest_framework.response import Response\n'), ((172, 19, 172, 46), 'rest_framework.response.Response', 'Response', ({(172, 28, 172, 45): "{'msg': 'success'}"}, {}), "({'msg': 'success'})", False, 'from rest_framework.response import Response\n'), ((194, 19, 194, 64), 'rest_framework.response.Response', 'Response', (), '', False, 'from rest_framework.response import Response\n'), ((197, 19, 197, 73), 'rest_framework.response.Response', 'Response', (), '', False, 'from rest_framework.response import Response\n'), ((245, 19, 245, 63), 'rest_framework.response.Response', 'Response', (), '', False, 'from rest_framework.response import Response\n'), ((271, 19, 271, 41), 'rest_framework.response.Response', 'Response', ({(271, 28, 271, 40): "{'msg': 'OK'}"}, {}), "({'msg': 'OK'})", False, 'from rest_framework.response import Response\n'), ((313, 19, 313, 33), 'rest_framework.response.Response', 'Response', ({(313, 28, 313, 32): 'resp'}, {}), '(resp)', False, 'from rest_framework.response import Response\n'), ((318, 19, 318, 33), 'rest_framework.response.Response', 'Response', ({(318, 28, 318, 32): 'resp'}, {}), '(resp)', False, 'from rest_framework.response import Response\n'), ((328, 28, 328, 71), 'django.contrib.auth.hashers.make_password', 'make_password', ({(328, 42, 328, 70): "request.data['new_password']"}, {}), "(request.data['new_password'])", False, 'from django.contrib.auth.hashers import make_password, check_password\n'), ((330, 19, 330, 46), 'rest_framework.response.Response', 'Response', ({(330, 28, 330, 45): "{'msg': 'success'}"}, {}), "({'msg': 'success'})", False, 'from rest_framework.response import Response\n'), ((334, 15, 334, 62), 'django.contrib.auth.hashers.check_password', 'check_password', ({(334, 30, 334, 46): 'current_password', (334, 48, 334, 61): 'user.password'}, {}), '(current_password, user.password)', False, 'from django.contrib.auth.hashers import make_password, check_password\n'), ((445, 19, 445, 64), 'rest_framework.response.Response', 'Response', (), '', False, 'from rest_framework.response import Response\n'), ((494, 12, 494, 37), 'django.contrib.auth.login', 'login', ({(494, 18, 494, 30): 'self.request', (494, 32, 494, 36): 'user'}, {}), '(self.request, user)', False, 'from django.contrib.auth import login, authenticate\n'), ((495, 18, 495, 46), 'rest_framework.authtoken.models.Token.objects.get', 'Token.objects.get', (), '', False, 'from rest_framework.authtoken.models import Token\n'), ((498, 19, 498, 64), 'rest_framework.response.Response', 'Response', (), '', False, 'from rest_framework.response import Response\n'), ((500, 19, 500, 59), 'rest_framework.response.Response', 'Response', ({(500, 28, 500, 58): "{'error': 'Incorrect password'}"}, {}), "({'error': 'Incorrect password'})", False, 'from rest_framework.response import Response\n'), ((512, 19, 512, 37), 'rest_framework.response.Response', 'Response', ({(512, 28, 512, 36): 'response'}, {}), '(response)', False, 'from rest_framework.response import Response\n'), ((514, 19, 514, 49), 'rest_framework.response.Response', 'Response', ({(514, 28, 514, 48): '{serializers.errors}'}, {}), '({serializers.errors})', False, 'from rest_framework.response import Response\n'), ((521, 19, 521, 50), 'rest_framework.response.Response', 'Response', ({(521, 28, 521, 49): "{'Error': 'Forbidden'}"}, {}), "({'Error': 'Forbidden'})", False, 'from rest_framework.response import Response\n'), ((531, 19, 531, 41), 'rest_framework.response.Response', 'Response', ({(531, 28, 531, 40): "{'msg': 'OK'}"}, {}), "({'msg': 'OK'})", False, 'from rest_framework.response import Response\n'), ((538, 19, 538, 50), 'rest_framework.response.Response', 'Response', ({(538, 28, 538, 49): "{'Error': 'Forbidden'}"}, {}), "({'Error': 'Forbidden'})", False, 'from rest_framework.response import Response\n'), ((543, 19, 543, 32), 'rest_framework.response.Response', 'Response', ({(543, 28, 543, 31): 'res'}, {}), '(res)', False, 'from rest_framework.response import Response\n'), ((550, 19, 550, 50), 'rest_framework.response.Response', 'Response', ({(550, 28, 550, 49): "{'Error': 'Forbidden'}"}, {}), "({'Error': 'Forbidden'})", False, 'from rest_framework.response import Response\n'), ((555, 19, 555, 32), 'rest_framework.response.Response', 'Response', ({(555, 28, 555, 31): 'res'}, {}), '(res)', False, 'from rest_framework.response import Response\n'), ((561, 19, 561, 50), 'rest_framework.response.Response', 'Response', ({(561, 28, 561, 49): "{'Error': 'Forbidden'}"}, {}), "({'Error': 'Forbidden'})", False, 'from rest_framework.response import Response\n'), ((565, 19, 565, 41), 'rest_framework.response.Response', 'Response', ({(565, 28, 565, 40): "{'msg': 'OK'}"}, {}), "({'msg': 'OK'})", False, 'from rest_framework.response import Response\n'), ((592, 19, 592, 37), 'rest_framework.response.Response', 'Response', ({(592, 28, 592, 36): 'response'}, {}), '(response)', False, 'from rest_framework.response import Response\n'), ((594, 19, 594, 52), 'rest_framework.response.Response', 'Response', ({(594, 28, 594, 51): "{'error': 'Unavailable'}"}, {}), "({'error': 'Unavailable'})", False, 'from rest_framework.response import Response\n'), ((112, 19, 112, 56), 'rest_framework.response.Response', 'Response', ({(112, 28, 112, 55): "{'error': 'User not found.'}"}, {}), "({'error': 'User not found.'})", False, 'from rest_framework.response import Response\n'), ((145, 19, 145, 54), 'rest_framework.response.Response', 'Response', ({(145, 28, 145, 53): "{'error': 'Error occured'}"}, {}), "({'error': 'Error occured'})", False, 'from rest_framework.response import Response\n'), ((162, 19, 162, 54), 'rest_framework.response.Response', 'Response', ({(162, 28, 162, 53): "{'error': 'Invalid code.'}"}, {}), "({'error': 'Invalid code.'})", False, 'from rest_framework.response import Response\n'), ((174, 19, 174, 53), 'rest_framework.response.Response', 'Response', ({(174, 28, 174, 52): "{'error': 'invalid code'}"}, {}), "({'error': 'invalid code'})", False, 'from rest_framework.response import Response\n'), ((182, 23, 182, 55), 'rest_framework.response.Response', 'Response', ({(182, 32, 182, 54): "{'watchlisted': 'true'}"}, {}), "({'watchlisted': 'true'})", False, 'from rest_framework.response import Response\n'), ((184, 18, 184, 51), 'rest_framework.response.Response', 'Response', ({(184, 27, 184, 50): "{'watchlisted': 'false'}"}, {}), "({'watchlisted': 'false'})", False, 'from rest_framework.response import Response\n'), ((214, 23, 214, 68), 'rest_framework.response.Response', 'Response', (), '', False, 'from rest_framework.response import Response\n'), ((216, 23, 216, 86), 'rest_framework.response.Response', 'Response', (), '', False, 'from rest_framework.response import Response\n'), ((248, 19, 248, 50), 'rest_framework.response.Response', 'Response', ({(248, 28, 248, 49): "{'error': 'Not Found'}"}, {}), "({'error': 'Not Found'})", False, 'from rest_framework.response import Response\n'), ((273, 19, 273, 59), 'rest_framework.response.Response', 'Response', ({(273, 28, 273, 58): "{'msg': 'Something went wrong'}"}, {}), "({'msg': 'Something went wrong'})", False, 'from rest_framework.response import Response\n'), ((335, 32, 335, 75), 'django.contrib.auth.hashers.make_password', 'make_password', ({(335, 46, 335, 74): "request.data['new_password']"}, {}), "(request.data['new_password'])", False, 'from django.contrib.auth.hashers import make_password, check_password\n'), ((337, 23, 337, 63), 'rest_framework.response.Response', 'Response', ({(337, 32, 337, 62): "{'success': 'Password changed'}"}, {}), "({'success': 'Password changed'})", False, 'from rest_framework.response import Response\n'), ((339, 23, 339, 63), 'rest_framework.response.Response', 'Response', ({(339, 32, 339, 62): "{'error': 'Incorrect password'}"}, {}), "({'error': 'Incorrect password'})", False, 'from rest_framework.response import Response\n'), ((407, 23, 407, 90), 'rest_framework.response.Response', 'Response', ({(407, 32, 407, 89): "{'Error': 'Cannot add lyrics to Save List twice or more.'}"}, {}), "({'Error': 'Cannot add lyrics to Save List twice or more.'})", False, 'from rest_framework.response import Response\n'), ((421, 19, 421, 64), 'rest_framework.response.Response', 'Response', (), '', False, 'from rest_framework.response import Response\n'), ((447, 19, 447, 38), 'rest_framework.response.Response', 'Response', ({(447, 28, 447, 37): "{'false'}"}, {}), "({'false'})", False, 'from rest_framework.response import Response\n'), ((492, 22, 492, 59), 'rest_framework.response.Response', 'Response', ({(492, 31, 492, 58): "{'error': 'User not found.'}"}, {}), "({'error': 'User not found.'})", False, 'from rest_framework.response import Response\n'), ((60, 25, 60, 64), 'django.contrib.auth.hashers.make_password', 'make_password', ({(60, 39, 60, 63): "request.data['password']"}, {}), "(request.data['password'])", False, 'from django.contrib.auth.hashers import make_password, check_password\n'), ((71, 22, 71, 57), 'rest_framework.authtoken.models.Token.objects.create', 'Token.objects.create', (), '', False, 'from rest_framework.authtoken.models import Token\n'), ((73, 23, 73, 52), 'random.randint', 'random.randint', ({(73, 38, 73, 44): '199999', (73, 45, 73, 51): '999999'}, {}), '(199999, 999999)', False, 'import random\n'), ((84, 23, 84, 52), 'django.template.loader.get_template', 'get_template', ({(84, 36, 84, 51): '"""api/code.html"""'}, {}), "('api/code.html')", False, 'from django.template.loader import get_template\n'), ((88, 24, 93, 13), 'django.core.mail.EmailMultiAlternatives', 'EmailMultiAlternatives', ({(89, 20, 89, 27): 'subject', (90, 20, 90, 24): 'text', (91, 20, 91, 26): 'from_e', (92, 20, 92, 24): '[to]'}, {}), '(subject, text, from_e, [to])', False, 'from django.core.mail import EmailMessage, EmailMultiAlternatives\n'), ((99, 22, 99, 50), 'rest_framework.authtoken.models.Token.objects.get', 'Token.objects.get', (), '', False, 'from rest_framework.authtoken.models import Token\n'), ((101, 23, 101, 41), 'rest_framework.response.Response', 'Response', ({(101, 32, 101, 40): 'response'}, {}), '(response)', False, 'from rest_framework.response import Response\n'), ((103, 23, 103, 50), 'rest_framework.response.Response', 'Response', ({(103, 32, 103, 49): 'serializer.errors'}, {}), '(serializer.errors)', False, 'from rest_framework.response import Response\n')]