Example #1
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
Example #2
0
 def submit(self):
     user = User.fromMap(self.cleaned_data)
     # check if username and email have not been used yet
     # if they have not then save the user
     if User.getByEmail(user.email) or User.getByUsername(user.username):
         raise UserConflictException()
     
     user.save()
     return UserSerializer(user).data
Example #3
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
Example #4
0
 def create(self, username, password):
     return NotImplementedError()
     payload = { 'username':username, 'password':password }
     r = requests.post(self.url + '/rest/v1/sessions',data=payload)
     if r.status_code is not 200:
         raise UserClientError(r.text)
     return User.fromMap(r.json())
Example #5
0
 def submit(self):
     try:
         ans = User.getByID(self.cleaned_data['user_id'])
         if not ans:
             raise UserNotFoundException()
     except CassaNotFoundException:
         raise UserNotFoundException()
     return UserSerializer(ans).data
Example #6
0
 def submit(self):
     if 'username' in self.cleaned_data:
         ans = User.getByUsername(self.cleaned_data['username'])
         uResponse = UserSerializer([] if not ans else [ans], many=True).data
         response = { 'data' : uResponse }
         return response
     elif 'email' in self.cleaned_data:
         ans = User.getByEmail(self.cleaned_data['email'])
         uResponse = UserSerializer([] if not ans else [ans], many=True).data
         response = { 'data' : uResponse }
         return response
     else:
         ans = User.all(page=self.cleaned_data['page'], limit=self.cleaned_data['limit'])
         uResponse = UserSerializer(ans, many=True).data
         response = { 'data' : uResponse }
         if ans:
             response['next'] = ans[-1].user_id
         return response
Example #7
0
 def update(self, user_id, username=None, password=None, email=None):
     payload = {}
     if username: payload['username'] = username
     if password: payload['password'] = password
     if email: payload['email'] = email
     
     headers = { 'HTTP_AUTHORIZATION' : self.session_id }
     
     r = requests.put(self.url + '/rest/v1/sessions/%s' % str(user_id), data=payload, headers=headers)
     if r.status_code is not 200:
         raise UserClientError(r.text)
     return User.fromMap(r.json())
Example #8
0
 def submit(self):
     user = User.getByUsername(self.cleaned_data['username'])
     if not user:
         raise SessionAuthorizationException()
     
     if not user.authenticate(self.cleaned_data['password']):
         raise SessionAuthorizationException()
     
     self.cleaned_data['user_id'] = UUID(user.user_id)
     del self.cleaned_data['username']
     del self.cleaned_data['password']
     session = Session.fromMap(self.cleaned_data)
 
     session.save()
     return SessionSerializer(session).data
Example #9
0
 def get(self, user_id):
     headers = { 'HTTP_AUTHORIZATION' : self.session_id }
     r = requests.delete(self.url + '/rest/v1/sessions/%s' % str(user_id), headers=headers)
     if r.status_code is not 200:
         raise UserClientError(r.text)
     return User.fromMap(r.json())