Ejemplo n.º 1
0
 def post(self, request, *args, **kwargs):
     form = self.form_class(request.POST)
     if form.is_valid():
         new_user = form.save()
         token = generate_token()
         prepare_confirmation(new_user, token)
         return HttpResponseRedirect(reverse('success'))
     return render(request, self.template_name, {'form': form})
Ejemplo n.º 2
0
 def register(self, request):
     """
     Register New User.
     """
     serializer = self.get_serializer(data=request.data)
     if serializer.is_valid():
         user = serializer.save()
         data = {'type': 'success', 'id': user.id}
         if not user.is_staff:
             token = generate_token()
             prepare_confirmation(user, token) 
             data.update({'confirm_token': token})
         return Response(data, status=status.HTTP_201_CREATED)
     else:
         return Response(
             {'type': 'error', 'message': serializer.errors},
             status=status.HTTP_202_ACCEPTED)
Ejemplo n.º 3
0
    def resend_user_token(self, email, password):
        try:
            is_correct_password = self.storage.users.is_correct_password(
                email, password)

            if not is_correct_password:
                raise UserNotAuthorised("user not authorised for this request")

            # because we check password above, this will not error
            user = self.storage.users.get_from_email(email)

            # if user already verified, then raise here
            if user["verified"]:
                raise UserNotAuthorised("user not authorised for this request")

            token = generate_token(str(uuid4().hex))
            self.storage.user_tokens.create(user["id"], token)
            self.send_grid.send_signup_verification(user["email"], token)
        except UserNotAuthorised as exc:
            raise exc
Ejemplo n.º 4
0
    def create_user(self, user_details):
        user_details = schemas.CreateUserRequest().load(user_details)

        try:
            user_id = self.storage.users.create(
                user_details["email"],
                user_details["password"],
                user_details["display_name"],
            )

            token = generate_token(str(uuid4().hex))

            self.storage.user_tokens.create(user_id, token)

            self.send_grid.send_signup_verification(user_details["email"],
                                                    token)

            return user_id
        except exc.IntegrityError:
            raise UserAlreadyExists(
                f'email {user_details["email"]} already exists')
Ejemplo n.º 5
0
def test_generate_token():
    uuid = "123"

    assert generate_token(uuid) == f"FF.{uuid}"