Exemple #1
0
    def post_setpe(self, token, password, confirm):
        try:
            self.context.auth.setpw(token, password, confirm)
        except UserError as err:
            return bobo.redirect('setpw?token=%s&%s' %
                                 (token, urllib.parse.quote(str(err))))

        return bobo.redirect('login')
Exemple #2
0
    def post_login(self, email, password):
        try:
            user = self.context.auth.login_creds(email, password)
        except UserError as err:
            response = bobo.redirect('/auth/login?message=' +
                                     urllib.parse.quote(str(err)))
        else:
            response = bobo.redirect('/')
            jwtauth.save(response,
                         self.context.auth.secret,
                         uid=user.id,
                         generation=user.generation)

        return response
def quote(quote_id):
    template = template_loader.load('quote.html')
    quote = Quotes.get_by_id(int(quote_id))
    # post-hoc attempt at geocoding based on the city and state
    if quote and quote.location=='0.0,0.0':
        address = quote.city+', '+quote.state
        address = address.replace(' ', '+')
        url="http://maps.google.com/maps/api/geocode/json?address=%s&sensor=false" % address
        try:
            # some queries to Google aren't returning data, or are timing out,
            # which causes the errors we'd been seeing. Wrapping a try around
            # it insulates us from the error.
            response = urlfetch.fetch(url, deadline=10)
            jsongeocode = response.content
            geocode = json.loads(jsongeocode)
            quote.location.lat = geocode['results'][0]['geometry']['location']['lat']
            quote.location.lon = geocode['results'][0]['geometry']['location']['lng']
            quote.put()
        except: pass
    # Test if the quote exists, and if it is marked as 'safe' (the default). 
    if quote and quote.safe:
        return template(master=master, quote=quote)
    # Otherwise, redirect to the homepage.
    else:
         return bobo.redirect('/')
def quote(quote_id):
    template = template_loader.load('quote.html')
    quote = Quotes.get_by_id(int(quote_id))
    # post-hoc attempt at geocoding based on the city and state
    if quote and quote.location == '0.0,0.0':
        address = quote.city + ', ' + quote.state
        address = address.replace(' ', '+')
        url = "http://maps.google.com/maps/api/geocode/json?address=%s&sensor=false" % address
        try:
            # some queries to Google aren't returning data, or are timing out,
            # which causes the errors we'd been seeing. Wrapping a try around
            # it insulates us from the error.
            response = urlfetch.fetch(url, deadline=10)
            jsongeocode = response.content
            geocode = json.loads(jsongeocode)
            quote.location.lat = geocode['results'][0]['geometry']['location'][
                'lat']
            quote.location.lon = geocode['results'][0]['geometry']['location'][
                'lng']
            quote.put()
        except:
            pass
    # Test if the quote exists, and if it is marked as 'safe' (the default).
    if quote and quote.safe:
        return template(master=master, quote=quote)
    # Otherwise, redirect to the homepage.
    else:
        return bobo.redirect('/')
Exemple #5
0
def index(bobo_request):
    t = db.table("access")
    t.insert({
        "date": datetime.datetime.now().timetuple()[:3],
        "ip": bobo_request.remote_addr
    })
    return bobo.redirect(url='/static/main/main1.html')
Exemple #6
0
def add(bobo_request):
	doc = {}
	for k in bobo_request.POST:
		doc[k] = bobo_request.POST[k]
	
	col = get_collection()
	col.insert(doc)
	return bobo.redirect('/')
Exemple #7
0
def add(quote, name, city, state):
    rand = random.random()
    new_quote = Quotes(quote=quote,
                       name=name,
                       city=city,
                       state=state,
                       rand=rand,
                       location='0,0')
    new_quote.put()
    return bobo.redirect('/q/' + str(new_quote.key().id()))
def add(quote, name, city, state, lat, lon, errormsg):
    rand = random.random()
    # Note: we're not doing any server-side validation (other than that
    # enforced by the data model), so we're a bit over-reliant on the 
    # client side validation. A user who has JS turned off and submits bad
    # data would see an unfriendly error message.
    new_quote = Quotes(quote=quote, name=name, city=city,
                       state=state, rand=rand, location=lat+','+lon,
                      errormsg=errormsg)
    new_quote.put()
    # after crrating the quote, redirect to the new quote's page. 
    return bobo.redirect('/q/'+str(new_quote.key().id()))
Exemple #9
0
def show_article(title):
    sql_db = query.DB(SQLDB_PATH)
    article = sql_db.search('blog', ('title', title))
    if len(article) == 0:
        sql_db.close()
        return bobo.redirect('/')
    else:
        html = ''
        with open(cdr + '/template/show.html', 'r', encoding='utf-8') as show:
            html = show.read()
            m = re.search('{article_my}', html)
            html = html[:m.span()[0]] + next(wrap_article_result(article))['content']+\
                html[m.span()[1]:]
        sql_db.close()
        return html
def add(quote, name, city, state, lat, lon, errormsg):
    rand = random.random()
    # Note: we're not doing any server-side validation (other than that
    # enforced by the data model), so we're a bit over-reliant on the
    # client side validation. A user who has JS turned off and submits bad
    # data would see an unfriendly error message.
    new_quote = Quotes(quote=quote,
                       name=name,
                       city=city,
                       state=state,
                       rand=rand,
                       location=lat + ',' + lon,
                       errormsg=errormsg)
    new_quote.put()
    # after crrating the quote, redirect to the new quote's page.
    return bobo.redirect('/q/' + str(new_quote.key().id()))
Exemple #11
0
 def post_request(self, email, name):
     try:
         message = self.context.auth.request(email, name,
                                             self.base.request.host_url)
     except UserError as err:
         return bobo.redirect('/auth/request?message=' +
                              urllib.parse.quote(str(err)))
     else:
         return template('message.html').render(
             title=self.context.title,
             heading="Thank you.",
             message="""
             Thank you for your request to use %s.
             Your request will be reviewed and, if approved, you
             will recieve an email with a link to set your
             password.""" % self.context.title,
         )
Exemple #12
0
    def run_app(env, start):
        request = webob.Request(env)

        token = request.cookies.get(TOKEN)
        old_email = email = None
        if token:
            try:
                email = serializer.loads(token)
            except itsdangerous.BadTimeSignature:
                pass # just don't log them in
            else:
                old_email = env.get('REMOTE_USER')
                env['REMOTE_USER'] = email

        try:
            if env['PATH_INFO'].startswith(prefix):
                return persona_app(env, start)
            else:
                needs_login = []
                def start_response(status, headers, exc_info=None):
                    if status.startswith("401 "):
                        needs_login.append(0)
                    else:
                        start(status, headers, exc_info)
                it = app(env, start_response)
                if needs_login:
                    return bobo.redirect(
                        prefix+'/login.html?came_from='+env['PATH_INFO']
                        )(env, start)
                else:
                    return it
        finally:
            if email:
                if old_email:
                    env['REMOTE_USER'] = old_email
                else:
                    del env['REMOTE_USER']
Exemple #13
0
def login(bobo_request, where=None):
    if bobo_request.remote_user:
        return bobo.redirect(where or bobo_request.relative_url('.'))
    return webob.Response(status=401)
Exemple #14
0
def query(short):
    if short in tcache:
        return bobo.redirect(str(tcache.get_value(short)))
    else:
        return webob.Response("not found, sorry", status=404)
Exemple #15
0
 def logout(self):
     response = bobo.redirect('/auth/login')
     response.set_cookie(jwtauth.TOKEN, '')
     return response
Exemple #16
0
def save(bobo_request, name, body):
    with open(os.path.join(top, name), "wb") as f:
        f.write(body.encode('UTF-8'))
    return bobo.redirect(bobo_request.path_url, 303)
Exemple #17
0
def authenticated(self, request, func):
    if not request.remote_user:
        return bobo.redirect(login_url(request))
Exemple #18
0
def save(bobo_request, name, body):
    with open(os.path.join(top, name), "wb") as f:
        f.write(body.encode('UTF-8'))
    return bobo.redirect(bobo_request.path_url, 303)
Exemple #19
0
 def login(self, request):
     return bobo.redirect('/auth/login')
def add(quote, name, city, state):
    rand = random.random()
    new_quote = Quotes(quote=quote, name=name, city=city,
                       state=state, rand=rand, location='0,0')
    new_quote.put()
    return bobo.redirect('/q/'+str(new_quote.key().id()))
Exemple #21
0
def redirect():
    return bobo.redirect('/')
Exemple #22
0
def save(bobo_request, name, body):
    open(os.path.join(top, name), 'w').write(body)
    return bobo.redirect(bobo_request.path_url, 303)
Exemple #23
0
def login(bobo_request, where=None):
    if bobo_request.remote_user:
        return bobo.redirect(where or bobo_request.relative_url('.'))
    return webob.Response(status=401)
Exemple #24
0
def checker(inst, request, func):
    email = zc.wsgisessions.sessions.get(request, __name__, 'email')
    if not email:
        return bobo.redirect("/login.html")
Exemple #25
0
def logout(bobo_request, where=None):
    response = bobo.redirect(where or bobo_request.relative_url('.'))
    response.delete_cookie('wiki')
    return response
Exemple #26
0
def authenticated(self, request, func):
    if not request.remote_user:
        return bobo.redirect(login_url(request))
Exemple #27
0
def save(bobo_request, name, body):
    open(os.path.join(top, name), 'w').write(body)
    return bobo.redirect(bobo_request.path_url, 303)
Exemple #28
0
def lp(bobo_request, text):
	from subprocess import Popen
	from shlex import split
	open('tempfile','w').write('\n'+text.encode('ascii', 'replace'))
	Popen(split('lp tempfile -d Brother_QL-580N')).wait()
	return bobo.redirect('/printed')
Exemple #29
0
def logout(bobo_request, where=None):
    response = bobo.redirect(where or bobo_request.relative_url('.'))
    response.delete_cookie('wiki')
    return response
Exemple #30
0
 def base(self, bobo_request):
     return bobo.redirect(bobo_request.url + '/')
 def login(*_):
     return bobo.redirect(no_site_url)
Exemple #32
0
 def base(self, bobo_request):
     return bobo.redirect(bobo_request.url+'/')
Exemple #33
0
def favicon():
	return bobo.redirect('/img/favicon.ico')