def post(self, request): serializer = s.SignupSerializer(data=request.data) serializer.is_valid(raise_exception=True) user = serializer.save() if user is not None: verification_pin = random.randint(100000, 999999) user.verification_token = verification_pin user.verification_tries = 0 user.save() activation_url = '{}/auth/activate/{}/{}'.format( settings.GLUU_USER_APP, user.id, user.verification_token ) task = AsyncTask( user.email_user, 'emails/profiles/verify_email/verify_email_subject.txt', 'emails/profiles/verify_email/verify_email.txt', { 'activation_link': activation_url, 'user': user }, 'emails/profiles/verify_email/verify_email.html' ) task.run() user = s.UserSerializer(user) return Response( {'results': user.data}, status=status.HTTP_201_CREATED )
def get(self, request): check_signup_endpoint = '{}/api/v1/confirm-created/'.format( settings.GLUU_USER_APP_BACKEND) headers = {'Content-Type': 'application/json'} data = { 'idp_uuid': request.query_params.get('idp_uuid', None), 'email_hash': request.query_params.get('email_hash', None) } r = requests.post(check_signup_endpoint, data=json.dumps(data), headers=headers) if r.status_code == 200: response = r.json() user = response.get('user') invite = response.get('invite') email = user.get('email') idp_uuid = user.get('idpUuid') first_name = user.get('firstName') last_name = user.get('lastName') user = m.Invitation.objects.create(email=email, first_name=first_name, last_name=last_name, idp_uuid=idp_uuid) company = invite.get('company') activation_key = invite.get('activationKey') if company is not None and activation_key is not None: try: invite = m.Invitation.objects.get( company__id=company, activation_key=activation_key) except m.Invitation.DoesNotExist: pass if email != invite.email: pass if user in invite.company.users.all(): pass invite.accept(user) user_serializer = s.UserSerializer(user) return Response({'results': user_serializer.data}, status=status.HTTP_200_OK) else: raise ValidationError('Incorrect activation key')
def post(self, request, *args, **kwargs): serializer = s.VerifyCodeSerializer(data=request.data) if serializer.is_valid(): user = serializer.validated_data['user'] serialized_data = s.UserSerializer(user) return Response( {'results': serialized_data.data}, status=status.HTTP_200_OK ) return Response( serializer.errors, status=status.HTTP_400_BAD_REQUEST )
def get(self, request): token_json = api.get_token_from_callback(request.query_params) access_token = token_json.get('access_token') id_token = token_json.get('id_token') if not access_token or not id_token: raise e.OxdError('Invalid token') user = authenticate(request, access_token=access_token, id_token=id_token) if user is not None: user_serializer = s.UserSerializer(user) return Response({'results': user_serializer.data}, status=status.HTTP_200_OK) return Response( {'user': '******'}, status=status.HTTP_403_FORBIDDEN)
def list(self, request): page = self.paginate_queryset(self.get_queryset()) serializer = s.UserSerializer(page, many=True) return self.get_paginated_response(serializer.data)
def get(self, request): app = request.query_params.get('app', c.GURU) redirect_uri = '{}/auth/login-callback'.format( settings.FRONTEND_URL ) if app == c.USERS: redirect_uri = '{}/auth/login-callback'.format( settings.GLUU_USER_APP ) query_params = { 'code': request.query_params.get('code', ''), 'redirect_uri': redirect_uri, 'state': request.query_params.get('state', '') } token_json = api.get_token_from_callback(query_params) access_token = token_json.get('access_token') id_token = token_json.get('id_token') if not access_token: raise e.OxdError('Invalid token') user = authenticate( request, access_token=access_token, id_token=id_token ) if user is not None: company = user.company if not company: domain = user.email email_parts = user.email.split('@') if len(email_parts) > 1: domain = email_parts[1] companies = m.Company.objects.filter( website__icontains=domain ) if companies.count() == 1: membership, created = m.Membership.objects.get_or_create( user=user, company=companies[0] ) if created: membership.role = im.UserRole.objects.get(name='user') membership.is_primary = True membership.save() else: company = m.Company.objects.create( name=user.email ) m.Membership.objects.create( user=user, company=company, role=im.UserRole.objects.get(name='admin'), is_primary=True ) user_serializer = s.UserSerializer(user) return Response( { 'results': user_serializer.data }, status=status.HTTP_200_OK ) return Response( { 'user': '******' }, status=status.HTTP_403_FORBIDDEN )