Esempio n. 1
0
 def clean(self):
     self.cleaned_data['premium'] = False
     self.cleaned_data['active'] = True
     self.cleaned_data['facebook'] = self.cleaned_data['facebook'] if 'facebook' in self.cleaned_data else False
     self.cleaned_data['salt'] = bcrypt.gensalt()
     self.cleaned_data['password'] = User.hash_password(self.cleaned_data['password'], self.cleaned_data['salt'])
     return self.cleaned_data
Esempio n. 2
0
 def submit(self):
     user_id = self.cleaned_data['user_id']
     del self.cleaned_data['user_id']
     
     # get the original user
     try:
         user = User.get(user_id)
     except CassaNotFoundException:
         raise UserNotFoundException()
     
     if not self.cleaned_data: # no real changes made
         return UserSerializer(user).data
 
     # check to see username or email are being changed
     # if they are maintain the uniqueness
     if 'username' in self.cleaned_data:
         if user.username != self.cleaned_data['username'] and User.get(username=self.cleaned_data['username']):
             raise UserConflictException()
     
     if 'email' in self.cleaned_data:
         if user.email != self.cleaned_data['email'] and User.get(email=self.cleaned_data['email']):
             raise UserConflictException()
         
     if 'password' in self.cleaned_data:
         self.cleaned_data['password'] = User.hash_password(self.cleaned_data['password'], user.salt)
     
     user.update(self.cleaned_data)
     user.save()
     
     return UserSerializer(user).data