def get_by_url_prefix(cls, url_prefix): """ http://www.amazon -> http://www.amazon.com, etc. :param url_prefix: :return: """ # need to find better matching patterns return cls(**Database.find_one( StoreConstants.COLLECTION, {"url_prefix": { "$regex": "^{}".format(url_prefix) }}))
def login_valid(email, password): """ This method verifies weather email/password combination is valid or not Checks if the email exists, and the password is correct to it :param email: user's email :param password: a sha512 hashed password :return: Boolean value """ user_data = Database.find_one( UserConstants.COLLECTION, {"email": email}) # password in sha512->pbkdf2_sha512 if user_data is None: raise UserErrors.UserNotExistException("Your user does not exist") if not Utils.check_hashed_password(password, user_data['password']): raise UserErrors.IncorrectPasswordException( "Your password is not correct") return True
def register_user(email, password): """ This method register an user using an email :param email: user's email :param password: sha512 hashed password :return: Boolean, to see if the process is successful (Exceptions might be raised) """ user_data = Database.find_one(UserConstants.COLLECTION, {"email": email}) if user_data is not None: raise UserErrors.UserAlreadyRegisterError( "The user is already registered with us.") if not Utils.email_is_valid(email): raise UserErrors.UserEmailInvalidError( "The email address cannot be parsed. Questions?") User(email, Utils.hash_password(password)).save_to_mongo() return True
def get_by_name(cls, store_name): return cls(**Database.find_one(StoreConstants.COLLECTION, {"name": store_name}))
def get_by_id(cls, id): return cls(**Database.find_one(StoreConstants.COLLECTION, {"_id": id}))
def get_by_id(cls, item_id): return cls( **Database.find_one(ItemConstants.COLLECTION, {"_id": item_id}))
def retrieve_item(cls, url): item_data = Database.find_one(ItemConstants.COLLECTION, url) return cls(**item_data)
def from_mongo(cls, id): post_data = Database.find_one(collecion='posts', query={'_id': id}) return cls(**post_data)
def find_by_id(cls, alert_id): return cls( **Database.find_one(AlertConstants.COLLECTION, {'_id': alert_id}))
def find_by_email(cls, email): return cls( **Database.find_one(UserConstants.COLLECTION, {'email': email}))
def from_mongo(cls, id): blog_data = Database.find_one(collecion='blogs', query={'_id': id}) return cls(**blog_data)
def get_by_id(cls, _id): data = Database.find_one("users", {"_id": _id}) if data is not None: return cls(**data)
def get_by_email(cls, email): data = Database.find_one("users", {"email": email}) if data is not None: return cls(**data)