def register_user(email, password, name): user_data = Database.find_one('users', {"email": email}) print("There is current user {}".format(user_data)) if user_data is not None: raise err.UserIsAlreadyExist("The user with {} is already exist".format(email)) if not Utils.email_is_valid(email): raise err.InvalidEmail("Please, write a valid email") userId = User(email, Utils.hash_password(password), name).save() userCursor = Database.find_one('users', {'_id': userId}) return True, userCursor
def get_board(cls, _id): cursorBoard = Database.find_one('boards', {'_id': _id}) if cursorBoard is not None: return cls(**cursorBoard), cursorBoard else: raise error.BoardIsNotExistInDatabase( "The board with this Id is not exist in Database")
def delete_comment(self, _id): result = Database.delete_one('comments', {'_id': self._id}) isDocumentExist = Database.find_one('comments', {'_id': self._id}) if result.deleted_count is 1 and isDocumentExist is None: return True return False
def is_login_valid(email, password): user_data = Database.find_one('users', {"email": email}) if user_data is None: raise err.UserNotExist("User is not exist") if not Utils.check_hashed_password(password, user_data['password']): raise err.IncorectPassword("Wrond password") return True
def remove_item(self, itemId): query = {'_id': self._id} document = {'items': {'_id': itemId}} Database.delete_one_from_array(Checklist.collection, query, document) cursor = Database.find_one(Checklist.collection, query) isRemovedtItemExist = list( filter(lambda c: c['_id'] == itemId, cursor['items'])) if len(isRemovedtItemExist) == 0: return True return False
def create_team(self): teamNameFromDb = Database.find_one("teams", {"teamName": self.teamName}) if teamNameFromDb is None: teamId = Team(teamName=self.teamName, authorId=self.authorId, boards=self.boards).save() _, team = Team.get_team_by_id(teamId) return team else: raise err.TeamIsAlreadyExist( "The team with this name is already exist")
def assign_attachment_file(self, fileId): query = {'_id': self._id} if fileId == self.attachments['assigned']: Database.update_one(Card.collection, query, {'attachments.assigned': ''}) else: Database.update_one(Card.collection, query, {'attachments.assigned': fileId}) cursorCard = Database.find_one(Card.collection, query) return { **cursorCard, 'attachments': { 'assigned': cursorCard['attachments']['assigned'] } }
def register_user(email, password): ''' Registers a user using an email & password. Password already comes hashed as sha-512. :param email: user's email (might be invalid) :param password: sha-512 hashed password :return: True if registered, False otherwise (exceptions can als be raised) ''' user_data = Database.find_one(UserConstants.COLLECTION, {"email": email}) if user_data is not None: raise UserErrors.UserAlreadyRegisteredError( "User email already exists") if not Utils.email_is_valid(email): raise UserErrors.InvalidEmailError("Invalid email format!") User(email, Utils.hash_password(password)).save_to_mongo() return True
def is_login_valid(email, password): ''' This method verifies that an email-password combo (as sent by site forms) is valid or not. Checks that email exists, and that password associated to that email is correct :param email: The user's email :param password: A sha512 hashed password :return: True if valid, False otherwise ''' user_data = Database.find_one( UserConstants.COLLECTION, {'email': email}) # Password in sha512 --> pbkdf2_sha512 if user_data is None: # Tell the user their email does not exist raise UserErrors.UserNotExistsError("Your user does not exist!") if not Utils.check_hashed_password(password, user_data['password']): # Tell the user their password is wrong raise UserErrors.IncorrectPasswordError("Your password was wrong!") return True
def get_list_by_id(cls, listId): cursorList = Database.find_one('lists', {"_id" : listId}) if cursorList is not None: return cursorList, cls(**cursorList) else: raise err.ListWithTihsIdIsNotExist("The list with this is is not exist in database")
def get_user_by_email(email): cursorUser = Database.find_one('users', {"email": email}) return cursorUser
def get_user_by_id_cursor(cls, queryID): cursorUser = Database.find_one('users', {"_id": queryID}) return cursorUser
def find_by_email(cls, email): # Retrieves user record by unique email return cls( **Database.find_one(UserConstants.COLLECTION, {'email': email}))
def get_team_by_id(cls, teamId): teamCursor = Database.find_one('teams', {"_id": teamId}) return cls(**teamCursor), teamCursor
def save_card_for_list(self, cardId): cursorList = Database.find_one('lists', { '_id': self._id }) Database.update_push('lists', { '_id' : self._id }, {'cards': cardId})
def get_by_id(cls, id): cursor = Database.find_one(Checklist.collection, {'_id': id}) return cls(**cursor)
def get_by_query(query): cursor = Database.find_one(Log.collection, query) return cursor
def get_by_id(_id): cursor = Database.find_one(Log.collection, {'_id': _id}) return cursor
def get_by_id(cls, _id): cursorComment = Database.find_one('comments', {'_id': _id}) return cursorComment, cls(**cursorComment)
def toggleBoardImportant(self, isImportant): Database.update_one('boards', {'_id': self._id}, {'isImportant': isImportant}) cursorBoard = Database.find_one('boards', {'_id': self._id}) return cursorBoard
def get_card_by_id(cls, card_id): cursor = Database.find_one('cards', {'_id': card_id}) if cursor is not None: return cls(**cursor), cursor else: raise err.CardIsUndefined("Thee card is undefined with this id")