Exemplo n.º 1
0
 def save(cls, user_data, **kwargs):
     with transaction.atomic():
         add_new = True
         # profile_data = user_data.pop('profile')
         password = user_data.pop('password', None)
         user_email = user_data.get('email', None)
         if user_data.get("id"):
             user = cls.get_user(user_data['id'])
         else:
             user = None
         if user is not None:
             add_new = False
             # profile = user.profile
         else:
             user = User()
         current_email = user.email
         # All data must be validated at serializer tier
         for key in user_data:
             setattr(user, key, user_data[key])
         # Set first password
         if add_new:
             if not password and not user.password:
                 password = Utils.id_generator(8)
             user.set_password(password)
         user.save()
         if not user.email:
             user.email = "{0}@{1}".format(str(user.id), "kitchenrock.vn")
             user.save()
         # if add_new:
         #     profile = UserProfile()
         #     profile.user_id = user.id
         # for key in profile_data:
         #     setattr(profile, key, profile_data[key])
         # profile.save()
         send_verify_email = True
         if user.is_active:
             send_verify_email = False
         if user_email != current_email:
             cls.add_email(user.id,
                           user.email,
                           current_email=current_email,
                           is_primary=True,
                           password=password,
                           send_verify_email=send_verify_email)
         if not add_new:
             # Reset cache
             cache_service = cls._get_cache_service()
             cache_service.delete(user.id)
         return cls.get_user(user.id)
Exemplo n.º 2
0
 def gen_token(cls, user_id):
     text = str(user_id) + Utils.id_generator(10) + str(int(time.time()))
     hash_object = hashlib.md5(text.encode('utf-8'))
     return hash_object.hexdigest()
Exemplo n.º 3
0
 def _gen_key(cls, length=KEY_SIZE):
     key = Utils.id_generator(length)
     while AppKey.objects.filter(key=key).exists():
         key = Utils.id_generator(length)
     return key.upper()
Exemplo n.º 4
0
 def _gen_unique_str(cls, length=DEFAULT_TOKEN_LENGTH):
     str = Utils.id_generator(length)
     if length < 40:
         while Api.objects.filter(token=str).exists():
             str = Utils.id_generator(length)
     return str