Exemplo n.º 1
0
    def create_validate(self, query_dict, **kwargs):
        # user_identity can be email, username, user_id, phone_sms_e164
        if query_dict.get('username'):
            user_identity = query_dict.get('username')
        else:
            user_identity = query_dict.get('user_identity')
        try:
            if is_mongo_pk(user_identity):
                user = User.objects.get(id=user_identity)
                query_dict['use_system_gen_password'] = True
            elif user_identity.startswith('+'):
                user_profile = UserProfile.objects.get(phone_sms_e164=user_identity)
                user = user_profile.user
            elif email_re.match(user_identity):
                user = User.objects.get(email=user_identity)
            else:
                user = User.objects.get(username=user_identity)
        except User.DoesNotExist:
            raise api_errors.APIException(api_errors.ERROR_AUTH_USERNAME_NOT_EXIST)

        if not user.is_active:
            raise api_errors.APIException(api_errors.ERROR_REGISTRATION_NOT_ACTIVATE)

        query_dict['user'] = user
Exemplo n.º 2
0
 def read_validate(self, query_dict, object_id, **kwargs):
     if is_mongo_pk(object_id):
         query_dict['obj'] = SoundCloud.objects.get(id=object_id)
     else:
         obj = SoundCloud.objects.create_object_by_id(object_id)
         query_dict['obj'] = obj
Exemplo n.º 3
0
 def read_validate(self, query_dict, object_id, **kwargs):
     if is_mongo_pk(object_id):
         query_dict['obj'] = YoutubeVideo.objects.get(id=object_id)
     else:
         obj = YoutubeVideo.objects.create_youtube_object_by_id(object_id)
         query_dict['obj'] = obj