Ejemplo n.º 1
0
    def POST(self, domain):
        # verify the cookie is not set to the current session.
        # in that case it would be a resubmission
        c = web.cookies(session_uuid=uuid4()).session_uuid
        if str(c) == str(glob.session_uuid):
            print "user submitted again to same session"
            return renderer.duplicate(
                config.base_url,
                glob.urls['user']['url_pattern'].replace('$', '') % domain,
                logman.LoggedIn())
        else:
            web.setcookie('session_uuid', glob.session_uuid, 3600)

        user_group = web.cookies(qv_user_group='').qv_user_group

        data = {}
        data.update(web.input())
        data['env'] = {}
        for (k, v) in web.ctx.env.items():
            if type(v) is str:
                data['env'][k.replace('.', '_')] = v
        data['inserted_at'] = datetime.now()
        data['user_group'] = user_group
        data['session'] = qv_domains.get_active_session(domain, data['uuid'])
        new_input.acquire()
        try:
            qv_collection.insert(data)
            new_input.notifyAll()
        finally:
            new_input.release()
        return renderer.submit(
            config.base_url,
            glob.urls['user']['url_pattern'].replace('$', '') % domain,
            logman.LoggedIn())
Ejemplo n.º 2
0
    def GET(self, domain):

        # check logged in
        if not logman.LoggedIn():
            print "Failed Login!"
            return web.seeother('/login')

        # check for valid domain
        if not qv_domains.is_domain(domain):
            print "Failed domain check!"
            return web.notacceptable()

        # check that user has access to this domain
        attempt_at_access = qv_domains.Access_domain(
            domain,
            web.cookies().get('QV_Usr'))
        if logman.isAdmin(
        ) or attempt_at_access == "Coord" or attempt_at_access == "Editor":
            print "Authourized"
        else:
            print "Failed Access!"
            return web.notacceptable()

        qs = qv_questions.find({'domain': domain}).sort([('inserted_at', -1)])

        data = {
            'existing_questions': [],
            'new_uuid':
            uuid4(),
            'domain':
            domain,
            'active_question':
            qv_domains.get_active_question(domain),
            'submit_url':
            glob.urls['question_post']['url_pattern'] % (domain),
            'get_url':
            glob.urls['question_get']['url_pattern'] % (domain, ''),
            'get_results_url':
            glob.urls['results_get']['url_pattern'] % (domain, ''),
            'delete_url':
            glob.urls['answers_post']['url_pattern'] % (domain, ''),
            'results_url':
            glob.urls['view']['url_pattern'] % (domain),
            'history_url':
            glob.urls['history']['url_pattern'] % (domain),
        }

        qsd = [q for q in qs]

        data['existing_questions'] = qsd

        return renderer.editor(config.base_url, data, logman.LoggedIn())
Ejemplo n.º 3
0
    def GET(self, domain):
        if not qv_domains.is_admin(domain):
            return web.notacceptable()
        qs = qv_questions.find({'domain': domain}).sort([('inserted_at', -1)])

        data = {
            'existing_questions': [],
            'new_uuid':
            uuid4(),
            'domain':
            domain,
            'active_question':
            qv_domains.get_active_question(domain),
            'submit_url':
            glob.urls['question_post']['url_pattern'] % (domain),
            'get_url':
            glob.urls['question_get']['url_pattern'] % (domain, ''),
            'get_results_url':
            glob.urls['results_get']['url_pattern'] % (domain, ''),
            'delete_url':
            glob.urls['answers_post']['url_pattern'] % (domain, ''),
            'results_url':
            glob.urls['view']['url_pattern'] % (domain),
            'history_url':
            glob.urls['history']['url_pattern'] % (domain),
        }

        qsd = [q for q in qs]

        data['existing_questions'] = qsd

        return renderer.admin(config.base_url, data, logman.LoggedIn())
Ejemplo n.º 4
0
 def GET(self):
     # get list of domain names
     domain_list = qv_domains.get_list_of_domains()
     if logman.LoggedIn():
         if logman.isAdmin():
             return renderer.home(config.base_url, domain_list, domain_list,
                                  True,
                                  True)  # (domain info, loggedin, isAdmin)
         manage_domain_list = []
         for d in domain_list:
             if qv_domains.Access_domain(
                     d[0],
                     web.cookies().get(
                         'QV_Usr')) == "Coord" or qv_domains.Access_domain(
                             d[0],
                             web.cookies().get('QV_Usr')) == "Editor":
                 manage_domain_list.append([
                     d[0], d[1], d[2],
                     qv_domains.Access_domain(d[0],
                                              web.cookies().get('QV_Usr'))
                 ])
         return renderer.home(config.base_url, domain_list,
                              manage_domain_list, True,
                              False)  # (domain info, loggedin, isAdmin)
     return renderer.home(config.base_url, domain_list, None, False, False)
Ejemplo n.º 5
0
    def GET(self, domain):
        if logman.LoggedIn() == True:
            if qv_domains.is_domain(domain):
                n_group = qv_domains.get_n_groups(domain)

                recs = usrman.get_usr_list()
                usrs = []
                for r in recs:
                    usrs.append(r["Username"])
                if qv_domains.Access_domain(
                        domain,
                        web.cookies().get('QV_Usr')) == "Coord":
                    return renderer.manage(
                        config.base_url,
                        domain,  # name of domain to manage (string)
                        True,  # is user logged in? (boolean)
                        logman.isAdmin(),  # is user and Admin? (boolean)
                        "Coord",  # Access that user has to domain (string)
                        qv_domains.get_list_of_editors(
                            domain
                        ),  # list of editors for domain (string[] / None)
                        None,  # list of coordinators for domain (string[] / None)
                        usrs,
                        n_group,
                        config.base_url + domain + '/view?magic=' +
                        qv_domains.get_admin_url(domain))
                if logman.isAdmin():
                    return renderer.manage(
                        config.base_url,
                        domain,  # name of domain to manage (string)
                        True,  # is user logged in? (boolean)
                        logman.isAdmin(),  # is user and Admin? (boolean)
                        None,  # Access that user has to domain (string)
                        qv_domains.get_list_of_users(
                            domain
                        ),  # list of users for domain (string[[]] / None)
                        None,  # list of coordinators for domain (string[] / None)
                        usrs,
                        n_group,
                        config.base_url + domain + '/view?magic=' +
                        qv_domains.get_admin_url(domain))
                if qv_domains.Access_domain(
                        domain,
                        web.cookies().get('QV_Usr')) == "Editor":
                    return renderer.manage(
                        config.base_url,
                        domain,  # name of domain to manage (string)
                        True,  # is user logged in? (boolean)
                        logman.isAdmin(),  # is user and Admin? (boolean)
                        "Editor",  # Access that user has to domain (string)
                        [""],  # list of editors for domain (string[] / None)
                        None,  # list of coordinators for domain (string[] / None)
                        usrs,
                        n_group)
            else:
                return web.notfound()
        return web.seeother('/login')
Ejemplo n.º 6
0
    def GET(self, domain):
        user_uuid = web.cookies().get('qv_user_uuid')
        domain_session_uuid_cookie = web.cookies().get(
            'qv_domain_session_uuid')
        domain_session_uuid = qv_domains.get_domain_session(domain)
        qv_domains.DomainActive(domain)

        if user_uuid is None:
            print 'new user'
            web.setcookie('qv_user_uuid', str(uuid4()))
        if domain_session_uuid_cookie is None or \
           domain_session_uuid != domain_session_uuid_cookie:
            n_group = qv_domains.get_n_groups(domain)

            #print n_group, domain_session_uuid, domain_session_uuid_cookie
            if n_group > 0:
                ng = qv_domains.last_group_assignment[domain] + 1
                if ng > n_group:
                    ng = 1
                group = ng
                qv_domains.last_group_assignment[domain] = ng
            #group = randint(1, n_group)
            else:
                group = 0
            web.setcookie('qv_user_group', str(group))
            web.setcookie('qv_domain_session_uuid', str(domain_session_uuid))

            return renderer.start(config.base_url, domain, logman.LoggedIn())
        else:
            user_group = web.cookies(qv_user_group='').qv_user_group

            uuid = qv_domains.get_active_question(domain)
            qs = qv_questions.find_one({'uuid': uuid})
            if qs is not None and 'image' not in qs:
                qs['image'] = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='
            data = {
                'user_group': user_group,
                'qs': qs,
                'session_uuid': glob.session_uuid,
                'submit_url': glob.urls['user_post']['url_pattern'] % domain,
            }
            return renderer.index(config.base_url, data, logman.LoggedIn())
Ejemplo n.º 7
0
    def POST(self, domain):

        data = web.input()
        if logman.LoggedIn():
            # update editors in list
            if qv_domains.Access_domain(
                    domain,
                    web.cookies().get('QV_Usr')) == "Coord":
                if qv_domains.update_list_of_editors(domain, data):
                    return "Successful!"
            if logman.isAdmin():
                if qv_domains.update_list_of_all(domain, data):
                    return "Admin Successful!"
            return "Failed! You are not logged in!"
Ejemplo n.º 8
0
    def GET(self, domain):
        # verify the cookie is not set to the current session.
        # in that case it would be a resubmission
        if not qv_domains.is_admin(domain):
            return web.notacceptable()

        uuid = qv_domains.get_active_question(domain)
        data = {
            'uuid': uuid,
            'domain': domain,
            'vote_url': config.base_url + domain + '/',
            'get_url': glob.urls['results_get']['url_pattern'] % (domain, uuid)
        }

        return renderer.small(config.base_url, data, logman.LoggedIn())
Ejemplo n.º 9
0
    def GET(self, domain):
        # verify the cookie is not set to the current session.
        # in that case it would be a resubmission
        if not logman.DomainLogin(domain):
            user_data = web.input()
            print qv_domains.get_admin_url(domain)
            if hasattr(user_data, "magic"):
                if user_data.magic == qv_domains.get_admin_url(domain):
                    pass
                else:
                    return web.notacceptable()
            else:
                return web.notacceptable()

        uuid = qv_domains.get_active_question(domain)
        data = {
            'uuid':
            uuid,
            'domain':
            domain,
            'vote_url':
            config.base_url + domain + '/',
            'get_url':
            glob.urls['results_get']['url_pattern'] % (domain, uuid),
            'existing_questions': [],
            'active_question':
            uuid,
            'activate_question_url':
            glob.urls['question_get']['url_pattern'] % (domain, ''),
            'delete_url':
            glob.urls['answers_post']['url_pattern'] % (domain, ''),
            'get_results_url':
            glob.urls['results_get']['url_pattern'] % (domain, ''),
            'history_url':
            glob.urls['history']['url_pattern'] % (domain)
        }

        qs = qv_questions.find({'domain': domain}).sort([('inserted_at', -1)])

        qsd = [q for q in qs]

        data['existing_questions'] = qsd

        return renderer.view(config.base_url, data, logman.LoggedIn())
Ejemplo n.º 10
0
 def GET(self):
     if logman.LoggedIn():
         logman.Logout()
     return renderer.mainlogin(config.base_url, logman.LoggedIn())