Esempio n. 1
0
 def change_username(username, new_username):
     user_data = Database.find_one(collection, {'username': username})
     if user_data is None:
         raise UserErrors.UserNotExistsError("Your User doesn't Exist")
     Database.update(collection=collection,
                     query={'username': username},
                     data={"$set": {
                         'username': new_username
                     }})
     return True
Esempio n. 2
0
 def change_password(username, new_password):
     user_data = Database.find_one(collection, {'username': username})
     if user_data is None:
         raise UserErrors.UserNotExistsError("Your User doesn't Exist")
     Database.update(
         collection=collection,
         query={'username': username},
         data={"$set": {
             'password': Utils.hash_password(new_password)
         }})
     return True
Esempio n. 3
0
 def delete_user(username):
     user_data = Database.find_one(collection, {'username': username})
     if user_data is None:
         raise UserErrors.UserNotExistsError("Your User doesn't Exist")
     Database.remove(collection=collection, query={'username': username})
     Database.updateMany(collection=group_table,
                         query={},
                         data={'$pull': {
                             'users': username
                         }})
     return True
Esempio n. 4
0
 def make_user_active(username):
     user_data = Database.find_one(collection, {'username': username})
     if user_data is None:
         raise UserErrors.UserNotExistsError("Your User doesn't Exist")
     if user_data['active'] is True:
         raise UserErrors.UserisAlreadyActiveError("User is Already Active")
     Database.update(collection=collection,
                     query={'username': username},
                     data={"$set": {
                         'active': True
                     }})
     return True
Esempio n. 5
0
    def is_login_valid(cls, username, password):
        user_data = Database.find_one(collection, {'username': username})

        if user_data is None:
            raise UserErrors.UserNotExistsError("Your User doesn't Exist")

        if user_data['active'] is False:
            raise UserErrors.UserisNotAuthorised(
                "You are not authorised to Log In")

        if not Utils.check_hashed_password(password, user_data['password']):
            raise UserErrors.IncorrectPasswordError("Your Password was wrong")

        return cls(**user_data)
Esempio n. 6
0
 def remove_user_from_group(gname, user):
     group_data = Database.find_one(collection=collection,
                                    query={'gname': gname})
     if group_data is None:
         raise GroupErrors.GroupNotExistsError('Group Not Exists')
     user_data = Database.find_one(collection=user_table,
                                   query={'username': user})
     if user_data is None:
         raise UserErrors.UserNotExistsError("No Users with that name")
     group_user_data = Database.find_one(collection=collection,
                                         query={
                                             'gname': gname,
                                             'users': user
                                         })
     if group_user_data is None:
         raise GroupErrors.UserNotExistsInGroupError(
             'User Not Exists in this group')
     Database.update(collection=collection,
                     query={'gname': gname},
                     data={'$pull': {
                         'users': user
                     }})
     return True