Exemplo n.º 1
0
 def login(cls):
     """Logs the user into the application. This method assumes that
        the user's login credentials is correct because it has be validated
        by the is_login_valid method.
     """
     if not Session.lookup('email'):
         raise Exception(
             '<set_login_sessions> must be called before the login method')
     Session.add('login_token', LoginToken.generate_code())
Exemplo n.º 2
0
    def reset_password(self, password_form):
        """reset_password(form-object) -> returns bool

           Allows the user to reset their password. This method assumes that the
           forgotten password code was called first.
        """

        self._user.password = PasswordImplementer.hash_password(
            password_form.password.data)
        self._user.save()
        Session.delete('login_token')

        return True
Exemplo n.º 3
0
    def save(self):
        """"""
        store = self._get_obj_to_save()
        store.save()

        # look at this one tomoorow
        username = Session.lookup('username')
        mail = MallDB.objects.filter(username=username).first()
        user = UserDB.objects.filter(username=username).first()

        store.mall = mail
        store.user = user
        store.user_email = Session.lookup('email')
        store.save()
Exemplo n.º 4
0
def confirm(username, code):
    """confirm(str, str) -> returns 404 not found page or redirect to login page

       Checks if the user's username and registration code is valid. Returns
       a 404 not found page if username and code is invalid, otherwise
       redirects the user to the login screen.
    """

    if not user.Account.Register.is_registration_code_valid(username, code):
        abort(404)

    Session.add('username', username)
    user.Account.Mall.username = username
    user.Account.Mall.save_generated_mall_id()
    return redirect(url_for('login_app.login'))
Exemplo n.º 5
0
def change_password():
    """The view function allows the user to change their current password"""

    form, error = ChangePasswordForm(), None
    user = User(email=Session.lookup('email'))

    if form.validate_on_submit():

        if user.Account.Password.change_old_password(form):

            user.Account.Password.email_user_about_password_change()
            Session.delete_login_credentials()
            return redirect(
                url_for('password_app.password_successful_changed'))

    return render_template('password/new_password.html', form=form)
Exemplo n.º 6
0
 def __init__(self, price_limit, item_id, active=True, last_checked=None, alert_id=None):
     self.price_limit = price_limit
     self.item_id = item_id
     self.item = None
     self.last_checked = last_checked
     self.email = Session.lookup('email')
     self.alert_id = alert_id if alert_id else CodeGenerator.generate_hex()
     self.active = active
Exemplo n.º 7
0
    def get_items_to_update(page, minutes=20):
        """Every twenty minutes the method returns a series items that will be
           updated with the new price
        """

        last_checked = time_passed_since_current_time(minutes=minutes)
        return AlertsDB.objects.filter(Q(user_email=Session.lookup('email')) &
                                       Q(last_checked__lte=last_checked)
                                       ).paginate(page, per_page=9)
Exemplo n.º 8
0
    def _get_obj_to_save(self):
        """Retrieves the object that will be saved to the database"""

        item = ItemDB(
            item_name=self.item_name,
            url=self.url,
            item_id=self.item_id,
            user_email=Session.lookup('email'),
            store_id=self.store_id,
            item_description=self.description,
        )
        if self.item_image:
            item.item_image = self._get_image_path()
        return item
Exemplo n.º 9
0
 def get_all_stores(cls, page):
     """"""
     return StoresDB.objects.filter(
         Q(predefined_store=False)
         & Q(user_email=Session.lookup('email'))).order_by(
             'creation_date').paginate(int(page), per_page=6)
Exemplo n.º 10
0
 def get_alerts(page):
     """Returns all items that the user has placed an alert on"""
     return AlertsDB.objects.filter(email=Session.lookup('email'),
                                    active=True,
                                    ).paginate(page, per_page=9)
Exemplo n.º 11
0
 def __repr__(self):
     return "<Alert for User '' with item '{}' with price '{}'>".format(Session.lookup('username'),
                                                                        self.item.item_name,
                                                                        self.price_limit)
Exemplo n.º 12
0
def logout():
    """Logs the user out of the application"""

    Session.delete_login_credentials()
    return redirect(url_for('login_app.login'))
 def login(*args, **kwargs):
     if not Session.lookup('email'):
         return redirect(url_for('login_app.login', next=request.path))
     return f(*args, **kwargs)
 def logged_in(*args, **kwargs):
     if Session.lookup('login_token'):
         return redirect(url_for('home_page_app.home_page'))
     return f(*args, **kwargs)
Exemplo n.º 15
0
 def set_login_sessions(email):
     """Set the user's email to the secure session"""
     Session.add('email', email)
Exemplo n.º 16
0
 def get_items_with_no_alerts(page=1):
     """"""
     return ItemDB.objects(
         Q(alert_added=False)
         & Q(user_email=Session.lookup('email'))).paginate(page, per_page=9)