Exemplo n.º 1
0
def vote(request, path):
    nexus = request.organization.main_nexus
    n_agora = agora_.get_by_nexus(nexus)
    booth = '%s/%s/election/%s/vote' % (settings.AGORA_ADMIN_USER, n_agora.agora, path)
    try:
        n_agora.link.head(booth)
    except:
        raise Http404('Vote does not exist.')
    r = agora_user.login(n_agora.link, agora_user.get_agora_username(request.user))
    if 'errors' in r:
        return render(request, 'mieli/unauthorized_voter.html')
    session = r['__session']
    if session == None:
        return HttpResponseServerError('Error while logging in you in the backend.')
    c = cookies.Cookies()
    c.parse_response(session)
    if not settings.AGORA_BACKEND_COOKIE in c:
        return HttpResponseServerError('Unexpected behavoir in backend.')
    try:
        abc = c[settings.AGORA_BACKEND_COOKIE]
    except KeyError:
        return HttpResponseServerError('Unexpected error getting backend cookie.')
    response = redirect('%s/%s' % (n_agora.link.url, booth))
    response.set_cookie(settings.AGORA_BACKEND_COOKIE, value=abc.value, max_age=abc.max_age, expires=abc.expires, path=abc.path, domain=abc.domain, secure=abc.secure, httponly=abc.httponly)
    return response
Exemplo n.º 2
0
def join(user, nexus, **kwargs):
    n_agora = get_by_nexus(nexus)
    if n_agora == None:
        raise Exception("nexus '%s' not linked" % (nexus.name))
    kwargs['action'] = 'add_membership'
    kwargs['username'] = agora_user.get_agora_username(user)
    kwargs['__auth'] = True
    kwargs['welcome_message'] = ''
    r = n_agora.link.post('agora/%d/action' % n_agora.agora_id, **kwargs)
    if 'error_message' in r:
        raise Exception(r['error_message'])