def redirect(self, request, uri): """ Makes internal redirect into the resource tree """ uri = normalizeUri(uri) request.prepath = [] request.postpath = string.split(request.uri[1:], '/')
def post_Share(self, request): user = self.getUser(request) shareConfig = config.Config['share'] path = request.params['path'] path = re.sub(r'/{2,}', '/', path) toEmail = request.params['to_email'] expiration = shareConfig['expiration'] if request.params.get('days'): expiration = 86400 * int(request.params['days']) cipher = SecureLink(**shareConfig['secret']) tokenURL = shareConfig['host'] + '/' + cipher.encode(shareConfig['methods'], user.getIdentity(), path, shareConfig['prefixes'], 255, expiration=expiration ) fromEmail = user.getIdentity() shareName = normalizeUri(os.path.basename(path)) if shareName == '': shareName = '/' elif len(shareName) > 30: shareName = shareName[0:27]+'...' body = shareConfig['email']['body'] vars = { 'email':fromEmail, 'folder': shareName, 'url': tokenURL, 'expirationDate': datetime.datetime.fromtimestamp(time.time()+expiration).strftime('%Y-%m-%d %H:%M:%S') } for (key, value) in vars.items(): body=body.replace("#%s#" % key, value) if not email_re.match(fromEmail): fromEmail = shareConfig['email']['from'] logging.getLogger().debug('post_Share: %s' % body ) # send the email email = mail.EmailMessage( subject=shareConfig['email']['subject'] % shareName, body=body, from_email=fromEmail, to=[toEmail], headers = shareConfig['email']['headers'] ) try: email.send() except: return {'code':'failure', 'body': 'Unable to send email. Please try again later.'} return {'body': 'Share invitation was send successfully.'}