Example #1
0
 def logout(self):
     """Logs the current user out."""
     if 'user_id' in session:
         log.debug('User #%s logged out.' % session['user_id'])
         del session['user_id']
     if 'user_type' in session:
         del session['user_type']
     session.save()
     redirect(url('index'))
Example #2
0
 def logout(self):
     """Logs the current user out."""
     if 'user_id' in session:
         log.debug('User #%s logged out.' % session['user_id'])
         del session['user_id']
     if 'user_type' in session:
         del session['user_type']
     session.save()
     redirect(url('index'))
Example #3
0
    def clear(self):
        """
        Clear applied filters in the session.
        This method can be safely called, even if no filter was registered
        """

        if 'sponsor_filters' in session:
            log.debug("Clear sponsor filter")
            del(session['sponsor_filters'])
            session.save()

        redirect(url('sponsors'))
Example #4
0
    def _login(self):
        """
        Manages submissions to the login form.
        """
        log.debug('Form validated successfully')
        password = debexpo.lib.utils.hash_it(self.form_result['password'])

        u = None
        try:
            u = meta.session.query(User).filter_by(
                email=self.form_result['email']).filter_by(
                    password=password).filter_by(verification=None).one()
        except:
            log.debug('Invalid email or password')
            c.message = _('Invalid email or password')
            return self.index(True)

        session['user_id'] = u.id
        session['user_type'] = u.type
        session.save()

        log.debug('Authentication successful; saving session')

        u.lastlogin = datetime.now()

        # Clear the 'path_before_login' once it was used once. This is necessary to make sure users won't be redirected
        # to pages which don't exist anymore, as the path may have been stored in the session for a long time. Consider
        # following use case:
        # a) User is not logged in
        # b) User opens the URL /package/sunflow/delete/... in the browser
        # c) User is being redirected to /login, he logs in and is being redirected
        #    to the URL in b). This deletes the package, but leaves the URL in the session.
        # d) Once the user is trying to log in again - possibly after several weeks, the URL from
        #    b) is still in the session - but it may not exist anymore.
        if 'path_before_login' in session:
            path = session['path_before_login']
            del (session['path_before_login'])
        else:
            path = url('my')

        # Purge the session upload key
        keys = meta.session.query(
            debexpo.model.user_upload_key.UserUploadKey).filter_by(user=u)
        if keys:
            for key in keys:
                meta.session.delete(key)

        meta.session.commit()
        redirect(path)
Example #5
0
    def _login(self):
        """
        Manages submissions to the login form.
        """
        log.debug('Form validated successfully')
        password = debexpo.lib.utils.hash_it(self.form_result['password'])

        u = None
        try:
            u = meta.session.query(User).filter_by(email=self.form_result['email']).filter_by(password=password).filter_by(verification=None).one()
        except:
            log.debug('Invalid email or password')
            c.message = _('Invalid email or password')
            return self.index(True)

        session['user_id'] = u.id
        session['user_type'] = u.type
        session.save()

        log.debug('Authentication successful; saving session')

        u.lastlogin = datetime.now()

        # Clear the 'path_before_login' once it was used once. This is necessary to make sure users won't be redirected
        # to pages which don't exist anymore, as the path may have been stored in the session for a long time. Consider
        # following use case:
        # a) User is not logged in
        # b) User opens the URL /package/sunflow/delete/... in the browser
        # c) User is being redirected to /login, he logs in and is being redirected
        #    to the URL in b). This deletes the package, but leaves the URL in the session.
        # d) Once the user is trying to log in again - possibly after several weeks, the URL from
        #    b) is still in the session - but it may not exist anymore.
        if 'path_before_login' in session:
                path = session['path_before_login']
                del(session['path_before_login'])
        else:
                path = url('my')

        # Purge the session upload key
        keys = meta.session.query(debexpo.model.user_upload_key.UserUploadKey
                                  ).filter_by(user=u)
        if keys:
            for key in keys:
                meta.session.delete(key)

        meta.session.commit()
        redirect(path)
Example #6
0
    def save(self):
        """
        Toggle a filter within the session.
        This method prepares a list of filters to limit results in the sponsor list

        ```tag``` the sponsor tag to be filtered. If the tag is already in the filter
            list remove it, add it otherwise.
        """

        tags = request.params.getall('t')
        if not self._validate_tags(tags):
            abort(404)

        if 'sponsor_filters' not in session:
            session['sponsor_filters'] = []

        session['sponsor_filters'] = tags
        session.save()

        redirect(url('sponsors'))