Beispiel #1
0
    def guidelines(self):

        if not config['debexpo.enable_experimental_code'].lower() == 'true':
            return render('/sponsor/index-old.mako')

        c.constants = constants

        c.sponsors = meta.session.query(SponsorMetrics)\
            .options(joinedload(SponsorMetrics.user))\
            .options(joinedload(SponsorMetrics.tags))\
            .filter(SponsorMetrics.availability >= constants.SPONSOR_METRICS_RESTRICTED)\
            .all()

        def hash_ip():
            """
            This is a simple hashing algorithm not supposed to be called from anywhere
            but for internal use only.
            It reads the client IP address and returns a float between 0.01 and 0.91 which is
            used as input for random.shuffle
            """
            ip = request.environ['REMOTE_ADDR']
            try:
                ip = struct.unpack( "!L", socket.inet_pton( socket.AF_INET, ip ))
                ip = ip[0]
            except socket.error:
                ip = struct.unpack( "!QQ", socket.inet_pton( socket.AF_INET6, ip ))
                ip = ip[1]
            ip = (float(ip % 10) + 0.01) / 10
            return ip

        random.shuffle(c.sponsors, hash_ip)

        # The select above works fine, except that it sucks.
        # It suffers from a poor performance and it could be significantly improved by querying the tag
        # labels and descriptions (i.e. the SponsorTags table by joining them with SponsorMetricsTags.
        # However the resulting result set does not quite look like what I imagine. Feel free to replace it
        # by something which actually works.

        #c.sponsors = meta.session.query(SponsorMetrics, SponsorMetricsTags, SponsorTags, User)\
        #    .join(User)\
        #    .join(SponsorMetricsTags)\
        #    .join(SponsorTags)\
        #    .filter(SponsorMetrics.availability >= constants.SPONSOR_METRICS_RESTRICTED)\


        if 'sponsor_filters' in session:
            log.debug("Applying tag filter")
            c.sponsor_filter = session['sponsor_filters']
        else:
            c.sponsor_filter = []
        if request.params.getall('t'):
            c.sponsor_filter = request.params.getall('t')

        c.technical_tags = meta.session.query(SponsorTags).filter_by(tag_type=constants.SPONSOR_METRICS_TYPE_TECHNICAL).all()
        c.social_tags = meta.session.query(SponsorTags).filter_by(tag_type=constants.SPONSOR_METRICS_TYPE_SOCIAL).all()

        if not self._validate_tags(c.sponsor_filter, c.technical_tags + c.social_tags):
            abort(404)

        return render('/sponsor/guidelines.mako')
Beispiel #2
0
    def index(self):
        """
        Return an introduction page for sponsors
        This page honors filters configured in the user session
        """

        return render('/sponsor/index.mako')
    def actually_reset_password(self, id):
        '''The point of this controller is to take a temporary auth key as input.

        If it is a valid one, change the password for that user to a randomly-
        generated string.

        If it is not a valid one, generate a 404.'''
        try:
            pr = meta.session.query(PasswordReset).filter_by(
                temporary_auth_key=id).one()
        except:
            log.debug('Invalid temporary auth key')
            abort(404,
                  "We do not know about that particular password reset key.")

        # Okay, so we got a user. Good.
        u = pr.user

        # Give the user a random password
        raw_password = debexpo.lib.utils.random_hash()[:10]

        # FIXME: We should not set u.password directly. Instead, we should
        # use a helper from the User model or something.
        u.password = debexpo.lib.utils.hash_it(raw_password)
        u.verification = None  # This sets the user's email address as "confirmed"
        meta.session.commit()

        log.debug('Password reset successful; saving user object')
        c.new_password = raw_password
        return render('/password_recover/actually_reset_password.mako')
    def _reset(self):
        """
        Manages submissions to the password reset form.
        """
        log.debug('Form validated successfully')
        try:
            u = meta.session.query(User).filter_by(
                email=self.form_result['email']).one()
        except:
            log.debug('Invalid email address somehow')
            c.message = _('We do not have an account with that email address')
            return self.index(get=True)

        # If that worked, then we send the user an email with a temporary URL
        # they can use to have our system generate a new password for them.
        log.debug('Sending activation email')

        email = Email('password_reset')
        password_reset_data = PasswordReset.create_for_user(u)
        meta.session.add(password_reset_data)
        meta.session.commit()

        recipient = u.email
        password_reset_url = 'http://' + config[
            'debexpo.sitename'] + url.current(
                action='actually_reset_password',
                id=password_reset_data.temporary_auth_key)
        email.send([recipient], password_reset_url=password_reset_url)

        # FIXME: This should be a HTTP redirect
        return render('/password_recover/_reset.mako')
Beispiel #5
0
    def _reset(self):
        """
        Manages submissions to the password reset form.
        """
        log.debug('Form validated successfully')
        try:
            u = meta.session.query(User).filter_by(email=self.form_result['email']).one()
        except:
            log.debug('Invalid email address somehow')
            c.message = _('We do not have an account with that email address')
            return self.index(get=True)

        # If that worked, then we send the user an email with a temporary URL
        # they can use to have our system generate a new password for them.
        log.debug('Sending activation email')

        email = Email('password_reset')
        password_reset_data = PasswordReset.create_for_user(u)
        meta.session.add(password_reset_data)
        meta.session.commit()

        recipient = u.email
        password_reset_url = 'http://' + config['debexpo.sitename'] + url.current(
            action='actually_reset_password', id=password_reset_data.temporary_auth_key)
        email.send([recipient], password_reset_url=password_reset_url)

        # FIXME: This should be a HTTP redirect
        return render('/password_recover/_reset.mako')
Beispiel #6
0
    def actually_reset_password(self, id):
        '''The point of this controller is to take a temporary auth key as input.

        If it is a valid one, change the password for that user to a randomly-
        generated string.

        If it is not a valid one, generate a 404.'''
        try:
            pr = meta.session.query(PasswordReset).filter_by(
                temporary_auth_key=id).one()
        except:
            log.debug('Invalid temporary auth key')
            abort(404,
                  "We do not know about that particular password reset key.")

        # Okay, so we got a user. Good.
        u = pr.user

        # Give the user a random password
        raw_password = debexpo.lib.utils.random_hash()[:10]

        # FIXME: We should not set u.password directly. Instead, we should
        # use a helper from the User model or something.
        u.password = debexpo.lib.utils.hash_it(raw_password)
        u.verification = None # This sets the user's email address as "confirmed"
        meta.session.commit()

        log.debug('Password reset successful; saving user object')
        c.new_password = raw_password
        return render('/password_recover/actually_reset_password.mako')
Beispiel #7
0
    def index(self):
        pkg_controller = PackagesController()

        c.config = config
        c.packages = pkg_controller._get_packages(
		        package_version_filter=(PackageVersion.uploaded >= (datetime.today() - timedelta(days=30))),
		        package_filter=(Package.needs_sponsor == 1)
            )
        c.deltas = pkg_controller._get_timedeltas(c.packages)
        c.deltas.pop()
	return render('/index/index.mako')
Beispiel #8
0
    def rfs_howto(self, packagename = None):


        c.package = None
        c.package_dir = None
        if packagename:
            package = meta.session.query(Package).filter_by(name=packagename).first()
            if package:
                c.package = package
                c.package_dir = get_package_dir(package.name)

        return render('/sponsor/rfs_howto.mako')
Beispiel #9
0
    def intro_maintainers(self):
        """Return an introduction page for package maintainers"""

        # The template will need to look at the user details.
        if 'user_id' in session:
            log.debug('Getting user object for user_id = "%s"' % session['user_id'])
            self.user = meta.session.query(User).get(session['user_id'])
            c.user = self.user
            c.logged_in = True
        else:
            c.logged_in = False

        return render('/index/intro-maintainers.mako')
Beispiel #10
0
    def index(self, get=False):
        """
        Entry point. Displays the login form.

        ``get``
            If True, display the form even if request.method is POST.
        """

        if request.method == 'POST' and get is False:
            log.debug('Login form submitted with email = "%s"' % request.POST.get('email'))
            return self._login()
        else:
            return render('/login/index.mako')
Beispiel #11
0
    def developer(self, id):
        if not config['debexpo.enable_experimental_code'].lower() == 'true':
            return render('/sponsor/index-old.mako')

        log.debug("Getting profile for user = %s" % (id))

        c.constants = constants

        c.sponsor = meta.session.query(SponsorMetrics)\
            .options(joinedload(SponsorMetrics.user))\
            .options(joinedload(SponsorMetrics.tags))\
            .filter(SponsorMetrics.availability >= constants.SPONSOR_METRICS_RESTRICTED)\
            .filter(User.email == id)\
            .first()
        if not c.sponsor:
            abort(404)
        c.profile = c.sponsor.user
        c.countries = { -1: '' }
        for country in meta.session.query(UserCountry).all():
            c.countries[country.id] = country.name


        return render('/sponsor/profile.mako')
Beispiel #12
0
    def index(self, get=False):
        """
        Entry point. Displays the login form.

        ``get``
            If True, display the form even if request.method is POST.
        """

        c.request = request
        if request.method == 'POST' and get is False:
            log.debug('Login form submitted with email = "%s"' %
                      request.POST.get('email'))
            return self._login()
        else:
            return render('/login/index.mako')
    def index(self, get=False):
        """
        Entry point. Displays the password reset form.

        ``get``
            If True, display the form even if request.method is POST.
        """

        if not hasattr(c, 'message'):
            c.message = None

        if request.method == 'POST' and get is False:
            log.debug('Password recovery form submitted with email = "%s"' %
                      request.POST.get('email'))
            return self._reset()
        else:
            return render('/password_recover/index.mako')
Beispiel #14
0
    def index(self, get=False):
        """
        Entry point. Displays the password reset form.

        ``get``
            If True, display the form even if request.method is POST.
        """

        if not hasattr(c, 'message'):
            c.message = None

        if request.method == 'POST' and get is False:
            log.debug(
                'Password recovery form submitted with email = "%s"' %
                request.POST.get('email'))
            return self._reset()
        else:
            return render('/password_recover/index.mako')
Beispiel #15
0
 def contact(self):
     c.config = config
     return render('/index/contact.mako')
Beispiel #16
0
 def qa(self):
     c.config = config
     return render('/index/qa.mako')
Beispiel #17
0
 def packaging_team(self):
     return render('/sponsor/packaging_team.mako')
Beispiel #18
0
 def intro_reviewers(self):
     c.config = config
     return render('/index/reviewers.mako')