def renderHTTP(self, ctx): """Handle HTTP requests.""" srv = IService(ctx) request = IRequest(ctx) current = must_user(ctx) user = srv.validate_challenge( # pylint: disable-msg=E1101 self.challenge, current.session) if user: message(ctx, u'Bienvenue, %s' % (user.email, )) request.redirect("/") request.finish() return '' # Some people simply reuse invitations: don't complain if they # are already connected, just redirect them to the main page. avatar = maybe_user(ctx) if avatar.identified: request.redirect("/") request.finish() return '' # pylint: disable-msg=E1101 self.contentTags = [ T.h1[u"Cette clé n'est pas valable"], T.p[u"Vous pouvez obtenir une nouvelle clé par e-mail.", T.div(_class="editable bl")[T.div(_class="br")[T.div( _class="tl")[T.div(_class="tr")[T.div( _class="edcontent")[login.LoginFragment( original=login.LoginInfo( force_reconnect=True))], ]]]]] ] return BasePage.renderHTTP(self, ctx)
def _create_list(self, ctx, name, email): """Actually create the new list.""" req = IRequest(ctx) srv = IService(ctx) avatar = must_user(ctx) # pylint: disable-msg=E1101 wl = srv.createList(avatar.user, name, email) if not wl: req.redirect('/') req.finish() return if not avatar.identified: message( ctx, u"Un message de confirmation a été envoyé" u" à l'adresse <%s>." % (email, )) req.redirect('/' + wl.url) req.finish()
def data_form(self, ctx, _): """Return the options passed in the invitation form.""" req = IRequest(ctx) warn = [] vals = {'msg': ''} srv = IService(ctx) avatar = must_user(ctx) user = avatar.user # pylint: disable-msg=E1101 if req.method == 'POST': if not arg(req, 'send'): req.redirect('/') req.finish() return self._defaults if not avatar.identified: warn.append(u"Vous n'avez pas encore activé votre compte.") vals['sender'] = arg(req, 'sender') if not vals['sender']: warn.append(u"Vous n'avez pas précisé votre nom.") vals['email'] = arg(req, 'email') if not vals['email']: warn.append(u"Vous n'avez pas précisé de destinataire.") vals['body'] = arg(req, 'body') if not vals['body']: warn.append(u"Votre message n'a pas de contenu.") # We simply filter out lists that don't belong to the # user. vals['lst'] = _my_lists(req.args.get('lst', []), srv, user) if not vals['lst']: warn.append(u"Choisissez au moins une liste ci-dessous.") vals['warn'] = warn if not warn: if not srv.inviteFriend(vals['sender'], user, vals['lst'], vals['email'], vals['body']): warn.append(u"L'adresse <%s> n'est pas valide." % (vals['email'], )) else: vals['msg'] = u'Votre invitation a été envoyée à %s' % ( vals['email'], ) # When we have sent properly, forget the previous # emails, so we don't double-send by mistake. vals['email'] = '' else: vals = self._defaults vals['lst'] = _my_lists(req.args.get('lst', []), srv, user) return vals
def renderHTTP(self, ctx): req = IRequest(ctx) gte = static.getTypeAndEncoding ctype, encoding = gte( self.filename, static.File.contentTypes, static.File.contentEncodings, defaultType="text/plain" ) req.setHeader("content-type", ctype) if encoding: req.setHeader("content-encoding", encoding) if boolean_of_arg(get_arg(req, "save", "False")): # tell the browser to save the file rather display it we don't # try to encode the filename, instead we echo back the exact same # bytes we were given in the URL. See the comment in # FileNodeHandler.render_GET for the sad details. req.setHeader("content-disposition", 'attachment; filename="%s"' % self.filename) filesize = self.filenode.get_size() assert isinstance(filesize, (int, long)), filesize first, size = 0, None contentsize = filesize req.setHeader("accept-ranges", "bytes") if not self.filenode.is_mutable(): # TODO: look more closely at Request.setETag and how it interacts # with a conditional "if-etag-equals" request, I think this may # need to occur after the setResponseCode below si = self.filenode.get_storage_index() if si: req.setETag(base32.b2a(si)) # TODO: for mutable files, use the roothash. For LIT, hash the data. # or maybe just use the URI for CHK and LIT. rangeheader = req.getHeader("range") if rangeheader: ranges = self.parse_range_header(rangeheader) # ranges = None means the header didn't parse, so ignore # the header as if it didn't exist. If is more than one # range, then just return the first for now, until we can # generate multipart/byteranges. if ranges is not None: first, last = ranges[0] if first >= filesize: raise WebError("First beyond end of file", http.REQUESTED_RANGE_NOT_SATISFIABLE) else: first = max(0, first) last = min(filesize - 1, last) req.setResponseCode(http.PARTIAL_CONTENT) req.setHeader("content-range", "bytes %s-%s/%s" % (str(first), str(last), str(filesize))) contentsize = last - first + 1 size = contentsize req.setHeader("content-length", str(contentsize)) if req.method == "HEAD": return "" d = self.filenode.read(req, first, size) def _error(f): log.msg("error during GET", facility="tahoe.webish", failure=f, level=log.UNUSUAL, umid="xSiF3w") req._tahoe_request_had_error = f # for HTTP-style logging if req.startedWriting: # The content-type is already set, and the response code has # already been sent, so we can't provide a clean error # indication. We can emit text (which a browser might # interpret as something else), and if we sent a Size header, # they might notice that we've truncated the data. Keep the # error message small to improve the chances of having our # error response be shorter than the intended results. # # We don't have a lot of options, unfortunately. req.write("problem during download\n") req.finish() else: # We haven't written anything yet, so we can provide a # sensible error message. eh = MyExceptionHandler() eh.renderHTTP_exception(ctx, f) d.addCallbacks(lambda ign: req.finish(), _error) return req.deferred