from rest_framework.generics import ListAPIView, RetrieveAPIView

from reqman.apps.account.models import User
from reqman.apps.reqtool.rest_api.serializers import UserSerializer
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
import json
from django.core.mail import send_mail
from django.conf import settings


class UserList(ListAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerializer


class UserDetail(RetrieveAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerializer

@csrf_exempt
def signup(request):
    if request.method == 'POST':
        data = json.loads(request.body)
        mail = data['email']
        username = data['username']
        password = data['password1']
        send_mail(
            'New register from Requirement tool',
            ' Username :'+username+'\n Mail:'+mail+' \n Password:'+password,
            settings.EMAIL_HOST_USER,
            ['nestorid@gapps.auth.gr'],
            fail_silently=False,
        )
        return HttpResponse("OK")
    else:
        return HttpResponse("Error")
        #form = UserCreationForm()
    #return render(request, 'signup.html', {'form': form})