Beispiel #1
0
def site_forgot_password(request):
    back=request.values.get('back', '')
    if request.method == 'POST':
        back = request.form.get('back', '')
        
        # create token
        otoken = PasswordToken(site=request.site._id)
        otoken.save()
        
        if request.site.alias:
            site_url = "http://%s.%s" % (request.site.alias, settings.SERVER_NAME)
        else:
            site_url = "http://%s/%s" % (settings.SERVER_NAME, request.site.cname)
        
        # send email
        mail_subject = u"Password to your couchit site"
        mail_content = render_template('site/forgot_password.txt', url=site_url, token=otoken._id)
        send_mail(mail_subject, mail_content, "CouchIt <*****@*****.**>", 
            [request.site.email], fail_silently=True)
            
        request.session['notify'] = u"We've sent out the secret link. Go check your email!"
        redirect_url = url_for('site_login', back=back)
        return redirect(redirect_url)
        
    return render_response('site/forgot_password.html', back=back)
Beispiel #2
0
def site_claim(request):
    if request.method == "POST":
        site = get_site(request.site.cname)
        site.password = make_hash(request.form['password'])
        site.email = request.form['email']
        site.privacy = request.form['privacy']
        site.claimed = True
        site.save()
        request.site = site
        
        if site.alias:
            site_url = "http://%s.%s" % (site.alias, settings.SERVER_NAME)
        else:
            site_url = "http://%s/%s" % (settings.SERVER_NAME, site.cname)
        
        mail_subject = u"You claimed %s" % site_url
        mail_content = render_template("site/email_claimed.txt", url=site_url)
        send_mail(mail_subject, mail_content, "CouchIt <*****@*****.**>", 
            [site.email], fail_silently=True)
            
        if local.site_url:
            redirect_url = local.site_url
        else:
            redirect_url = '/'
        
        request.session['%s_authenticated' % site.cname] = True;
        return redirect(redirect_url)
        
    return render_response('site/claim.html')
Beispiel #3
0
def diff_page(request=None, pagename=None):
    if pagename is None:
        pagename ='Home'
    page = get_page(request.site._id, pagename)
    if not page:
        if request.is_xhr:
            return send_json({'ok': False, 'reason': 'not found'})
        raise NotFound
    
    diff = ''
    rev1 = rev2 = page
    revisions = request.values.getlist('r')
    if revisions and len(revisions) >=2:
        diff, rev1, rev2 = get_diff(page, revisions[0], revisions[1])
    
    if request.is_xhr:
         return send_json({
            'ok': True,
            'diff': render_template('page/diff_inc.html', diff=diff, rev1=rev1, rev2=rev2)
         })
     
    all_revisions = [page] + page.revisions()

    # get all pages
    pages = all_pages(request.site._id)

    return render_response('page/diff.html', page=page, pages=pages, diff=diff, rev1=rev1, 
    rev2=rev2, revisions=all_revisions)
Beispiel #4
0
def site_export(request, feedtype="atom"):
    def _zinfo(fname, date_time):
        zinfo = zipfile.ZipInfo()
        zinfo.filename = fname
        zinfo.compress_type = zipfile.ZIP_DEFLATED
        zinfo.date_time = date_time
        return zinfo
    
    pages = all_pages(request.site._id)
    if pages:
        pages.sort(lambda a,b: cmp(a.updated, b.updated))
    if feedtype == "atom":
        feed = AtomFeed(
            title="%s: Latest changes" % request.site.title and request.site.title or request.site.cname,
            subtitle=request.site.subtitle,
            updated = pages[0].updated,
            feed_url = request.url
        )
        for page in pages:
            _url = "%s%s" % (request.host_url, url_for("show_page", pagename=page.title.replace(' ', '_')))
            feed.add(page.title, escape(page.content),
            updated=page.updated, 
            url=_url,
            id=_url,
            author=page.title.replace(' ', '_')
        )
        return feed.get_response()
    elif feedtype == "json":
        json = {
            'title': "%s: Latest changes" % request.site.title and request.site.title or request.site.cname,
            'subtitle': request.site.subtitle,
            'updated':datetime_tojson(pages[0].updated),
            'pages': []
        }
        for page in pages:
            url = url_for("show_page", 
                        pagename=page.title.replace(' ', '_')
            )
            json['pages'].append({
                'title': page.title,
                'content': page.content,
                'url':  url,
                'updated':datetime_tojson(page.updated),
                'id':page.title.replace(' ', '_')
            })
        return send_json(json)
    elif feedtype == "zip":
        pages = all_pages(request.site._id)
        zip_content = StringIO()
        zfile = zipfile.ZipFile(zip_content, "w", zipfile.ZIP_DEFLATED)
        import time, codecs
        for page in pages:
             zinfo = _zinfo("markdown/%s" % smart_str(page.title.replace(" ", "_")) + ".txt", 
                        time.localtime()[:6])
             zfile.writestr(zinfo, codecs.BOM_UTF8 + page.content.encode('utf-8'))
             zinfo = _zinfo("%s" % smart_str(page.title.replace(" ", "_")) + ".html", 
                         time.localtime()[:6])
             zfile.writestr(zinfo, codecs.BOM_UTF8 + render_template("page/export.html", 
                        page=page, request=request, pages=pages).encode( "utf-8" ))
                        
        zinfo = _zinfo("index.html", time.localtime()[:6])
        zfile.writestr(zinfo,  codecs.BOM_UTF8 + render_template("page/export_index.html",
            pages=pages, request=request).encode( "utf-8" ))
         
        zfile.close()
        response = BCResponse(zip_content.getvalue())
        response.headers['content-type'] = "application/x-zip-compressed"
        return response