コード例 #1
0
ファイル: auth.py プロジェクト: rice-apps/rice-elections
    def get(self):
        ticket = self.request.get('ticket')

        if not ticket:
            render_page(self, '/templates/message', {'status': 'Error', 'msg': 'Ticket not specified.'})
            return

        net_id = self.validate_cas_2()
        if not net_id:
            render_page(self, '/templates/message', {'status': 'Error', 'msg': 'Invalid ticket. Credentials not verified.'})
            return

        # Close any active session the user has since credentials have been freshly verified.
        session = get_current_session()
        if session.is_active():
            session.terminate()

        # Get the user's record
        voter = models.get_voter(net_id, create=True)

        # Start a session for the user
        session['net_id'] = voter.net_id

        destination_url = str(self.request.get('destination'))
        if not destination_url:
            render_page(self, '/templates/message', {'status': 'Error', 'msg': 'User authenticated. However, no destination '
                              'url is provided.'})
            return

        logging.info('Redirecting to %s', destination_url)
        self.redirect(destination_url)
コード例 #2
0
def main():
    print "Creating organizations..."

    brown = models.Organization(name='Brown College',
                                description='The best residential college.',
                                image='/static/img/who/brown-college.png',
                                website='http://brown.rice.edu')
    brown.put()
    mcmurtry = models.Organization(name='McMurtry College',
                                description='Not the best residential college.',
                                image='/static/img/who/mcmurtry-college.png',
                                website='http://mcmurtry.rice.edu')
    mcmurtry.put()
    baker = models.Organization(name='Baker College',
                                description='Not the best residential college.',
                                image='/static/img/who/mcmurtry-college.png',
                                carousel_show_name=False,
                                website='http://baker.rice.edu')
    baker.put()
    martel = models.Organization(name='Martel College',
                                description='Best deck.',
                                website='http://martel.rice.edu')
    martel.put()

    testing = models.Organization(name='Testing',
                                  description='Test 1 2 3',
                                  website='foo.bar')
    testing.put()

    print "Done."
    print "Creating admins..."

    users = [
        ('wa1', '*****@*****.**'),
        ('dan1', '*****@*****.**'),
        ('jcc7', '*****@*****.**'),
        ('jbb4', '*****@*****.**'),
        ('cmp1', '*****@*****.**'),
        ('pe4', '*****@*****.**'),
        ('wcl2', '*****@*****.**')
    ]

    admins = []

    for net_id, email in users:
        voter = models.get_voter(net_id, create=True)
        admin = models.Admin(voter=voter, email=email).put()
        admins.append(admin)


    for admin in admins[:3]:
        models.OrganizationAdmin(admin=admin, organization=brown).put()

    models.OrganizationAdmin(admin=admins[3], organization=mcmurtry).put()
    models.OrganizationAdmin(admin=admins[4], organization=baker).put()
    models.OrganizationAdmin(admin=admins[5], organization=martel).put()
    models.OrganizationAdmin(admin=admins[6], organization=testing).put()

    print "Done."
コード例 #3
0
ファイル: intern.py プロジェクト: rice-apps/rice-elections
 def add_admin(self, data):
     org = models.get_organization(data['organization'])
     voter = models.get_voter(data['net_id'], create=True)
     org_admin = models.put_admin(voter, data['net_id']+'@rice.edu', org)
     if org_admin:
         webapputils.respond(self, 'OK', 'Done')
     else:
         webapputils.respond(self, 'ERROR', "Couldn't create admin")
コード例 #4
0
ファイル: intern.py プロジェクト: hwangange/rice-elections
 def add_admin(self, data):
     org = models.get_organization(data['organization'])
     voter = models.get_voter(data['net_id'], create=True)
     org_admin = models.put_admin(voter, data['net_id'] + '@rice.edu', org)
     if org_admin:
         webapputils.respond(self, 'OK', 'Done')
     else:
         webapputils.respond(self, 'ERROR', "Couldn't create admin")
コード例 #5
0
ファイル: setup.py プロジェクト: gwarr3n/rice-elections
def main():
    print "Creating organizations..."

    brown = models.Organization(name='Brown College',
                                description='The best residential college.',
                                image='/static/img/who/brown-college.png',
                                website='http://brown.rice.edu')
    brown.put()
    mcmurtry = models.Organization(name='McMurtry College',
                                description='Not the best residential college.',
                                image='/static/img/who/mcmurtry-college.png',
                                website='http://mcmurtry.rice.edu')
    mcmurtry.put()
    baker = models.Organization(name='Baker College',
                                description='Not the best residential college.',
                                image='/static/img/who/mcmurtry-college.png',
                                carousel_show_name=False,
                                website='http://baker.rice.edu')
    baker.put()
    martel = models.Organization(name='Martel College',
                                description='Best deck.',
                                website='http://martel.rice.edu')
    martel.put()

    print "Done."
    print "Creating admins..."

    users = [
        ('wa1', '*****@*****.**'),
        ('dan1', '*****@*****.**'),
        ('jcc7', '*****@*****.**'),
        ('jbb4', '*****@*****.**'),
        ('cmp1', '*****@*****.**'),
        ('pe4', '*****@*****.**')
    ]

    admins = []

    for net_id, email in users:
        voter = models.get_voter(net_id, create=True)
        admin = models.Admin(voter=voter, email=email).put()
        admins.append(admin)


    for admin in admins[:3]:
        models.OrganizationAdmin(admin=admin, organization=brown).put()

    models.OrganizationAdmin(admin=admins[3], organization=mcmurtry).put()
    models.OrganizationAdmin(admin=admins[4], organization=baker).put()
    models.OrganizationAdmin(admin=admins[5], organization=martel).put()

    print "Done."
コード例 #6
0
ファイル: auth.py プロジェクト: voyagewsr/rice-elections
def get_voter(handler=None):
    """
    Returns the voter from user session.

    Args:
        handler {webapp2.RequestHandler}: Redirects the user to login if the
            user is not logged in. Note: Redirects only work for GET requests.

    Returns:
        voter: the Voter if authenticated. None otherwise.
    """
    session = get_current_session()
    if session.has_key('net_id'):
        return models.get_voter(session['net_id'])
    elif handler:
        require_login(handler)
    else:
        return None
コード例 #7
0
ファイル: auth.py プロジェクト: rice-apps/rice-elections
def get_voter(handler=None):
    """
    Returns the voter from user session.

    Args:
        handler {webapp2.RequestHandler}: Redirects the user to login if the
            user is not logged in. Note: Redirects only work for GET requests.

    Returns:
        voter: the Voter if authenticated. None otherwise.
    """
    session = get_current_session()
    if session.has_key('net_id'):
        return models.get_voter(session['net_id'])
    elif handler:
        require_login(handler)
    else:
        return None
コード例 #8
0
ファイル: auth.py プロジェクト: voyagewsr/rice-elections
    def get(self):
        ticket = self.request.get('ticket')

        if not ticket:
            render_page(self, '/templates/message', {
                'status': 'Error',
                'msg': 'Ticket not specified.'
            })
            return

        net_id = self.validate_cas_2()
        if not net_id:
            render_page(
                self, '/templates/message', {
                    'status': 'Error',
                    'msg': 'Invalid ticket. Credentials not verified.'
                })
            return

        # Close any active session the user has since credentials have been freshly verified.
        session = get_current_session()
        if session.is_active():
            session.terminate()

        # Get the user's record
        voter = models.get_voter(net_id, create=True)

        # Start a session for the user
        session['net_id'] = voter.net_id

        destination_url = str(self.request.get('destination'))
        if not destination_url:
            render_page(
                self, '/templates/message', {
                    'status':
                    'Error',
                    'msg':
                    'User authenticated. However, no destination '
                    'url is provided.'
                })
            return

        logging.info('Redirecting to %s', destination_url)
        self.redirect(destination_url)
コード例 #9
0
ファイル: auth.py プロジェクト: gwarr3n/rice-elections
    def get(self):
        ticket = self.request.get("ticket")

        if not ticket:
            render_page(self, "/templates/message", {"status": "Error", "msg": "Ticket not specified."})
            return

        net_id = self.validate_cas_2()
        if not net_id:
            render_page(
                self, "/templates/message", {"status": "Error", "msg": "Invalid ticket. Credentials not verified."}
            )
            return

        # Close any active session the user has since credentials have been freshly verified.
        session = get_current_session()
        if session.is_active():
            session.terminate()

        # Get the user's record
        voter = models.get_voter(net_id, create=True)

        # Start a session for the user
        session["net_id"] = voter.net_id

        destination_url = str(self.request.get("destination"))
        if not destination_url:
            render_page(
                self,
                "/templates/message",
                {"status": "Error", "msg": "User authenticated. However, no destination " "url is provided."},
            )
            return

        logging.info("Redirecting to %s", destination_url)
        self.redirect(destination_url)