示例#1
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')
示例#2
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')
示例#3
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')
示例#4
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'))
示例#5
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')