示例#1
0
 def get_template_from_request(self, request,
                               html_template = 'html_response',
                               **kw):
     if self.is_type(request, 'json'):
         template = get_template('json_response')
         content_type = 'application/json'
     else:
         template = get_template(html_template)
         content_type = 'text/html'
     return (content_type, template)
示例#2
0
    def get_user_info(self, request, **params):
        """ Display the appropriate user page or discovery page """
        user_info = {}
        user = str(request.sync_info['user'])
        params = {'user': user,
                  'host': self.app.config['oid.host'],
                  'config': self.app.config,
                  'request': request }

        uid = self.get_session_uid(request)
        if uid is not None:
            # Convert the user name to a standardized token
            user_name = extract_username(user)
            user_id = self.app.auth.backend.get_user_id(user_name)
            if user_id == uid:
                # hey that's me !
                user_info = self.app.storage.get_user_info(user_id) or {}
                params['user_info'] = user_info
                params['sig'] = self.gen_signature(uid, request)
        # Use the older style of discovery (with link refs)
        template = get_template('user')
        ct = 'text/html'
        res = template.render(**params)
        response = Response(str(res), content_type=ct)
        if not user_info:
            response.delete_cookie('beaker.session.id')
        return response
示例#3
0
 def send_validate_email(self, uid, email, nosend = False, **kw):
     """ Send an email containing the validation token URL to the
         newly registered email, and add the email to the list of
         unvalidated emails.
     """
     #first, generate a token:
     user = self.app.storage.get_user_info(uid)
     if user is None:
         return False
     mailserv_name = self.app.config.get('oid.mail_server',
                                               'localhost')
     reply_to = self.app.config.get('oid.reply_to',
                                    'no-reply@' + mailserv_name)
     #store the unverified email
     unv_emails = user.get('unv_emails', {})
     if (email not in unv_emails):
         rtoken = self.app.storage.add_validation(uid, email)
     else:
         rtoken = self.app.storage.get_validation_token(uid, email)
     # format the email and send it on it's merry way.
     template = get_template('validate_email_body')
     verify_url = (self.app.config.get('oid.validate_host',
                                      'http://localhost') +
                                     '/%s/validate/%s' % (VERSION, rtoken))
     body = template.render(from_addr =
                             self.app.config.get('oid.from_address',
                                                 reply_to),
                            to_addr = email,
                            reply_to = reply_to,
                            verify_url = verify_url)
     if (not nosend and not self.app.config.get('test.nomail', False)):
         #for testing, we don't send out the email. (Presume that works.)
         logger.debug('sending validation email to %s' % email)
         server = smtplib.SMTP(mailserv_name)
         server.sendmail(reply_to,
                         email,
                         body)
         server.quit()
     return True
示例#4
0
        uid = self.get_uid(request, strict = False)
        if not uid:
            extra = {'validate': token}
            return self.login(request, extra)
        body = ""
        try:
            email = self.app.storage.check_validation(uid, token)
        except OIDStorageException, ex:
            logger.error('Could not check token for user %s, %s' %
                         (uid, str(ex)))
            raise HTTPBadRequest()
        if not email:
            logger.error('No email associated with uid:%s and token:% ' %
                         (uid, token))
            raise HTTPBadRequest()
        template = get_template('validation_confirm')
        user = self.app.storage.get_user_info(uid)
        body = template.render(request = request,
                               user = user,
                               email = email,
                               config = self.app.config)
        return Response(str(body), content_type = 'text/html')

    def verify_address(self, request, **kw):
        """ Verify a given address (unused?)
        """
        if not self.is_internal(request):
            raise HTTPForbidden()
        ## Only logged in users can play
        uid = self.get_session_uid(request)
        if uid is None: