Beispiel #1
0
    def post(self, request):
        """
        To sign up the user manually
        request type allowed : only POST

        :param request:
        :return: either success message or user info if user already signed up
        """
        data = request.data.copy()
        print(data)
        data['signup'] = True
        r = verify_token(data)
        if r['message'] != 'valid':
            return Response({'message': r['message']})
        print(r)
        user_id = r.get('username')
        print(user_id)
        user = User()  # insert user info into database
        try:
            user = User.objects.get(username=user_id)

            serializer = UserSerializer(user)
            return Response(serializer.data)
        except ObjectDoesNotExist:
            user.username = data['username']
            user.first_name = data['firstName']
            user.last_name = data['lastName']
            user.email = data['email']

            password = data['password']

            user.password = make_password(password=password,
                                          salt=None,
                                          hasher='unsalted_md5')
            user.is_active = False
            user.save()

            # To send confirmation email

            subject = 'Activate your Entrygate account.'
            message = render_to_string(
                'users/acc_active_email.html', {
                    'user': user,
                    'domain': 'entrygate-booking.herokuapp.com',
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            toemail = data['email']
            email = EmailMessage(subject, message, to=[toemail])
            email.send()
            return Response({
                'message':
                'User successfully registered and Please confirm your Email'
            })
Beispiel #2
0
 def post(self, request):
     """
     To sign in a user.
     
     :param request: 
     :return: json object which contains user information
     """
     data = request.data.copy()
     data['signup'] = False
     r = verify_token(data)
     if r['message'] != 'valid':
         return Response({'message': r['message']})
     user_id = r['user_id']
     if user_id:
         user = User.objects.get(id=user_id)
         serializer = UserSerializer(user)
         return Response(serializer.data)
Beispiel #3
0
    def get(self, request, user_id):
        """
        To get the user information whose user_id specified in Url
        request type allowed : only GET
        
        :param request: 
        :param user_id: 
        :return: json object of either user info. or error message
        """
        data = request.GET.copy()
        data['signup'] = False
        r = verify_token(data)
        if r['message'] != 'valid':
            return Response({'message': r['message']})

        if user_id == r['user_id']:
            user = User.objects.get(id=user_id)
            serializer = UserSerializer(user)
            return Response(serializer.data)
        else:
            return Response({'message': 'Access token not for the given User'})
Beispiel #4
0
 def post(self, request):
     """
     To update profile info. of the user.
     
     :param request: 
     :return: Success or Failure message
     """
     data = request.data.copy()
     data['signup'] = False
     r = verify_token(data)
     if r['message'] != 'valid':
         return Response({'message': r['message']})
     user_id = r['user_id']
     if user_id:
         user = User.objects.get(id=user_id)
         if 'first_name' in data:
             user.first_name = data['first_name']
         if 'last_name' in data:
             user.last_name = data['last_name']
         if 'gender' in data:
             user.gender = data['gender']
         if 'email' in data:
             if not user.email:
                 user.email = data['email']
         if 'contact' in data:
             user.contact = data['contact']
         if 'pic_url' in data:
             user.pic_url = data['pic_url']
         if 'height' in data:
             user.height = data['height']
         if 'weight' in data:
             user.weight = data['weight']
         if 'dob' in data:
             user.dob = data['dob']
         user.save()
         return Response({'message': 'Profile successfully updated'})
Beispiel #5
0
    def post(self, request):
        """
        To sign up the user manually
        request type allowed : only POST

        :param request:
        :return: either success message or user info if user already signed up
        """
        data = request.data.copy()
        print(data)
        data['signup'] = True
        r = verify_token(data)
        if r['message'] != 'valid':
            return Response({'message': r['message']})
        else:
            print(r)
            email = data['email']
            print(email)
            user = User()
            user = User.objects.get(email=email)
            # insert user info into database

            user.username = data['username']

            password = data['password']

            user.password = make_password(password=password,
                                          salt=None,
                                          hasher='unsalted_md5')
            # user.is_active = False
            user.save()

            # To send confirmation email

            return JsonResponse(json.dumps({'message': 'registered'}),
                                safe=False)