Exemplo n.º 1
0
    def GET(self, emailform=None, loadcontactsform=None):
        i = web.input()
        url = i.get('url', '/')
        title = i.get('title', 'The good government site with teeth')

        user_id = helpers.get_loggedin_userid()
        contacts = get_contacts(user_id)
        sender = helpers.get_user_by_email(helpers.get_loggedin_email() or helpers.get_unverified_email())

        page_or_petition = 'page'    
        if not emailform:
            emailform = forms.emailform()
            track_id, description = None, None
            if url.startswith('/c/') and url != '/c/':
                url = url.rstrip('/')
                pid = web.lstrips(url, '/c/')
                p = get_petition_by_id(pid)
                description = p and p.description
                track_id = helpers.get_trackid(user_id, pid)
                contacts = filter(lambda c: not is_signatory(c.email, pid), contacts)
                page_or_petition = 'petition'

            msg = render_plain.share_mail(title, url, sender, description, track_id)
            emailform.fill(subject=title, body=msg)

        loadcontactsform = loadcontactsform or forms.loadcontactsform()

        msg, msg_type = helpers.get_delete_msg()
        return render.share(title, url, emailform,
                            contacts, loadcontactsform, page_or_petition, msg)
Exemplo n.º 2
0
def create_petition(i, email):
    tocongress = i.get("tocongress", "off") == "on"
    i.pid = i.pid.replace(" ", "-")
    u = helpers.get_user_by_email(email)
    is_draft = "save" in i
    published = None if is_draft else datetime.now()
    try:
        db.insert(
            "petition",
            seqname=False,
            id=i.pid,
            title=i.ptitle,
            created=datetime.now(),
            published=published,
            description=i.msg,
            owner_id=u.id,
            to_congress=tocongress,
        )
    except:
        return

    if is_draft:
        msg = """Petition saved for publishing later."""
        helpers.set_msg(msg)
    else:
        create_first_signature(i, u.email)
Exemplo n.º 3
0
    def GET(self, emailform=None, loadcontactsform=None):
        i = web.input()
        url = i.get("url", "/")
        title = i.get("title", "The good government site with teeth")

        user_id = helpers.get_loggedin_userid()
        contacts = get_contacts(user_id)
        sender = helpers.get_user_by_email(helpers.get_loggedin_email() or helpers.get_unverified_email())

        page_or_petition = "page"
        isdraft = False
        if not emailform:
            emailform = forms.emailform()
            track_id, description = None, None
            if url.startswith("/c/") and url != "/c/":
                url = url.rstrip("/")
                pid = web.lstrips(url, "/c/")
                p = get_petition_by_id(pid)
                isdraft = is_draft(p)
                description = p and p.description
                track_id = helpers.get_trackid(user_id, pid) if not isdraft else None
                contacts = filter(lambda c: not is_signatory(c.email, pid), contacts)
                page_or_petition = "petition"
            msg = render_plain.share_mail(title, url, sender, description, isdraft, track_id)
            emailform.fill(subject=title, body=msg)

        loadcontactsform = loadcontactsform or forms.loadcontactsform()

        msg, msg_type = helpers.get_delete_msg()
        return render.share(title, url, emailform, contacts, loadcontactsform, page_or_petition, msg)
Exemplo n.º 4
0
    def GET(self, emailform=None, loadcontactsform=None):
        i = web.input()
        url = i.get('url', '/')
        title = i.get('title', 'The good government site with teeth')

        user_id = helpers.get_loggedin_userid()
        contacts = get_contacts(user_id)
        sender = helpers.get_user_by_email(helpers.get_loggedin_email()
                                           or helpers.get_unverified_email())

        page_or_petition = 'page'
        isdraft = False
        if not emailform:
            emailform = forms.emailform()
            track_id, description = None, None
            if url.startswith('/c/') and url != '/c/':
                url = url.rstrip('/')
                pid = web.lstrips(url, '/c/')
                p = get_petition_by_id(pid)
                isdraft = is_draft(p)
                description = p and p.description
                track_id = helpers.get_trackid(user_id,
                                               pid) if not isdraft else None
                contacts = filter(lambda c: not is_signatory(c.email, pid),
                                  contacts)
                page_or_petition = 'petition'
            msg = render_plain.share_mail(title, url, sender, description,
                                          isdraft, track_id)
            emailform.fill(subject=title, body=msg)

        loadcontactsform = loadcontactsform or forms.loadcontactsform()

        msg, msg_type = helpers.get_delete_msg()
        return render.share(title, url, emailform, contacts, loadcontactsform,
                            page_or_petition, msg)
Exemplo n.º 5
0
    def POST_sign(self, pid):
        i = web.input()
        sform = forms.signform()
        tocongress = to_congress(pid)
        p = get_petition_by_id(pid)
                
        if tocongress:
            i.pid, i.ptitle, i.msg = pid, p.title, p.description
            wyrform = forms.wyrform()
            wyr_valid =  wyrform.validates(i)
        else:
            wyrform, wyr_valid = None, True

        if sform.validates(i) and wyr_valid:
            auth.assert_login(i)
            user = helpers.get_user_by_email(i.email)
            signid = save_signature(i, pid, user.id, tocongress)
            if tocongress: 
                try:
                    i.msg = "%s\n%s" %(i.msg, i.comment) #need to compose 
                    msg_sent = send_to_congress(i, wyrform, signid)
                except CaptchaException:
                    return self.GET(pid, signform=sform, wyrform=wyrform)    
            if signid:
                sendmail_to_signatory(user, pid)
            query = urllib.urlencode(dict(url='/c/%s' % pid, title=p.title))
            raise web.seeother('/share?%s' % query, absolute=True)
        else:
            return self.GET(pid, signform=sform, wyrform=wyrform)
Exemplo n.º 6
0
def create_first_signature(i, email):
    tocongress = i.get('tocongress', 'off') == 'on'
    i.pid = i.pid.replace(' ', '-')
    u = helpers.get_user_by_email(email)
    signid = save_signature(i, i.pid, u.id)
    if tocongress: send_to_congress(u.id, i, signid)
    sendmail_to_signatory(u, i.pid)
    msg = """Congratulations, you've created your petition.
             Now share it with all your friends."""
    helpers.set_msg(msg)
Exemplo n.º 7
0
def create_first_signature(i, email):
    tocongress = i.get("tocongress", "off") == "on"
    i.pid = i.pid.replace(" ", "-")
    u = helpers.get_user_by_email(email)
    signid = save_signature(i, i.pid, u.id)
    if tocongress:
        send_to_congress(u.id, i, signid)
    sendmail_to_signatory(u, i.pid)
    msg = """Congratulations, you've created your petition.
             Now share it with all your friends."""
    helpers.set_msg(msg)
Exemplo n.º 8
0
def get_signid(pid):
    uemail = helpers.get_loggedin_email() or helpers.get_unverified_email()
    user = helpers.get_user_by_email(uemail)
    uid = user and user.id
    try:    
        sign = db.select('signatory', what='id', 
                    where="petition_id=$pid and user_id=$uid",
                    vars=locals())[0]
    except IndexError:
        pass
    else:                    
        return sign.id
Exemplo n.º 9
0
 def GET_edit(self, pid):
     user_email = helpers.get_loggedin_email()
     if is_author(user_email, pid):
         p = get_petition_by_id(pid)
         u = helpers.get_user_by_email(user_email)
         pform = forms.petitionform()
         pform.fill(userid=u.id, email=user_email, pid=p.id, ptitle=p.title, msg=p.description, tocongress=p.to_congress)
         cform = forms.wyrform()
         fill_user_details(cform)
         title = "Edit your petition"
         return render.petitionform(pform, cform, title, target='/c/%s?m=edit' % (pid))
     else:
         login_link = '<a href="/u/login">Login</a>'
         helpers.set_msg('Only author of this petition can edit it. %s if you are.' % login_link, msg_type='error')
         raise web.seeother('/%s' % pid)
Exemplo n.º 10
0
 def POST(self):
     i = web.input()
     emailform, loadcontactsform = forms.emailform(), forms.loadcontactsform()
     if emailform.validates(i):
         url, msg, subject = i.url, i.body, i.subject
         emails = [e.strip() for e in i.emails.strip(", ").split(",")]
         u = helpers.get_user_by_email(helpers.get_loggedin_email() or helpers.get_unverified_email())
         from_address = u and "%s %s <%s>" % (u.fname, u.lname, u.email) or config.from_address
         for email in emails:
             web.sendmail(from_address, email, subject, msg)
         page_or_petition = url.startswith("/c/") and "petition" or "page"
         helpers.set_msg("Thanks for sharing this %s with your friends!" % page_or_petition)
         raise web.seeother(url)
     else:
         return self.GET(emailform=emailform, loadcontactsform=loadcontactsform)
Exemplo n.º 11
0
 def GET_unsign(self, pid):
     i = web.input()
     user = helpers.get_user_by_email(i.email)
     
     if user:
         signatory = db.select('signatory', where='petition_id=$pid and user_id=$user.id', vars=locals())
     
     if not (user and signatory and auth.check_secret_token(i.email, i.token)):
         msg = "Invalid token or there is no signature for this petition with this email."
         msg_type = 'error'
     else:
         msg = render_plain.confirm_unsign(pid, user.id)
         msg_type = ''
         
     helpers.set_msg(msg, msg_type)
     raise web.seeother('/%s' % pid)
Exemplo n.º 12
0
def create_petition(i, email, wyrform):
    tocongress = i.get('tocongress', 'off') == 'on'
    i.pid = i.pid.replace(' ', '_')
    u = helpers.get_user_by_email(email)
    try:
        db.insert('petition', seqname=False, id=i.pid, title=i.ptitle, description=i.msg,
                owner_id=u.id, to_congress=tocongress)
    except:
        return
    signid = save_signature(i, i.pid, u.id, tocongress)            

    if tocongress and captcha_to_be_filled(i): wyrform.fill(signid=signid)
    if tocongress: send_to_congress(i, wyrform, signid)

    msg = """Congratulations, you've created your petition.
             Now sign and share it with all your friends."""
    helpers.set_msg(msg)
Exemplo n.º 13
0
    def GET_unsign(self, pid):
        i = web.input()
        user = helpers.get_user_by_email(i.email)

        if user:
            where = "petition_id=$pid and user_id=$user.id and deleted is null"
            signatory = db.select("signatory", where=where, vars=locals())

        valid_token = auth.check_secret_token(i.get("email", ""), i.get("token", "@"))
        if not (user and signatory and valid_token):
            msg = "Invalid token or there is no signature for this petition with this email."
            msg_type = "error"
        else:
            msg = str(render_plain.confirm_unsign(pid, user.id))
            msg_type = ""

        helpers.set_msg(msg, msg_type)
        raise web.seeother("/%s" % pid)
Exemplo n.º 14
0
    def GET_unsign(self, pid):
        i = web.input()
        user = helpers.get_user_by_email(i.email)

        if user:
            where = 'petition_id=$pid and user_id=$user.id and deleted is null'
            signatory = db.select('signatory', where=where, vars=locals())

        valid_token = auth.check_secret_token(i.get('email', ''),
                                              i.get('token', '@'))
        if not (user and signatory and valid_token):
            msg = "Invalid token or there is no signature for this petition with this email."
            msg_type = 'error'
        else:
            msg = str(render_plain.confirm_unsign(pid, user.id))
            msg_type = ''

        helpers.set_msg(msg, msg_type)
        raise web.seeother('/%s' % pid)
Exemplo n.º 15
0
 def POST(self):
     i = web.input()
     emailform, loadcontactsform = forms.emailform(
     ), forms.loadcontactsform()
     if emailform.validates(i):
         url, msg, subject = i.url, i.body, i.subject
         emails = [e.strip() for e in i.emails.strip(', ').split(',')]
         u = helpers.get_user_by_email(helpers.get_loggedin_email()
                                       or helpers.get_unverified_email())
         from_address = u and "%s %s <%s>" % (
             u.fname, u.lname, u.email) or config.from_address
         for email in emails:
             web.sendmail(from_address, email, subject, msg)
         page_or_petition = url.startswith('/c/') and 'petition' or 'page'
         helpers.set_msg('Thanks for sharing this %s with your friends!' %
                         page_or_petition)
         raise web.seeother(url)
     else:
         return self.GET(emailform=emailform,
                         loadcontactsform=loadcontactsform)
Exemplo n.º 16
0
 def GET_edit(self, pid):
     user_email = helpers.get_loggedin_email()
     if is_author(user_email, pid):
         p = get_petition_by_id(pid)
         u = helpers.get_user_by_email(user_email)
         pf = forms.petitionform()
         pf.fill(
             userid=u.id, email=user_email, pid=p.id, ptitle=p.title, msg=p.description, tocongress=p.to_congress
         )
         wf = forms.wyrform()
         fill_user_details(wf)
         isdraft = is_draft(p)
         return render.petitionform(pf, wf, is_new=False, is_draft=isdraft)
     elif user_email:
         msg = "You don't have permissions to edit this petition."
     else:
         login_link = '<a href="/u/login">Login</a>'
         msg = "Only author of this petition can edit it. %s if you are." % login_link
     helpers.set_msg(msg)
     raise web.seeother("/%s" % pid)
Exemplo n.º 17
0
 def GET_edit(self, pid):
     user_email = helpers.get_loggedin_email()
     if is_author(user_email, pid):
         p = get_petition_by_id(pid)
         u = helpers.get_user_by_email(user_email)
         pf = forms.petitionform()
         pf.fill(userid=u.id,
                 email=user_email,
                 pid=p.id,
                 ptitle=p.title,
                 msg=p.description,
                 tocongress=p.to_congress)
         wf = forms.wyrform()
         fill_user_details(wf)
         isdraft = is_draft(p)
         return render.petitionform(pf, wf, is_new=False, is_draft=isdraft)
     elif user_email:
         msg = "You don't have permissions to edit this petition."
     else:
         login_link = '<a href="/u/login">Login</a>'
         msg = 'Only author of this petition can edit it. %s if you are.' % login_link
     helpers.set_msg(msg)
     raise web.seeother('/%s' % pid)
Exemplo n.º 18
0
def create_petition(i, email):
    tocongress = i.get('tocongress', 'off') == 'on'
    i.pid = i.pid.replace(' ', '-')
    u = helpers.get_user_by_email(email)
    is_draft = 'save' in i
    published = None if is_draft else datetime.now()
    try:
        db.insert('petition',
                  seqname=False,
                  id=i.pid,
                  title=i.ptitle,
                  created=datetime.now(),
                  published=published,
                  description=i.msg,
                  owner_id=u.id,
                  to_congress=tocongress)
    except:
        return

    if is_draft:
        msg = """Petition saved for publishing later."""
        helpers.set_msg(msg)
    else:
        create_first_signature(i, u.email)
Exemplo n.º 19
0
def is_signatory(email, pid):
    user = email and helpers.get_user_by_email(email)
    where = 'petition_id=$pid and user_id=$user.id and deleted is null'
    return user and bool(db.select('signatory', where=where, vars=locals()))
Exemplo n.º 20
0
def is_signatory(email, pid):
    user = email and helpers.get_user_by_email(email)
    where = "petition_id=$pid and user_id=$user.id and deleted is null"
    return user and bool(db.select("signatory", where=where, vars=locals()))
Exemplo n.º 21
0
def is_author(email, pid):
    user = email and helpers.get_user_by_email(email)
    where = "id=$pid and owner_id=$user.id and deleted is null"
    return user and bool(db.select("petition", where=where, vars=locals()))
Exemplo n.º 22
0
def is_author(email, pid):
    user = email and helpers.get_user_by_email(email)
    where = 'id=$pid and owner_id=$user.id and deleted is null'
    return user and bool(db.select('petition', where=where, vars=locals()))