예제 #1
0
 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 find_update(cls, time_since_update=AlertConstants.ALERT_TIMEOUT):
     # update alerts status if last update was more than ALERT_TIMEOUT minutes ago,
     # default 10 minutes
     last_updated_limit = datetime.datetime.utcnow() - datetime.timedelta(
         minutes=time_since_update)
     return [
         cls(**element)
         for element in Database.find(AlertConstants.COLLECTION, {
             "last_checked": {
                 "$lte": last_updated_limit
             },
             "active": True
         })
     ]
 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
예제 #5
0
 def get_by_id(cls, item_id):
     return cls(
         **Database.find_one(ItemConstants.COLLECTION, {"_id": item_id}))
예제 #6
0
 def retrieve_item(cls, url):
     item_data = Database.find_one(ItemConstants.COLLECTION, url)
     return cls(**item_data)
예제 #7
0
 def from_blog(id):
     return [
         post for post in Database.find(collection='posts',
                                        query={'blog_id': id})
     ]
예제 #8
0
 def from_mongo(cls, id):
     post_data = Database.find_one(collecion='posts', query={'_id': id})
     return cls(**post_data)
예제 #9
0
 def save_to_mongo(self):
     Database.insert(collection='posts', data=self.json())
예제 #10
0
 def get_by_id(cls, _id):
     data = Database.find_one("users", {"_id": _id})
     if data is not None:
         return cls(**data)
예제 #11
0
 def from_mongo(cls, id):
     blog_data = Database.find_one(collecion='blogs', query={'_id': id})
     return cls(**blog_data)
예제 #12
0
 def get_by_name(cls, store_name):
     return cls(**Database.find_one(StoreConstants.COLLECTION,
                                    {"name": store_name}))
 def find_by_id(cls, alert_id):
     return cls(
         **Database.find_one(AlertConstants.COLLECTION, {'_id': alert_id}))
def init_db():
    Database.initialize()
 def find_by_email(cls, email):
     return cls(
         **Database.find_one(UserConstants.COLLECTION, {'email': email}))
 def save_to_mongo(self):
     Database.insert(UserConstants.COLLECTION, self.json())
예제 #17
0
 def get_by_id(cls, id):
     return cls(**Database.find_one(StoreConstants.COLLECTION, {"_id": id}))
예제 #18
0
 def all(cls):
     return [
         cls(**element)
         for element in Database.find(StoreConstants.COLLECTION, ({}))
     ]
예제 #19
0
 def save_to_mongo(self):
     Database.update(StoreConstants.COLLECTION, {'_id': self._id},
                     self.json())
예제 #20
0
 def save_to_mongo(self):
     Database.insert(colletion='blogs', data=self.json())
 def save_to_mongo(self):
     Database.update(AlertConstants.COLLECTION, {"_id": self._id},
                     self.json())
 def find_by_user_email(cls, user_email):
     return [
         cls(**elem) for elem in Database.find(AlertConstants.COLLECTION,
                                               {'user_email': user_email})
     ]
예제 #23
0
 def delete(self):
     Database.remove(StoreConstants.COLLECTION, {'_id': self._id})
예제 #24
0
 def get_by_email(cls, email):
     data = Database.find_one("users", {"email": email})
     if data is not None:
         return cls(**data)