Beispiel #1
0
def user_registration_fun(data):
    serializer = RegistrationSerializer(data=data)
    if serializer.is_valid():
        with transaction.atomic():
            user = serializer.save()
            var = Token.objects.create(user=user).key
    return user
Beispiel #2
0
 def post(self, request):
     reg_data = RegistrationSerializer(data=request.data)
     if not reg_data.is_valid():
         return Response(reg_data.errors, status=status.HTTP_400_BAD_REQUEST)
     user = reg_data.save()
     login(request, user)
     return Response({}, status=status.HTTP_201_CREATED)
Beispiel #3
0
def registration_view(request):
    print("viewww")
    if (request.method == 'POST'):
        print("idhar ayaa")
        serializer = RegistrationSerializer(data=request.data)
        data = {}
        if serializer.is_valid():
            account = serializer.save()
            print('working')
            data['status'] = "account created"
            data['username'] = account.username
            token = Token.objects.get(user=account).key
            data['token'] = token
            return Response({'status': data['status']},
                            content_type='application/json',
                            status=201)
        else:
            data = serializer.errors
            print(data)
            return Response({'error': data},
                            content_type='application/json',
                            status=400)
    else:
        return Response({'failure': 'error in data'},
                        content_type='application/json',
                        status=400)
Beispiel #4
0
    def post(self, request):

        serializer = RegistrationSerializer(data=request.data)

        if serializer.is_valid():
            new_user = serializer.save()

            # token = Token.objects.create(user=new_user).key
            access_token = RefreshToken.for_user(new_user).access_token

            # prepare the data that will be sent to user
            fe_url = settings.FRONTEND_URL
            full_url = 'http://' + fe_url + "/email_verification?token=" + str(
                access_token)

            send_mail(subject='Verify your email',
                      from_email='*****@*****.**',
                      message='Hi ' + new_user.username +
                      ' Please use the link below to verify your email \n' +
                      full_url,
                      recipient_list=[new_user.email],
                      fail_silently=False)

            return Response(
                {
                    'success':
                    'User registered successfully! A verification link has been sent to your email address'
                },
                status=status.HTTP_201_CREATED)

        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
 def create(self, request, *args, **kwargs):
     """
     params: request => username, password, first_name, last_name, email, gender, bod, country, state, profile_pic, visit_reason
     return : message => Successfully user created
     """
     serializer = RegistrationSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(data={"message":"Successfully created"}, status=status.HTTP_201_CREATED)
     else:
         return Response(data={"message":serializer.errors}, status=status.HTTP_400_BAD_REQUEST)
Beispiel #6
0
def registration_view(request):
    if request.method == 'POST':
        serializer = RegistrationSerializer(data=request.data)
        data = {}
        if serializer.is_valid():
            user = serializer.save()
            data['response'] = 'successfully registered a new user.'
            data['email'] = user.email
            data['username'] = user.username
            data['phone'] = user.phone
        else:
            data = serializer.errors
        return Response(data)
Beispiel #7
0
def user_registration(request):
    serializer = RegistrationSerializer(data=request.data)
    data = {}
    if request.method == "POST":
        if serializer.is_valid():
            with transaction.atomic():
                user = serializer.save()
                data['response'] = "Successfully registered"
                token = Token.objects.create(user=user).key
                data['token'] = token
        else:
            data = serializer.errors
    return Response(data)
Beispiel #8
0
def registration_view(request):

    if request.method == 'POST':
        serializer = RegistrationSerializer(data=request.data)
        data = {}
        if serializer.is_valid():
            account = serializer.save()
            data['response'] = 'successfully registered new user.'
            data['email'] = account.email
            data['username'] = account.username
            token = Token.objects.get(user=account).key
            data['token'] = token
        else:
            data = serializer.errors
        return Response(data)
Beispiel #9
0
def registration_view(request):

    if request.method == 'POST':
        serializer = RegistrationSerializer(data=request.data)
        data = {}
        if serializer.is_valid():
            user = serializer.save()
            data['response'] = "Successfully registered a new user."
            data['email'] = user.email
            data['username'] = user.username
            data['is_student'] = user.is_student
            data['is_teacher'] = user.is_teacher
        else:
            data = serializer.errors
        return Response(data)
Beispiel #10
0
def registration_view(request):
    if request.method == 'POST':
        serializer = RegistrationSerializer(data=request.data)
        data = {}
        if serializer.is_valid():
            users = serializer.save()
            data['response'] = "Successfully registered a new user."
            data['first name'] = users.first_name
            data['last name'] = users.last_name
            data['username'] = users.username
            data['email'] = users.email
            token = Token.objects.get(user=users).key
            data['token'] = token
        else:
            data = serializer.errors
        return Response(data)
Beispiel #11
0
    def post(self,request):
        try:
          serializer = RegistrationSerializer(data=request.data)
   
          if serializer.is_valid():
               email=request.data['email']
               first_name = request.data['first_name']

               last_name = request.data['last_name']
               age=request.data['age']
               city=request.data['city']
               grade=request.data['grade']
               board=request.data['board']
               phone = request.data['phone']
               password = request.data['password']
               
               
               try:
                   user_email_obj = User.objects.filter(username=email,email=email,first_name=first_name,last_name=last_name)
                   print (user_email_obj)
                   if user_email_obj:
                      return fail_response({'error':'user already exist'})
                   else:
                        user_obj = User.objects.create(username=email,email=email,first_name=first_name,last_name=last_name)
                        user_obj.set_password(password)
                        user_obj.save()
                        token = Token.objects.create(user=user_obj)
                        profile_obj = Profile.objects.create(user=user_obj,email=email,phone=phone,age=age,city=city,grade=grade,board=board)


                        objt = {
                        'profile':ProfileSerializer(profile_obj).data,
                        'Token':token.key,
                        }

                        return Success_response(objt)

               except Exception as e:

                    return fail_response({'error':str(e)})

          else:
                return fail_response({'error':str(serializer.errors)})

                
        except Exception as e:
             return fail_response({'error':e}) 
Beispiel #12
0
 def get_applicant_obj(self,instance):
     applicant_obj = RegistrationSerializer(instance.applicant).data
     applicant_obj.pop('password')
     applicant_obj.pop('otp')
     return applicant_obj
Beispiel #13
0
 def post(self, request, version):
     serializer = RegistrationSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)