from django.shortcuts import render
from django.contrib.auth import login
from rest_framework import generics,permissions
from rest_framework.response import Response
from rest_framework.authtoken.serializers import AuthTokenSerializer
from knox.views import LoginView as KnoxLoginView
from knox.auth import AuthToken
from .serializer import *
from .models import *
from django.core.mail import EmailMessage

def send_email(request):
    pass

class RegisterView(generics.GenericAPIView):
    serializer_class = RegisterSerializer
    def post(self,request,*args,**kwargs):
        serializer=self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user=serializer.save()
        return Response(
            {
            "user":UserSerializer(user,context=self.get_serializer_context()).data,
            "token":AuthToken.objects.create(user)[1]
        }
        )
class LoginView(KnoxLoginView):
    permission_classes =(permissions.AllowAny,)
    def post(self, request, format=None):
        serializer=AuthTokenSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user=serializer.validated_data['user']
        login(request, user)
        return super(LoginView, self).post(request, format=None)

class EmailView(generics.GenericAPIView):
    serializer_class = EmailSerializer
    def post(self,request,format=None):
        serializer=self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        email=serializer.validated_data['email']
    def send_email(self,gmail,Message):
        email=EmailMessage("Yangi xabar", Message,to=[gmail])
        email.send()

def check_email(request, id):
    user=User.objects.get(pk=id)
    print(user.email_active)
    return HttpResponse('<h1>Ok</h1>')
3b019774968b3a75109afe0e3ddc5cda00a51bc7
<mask token>


class RegisterView(generics.GenericAPIView):
    <mask token>
    <mask token>


class LoginView(KnoxLoginView):
    permission_classes = permissions.AllowAny,

    def post(self, request, format=None):
        serializer = AuthTokenSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user = serializer.validated_data['user']
        login(request, user)
        return super(LoginView, self).post(request, format=None)


class EmailView(generics.GenericAPIView):
    serializer_class = EmailSerializer

    def post(self, request, format=None):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        email = serializer.validated_data['email']

    def send_email(self, gmail, Message):
        email = EmailMessage('Yangi xabar', Message, to=[gmail])
        email.send()


<mask token>

<mask token>


class RegisterView(generics.GenericAPIView):
    <mask token>

    def post(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user = serializer.save()
        return Response({'user': UserSerializer(user, context=self.
            get_serializer_context()).data, 'token': AuthToken.objects.
            create(user)[1]})


class LoginView(KnoxLoginView):
    permission_classes = permissions.AllowAny,

    def post(self, request, format=None):
        serializer = AuthTokenSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user = serializer.validated_data['user']
        login(request, user)
        return super(LoginView, self).post(request, format=None)


class EmailView(generics.GenericAPIView):
    serializer_class = EmailSerializer

    def post(self, request, format=None):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        email = serializer.validated_data['email']

    def send_email(self, gmail, Message):
        email = EmailMessage('Yangi xabar', Message, to=[gmail])
        email.send()


<mask token>

<mask token>


class RegisterView(generics.GenericAPIView):
    serializer_class = RegisterSerializer

    def post(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user = serializer.save()
        return Response({'user': UserSerializer(user, context=self.
            get_serializer_context()).data, 'token': AuthToken.objects.
            create(user)[1]})


class LoginView(KnoxLoginView):
    permission_classes = permissions.AllowAny,

    def post(self, request, format=None):
        serializer = AuthTokenSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user = serializer.validated_data['user']
        login(request, user)
        return super(LoginView, self).post(request, format=None)


class EmailView(generics.GenericAPIView):
    serializer_class = EmailSerializer

    def post(self, request, format=None):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        email = serializer.validated_data['email']

    def send_email(self, gmail, Message):
        email = EmailMessage('Yangi xabar', Message, to=[gmail])
        email.send()


<mask token>

<mask token>


def send_email(request):
    pass


class RegisterView(generics.GenericAPIView):
    serializer_class = RegisterSerializer

    def post(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user = serializer.save()
        return Response({'user': UserSerializer(user, context=self.
            get_serializer_context()).data, 'token': AuthToken.objects.
            create(user)[1]})


class LoginView(KnoxLoginView):
    permission_classes = permissions.AllowAny,

    def post(self, request, format=None):
        serializer = AuthTokenSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user = serializer.validated_data['user']
        login(request, user)
        return super(LoginView, self).post(request, format=None)


class EmailView(generics.GenericAPIView):
    serializer_class = EmailSerializer

    def post(self, request, format=None):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        email = serializer.validated_data['email']

    def send_email(self, gmail, Message):
        email = EmailMessage('Yangi xabar', Message, to=[gmail])
        email.send()


def check_email(request, id):
    user = User.objects.get(pk=id)
    print(user.email_active)
    return HttpResponse('<h1>Ok</h1>')

from django.shortcuts import render
from django.contrib.auth import login
from rest_framework import generics,permissions
from rest_framework.response import Response
from rest_framework.authtoken.serializers import AuthTokenSerializer
from knox.views import LoginView as KnoxLoginView
from knox.auth import AuthToken
from .serializer import *
from .models import *
from django.core.mail import EmailMessage

def send_email(request):
    pass

class RegisterView(generics.GenericAPIView):
    serializer_class = RegisterSerializer
    def post(self,request,*args,**kwargs):
        serializer=self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user=serializer.save()
        return Response(
            {
            "user":UserSerializer(user,context=self.get_serializer_context()).data,
            "token":AuthToken.objects.create(user)[1]
        }
        )
class LoginView(KnoxLoginView):
    permission_classes =(permissions.AllowAny,)
    def post(self, request, format=None):
        serializer=AuthTokenSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user=serializer.validated_data['user']
        login(request, user)
        return super(LoginView, self).post(request, format=None)

class EmailView(generics.GenericAPIView):
    serializer_class = EmailSerializer
    def post(self,request,format=None):
        serializer=self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        email=serializer.validated_data['email']
    def send_email(self,gmail,Message):
        email=EmailMessage("Yangi xabar", Message,to=[gmail])
        email.send()

def check_email(request, id):
    user=User.objects.get(pk=id)
    print(user.email_active)
    return HttpResponse('<h1>Ok</h1>')