Beispiel #1
0
    def handle_exception(self, exception, debug_mode):
        logging.error(exception)
        
        site_config = db.get_site_config()
        
        kw = {}
        kw['site_config'] = site_config

        if site_config and site_config.error_email_enabled:
            mail.email_exception_report(self.request, exception)
            self.response.write(self.jinja2.render_template('error500.html', **kw))
        else:
            super(BaseHandler, self).handle_exception(exception, debug_mode)
Beispiel #2
0
    def post(self, feature=None):
        
        # validate features that can be switched
        if feature in ['booking_enabled', 'google_analytics_enabled', 'facebook_like_enabled', 'signup_enabled', 'error_email_enabled', 'welcome_email_enabled']:            
            site_config = db.get_site_config()

            # toggle state
            current_state = getattr(site_config, feature)
            
            if current_state:           
                setattr(site_config, feature, False)
                success_message = 'feature %s is now set to %s' % (feature, False)
                    
            else:
                setattr(site_config, feature, True)
                success_message = 'feature %s is now set to %s' % (feature, True)

            site_config.put()
            
            self.render_data(success_message=success_message)

        else:
            logging.error('Received unknown feature switch : %s' % feature)
Beispiel #3
0
    def post(self):
        provider_signup_form2 = forms.user.ProviderSignupForm2().get_form(
            self.request.POST, request_webob=self.request)

        # check for double submit
        # if the first submit worked, a user should have been created and logged in
        user = self.get_current_user()
        if user:
            provider = db.get_provider_from_user(user)
            if provider:
                email = provider_signup_form2['email'].data
                if email == provider.email == user.get_email():
                    # someone is already logged in with the address being submitted
                    # probably a double submit...
                    self.redirect('/provider/welcome/' + provider.vanity_url)
                    return

        if provider_signup_form2.validate():
            # init the provider
            provider = Provider()
            provider_signup_form2.populate_obj(provider)

            # pre-populate vanity_url with first name + last name + number if collision
            first_name = provider.first_name
            last_name = provider.last_name
            vanity_url = first_name + last_name

            provider.vanity_url = validate_vanity_url(vanity_url)

            provider.domain = self.get_domain()

            # set location info from request
            if "X-AppEngine-Country" in self.request.headers:
                provider.gae_country = self.request.headers[
                    "X-AppEngine-Country"]

            if "X-AppEngine-Region" in self.request.headers:
                provider.gae_region = self.request.headers[
                    "X-AppEngine-Region"]

            if "X-AppEngine-City" in self.request.headers:
                provider.gae_city = self.request.headers["X-AppEngine-City"]

            if "X-AppEngine-CityLatLong" in self.request.headers:
                provider.gae_city_lat_long = self.request.headers[
                    "X-AppEngine-CityLatLong"]

            # save provider
            provider.put()

            # check if an invitation was associated to this
            invite = db.get_invite_from_email(provider.email)
            if invite:
                invite.profile_created = True
                invite.token = None
                invite.put()

                # connect this provider to invite_provider
                provider_network_connection = ProviderNetworkConnection()
                provider_network_connection.invite = invite.key
                provider_network_connection.source_provider = invite.provider
                provider_network_connection.target_provider = provider.key
                provider_network_connection.confirmed = True

                provider_network_connection.put()

            # now create an empty user for the provider
            user = self.create_empty_user_for_provider(provider)
            user.language = self.get_language()
            user.last_login = datetime.datetime.now()
            provider.profile_language = user.language
            provider.put()

            # set the password for the user
            password = provider_signup_form2.password.data
            password_hash = security.generate_password_hash(password,
                                                            length=12)
            user.password = password_hash
            user.put()

            # login with new password
            self.login_user(user.get_email(), password)

            # new user
            logging.info(
                '(PasswordHandler.post) New user just set their password: %s' %
                user.get_email())

            self.redirect('/provider/welcome/' + provider.vanity_url)

            self.log_event(user, "New account created for user"
                           )  # create a signup token for new user

            # remove partial provider
            partial_provider = db.get_partial_provider_from_email(
                provider.email)
            if partial_provider:
                partial_provider.key.delete()

            # Send welcome email to provider
            welcome_email_enabled = db.get_site_config().welcome_email_enabled
            if welcome_email_enabled:
                mail.email_provider_welcome(self.jinja2, provider)

        else:
            self.render_template('user/signup_provider_2.html',
                                 provider_signup_form2=provider_signup_form2)
Beispiel #4
0
 def render_data(self, **kw):
     dev_server = util.is_dev_server(self.request)
     site_config = db.get_site_config()
     
     logging.info('(AdminBaseHandler.render_data) dev_server=%s' % dev_server)
     self.render_template('admin/data.html', dev_server=dev_server, site_config=site_config, **kw)
Beispiel #5
0
    def post(self):
        provider_signup_form2 = forms.user.ProviderSignupForm2().get_form(self.request.POST, request_webob=self.request)
        
        
        # check for double submit
        # if the first submit worked, a user should have been created and logged in
        user = self.get_current_user()
        if user:
            provider = db.get_provider_from_user(user)
            if provider:
                email = provider_signup_form2['email'].data
                if email == provider.email == user.get_email():
                    # someone is already logged in with the address being submitted
                    # probably a double submit...
                    self.redirect('/provider/welcome/' + provider.vanity_url)
                    return
        
        if provider_signup_form2.validate():            
            # init the provider
            provider = Provider()
            provider_signup_form2.populate_obj(provider)
            
            # pre-populate vanity_url with first name + last name + number if collision
            first_name = provider.first_name
            last_name = provider.last_name
            vanity_url = first_name + last_name

            provider.vanity_url = validate_vanity_url(vanity_url)
            
            provider.domain = self.get_domain()    
            
            
            # set location info from request
            if "X-AppEngine-Country" in self.request.headers:
                provider.gae_country = self.request.headers["X-AppEngine-Country"]
                
            if "X-AppEngine-Region" in self.request.headers:
                provider.gae_region = self.request.headers["X-AppEngine-Region"]

            if "X-AppEngine-City" in self.request.headers:
                provider.gae_city = self.request.headers["X-AppEngine-City"]
            
            if "X-AppEngine-CityLatLong" in self.request.headers:
                provider.gae_city_lat_long = self.request.headers["X-AppEngine-CityLatLong"]

            # save provider
            provider.put()
            
            # check if an invitation was associated to this
            invite = db.get_invite_from_email(provider.email)
            if invite:
                invite.profile_created = True
                invite.token = None
                invite.put()
                
                # connect this provider to invite_provider
                provider_network_connection = ProviderNetworkConnection()
                provider_network_connection.invite = invite.key
                provider_network_connection.source_provider = invite.provider
                provider_network_connection.target_provider = provider.key
                provider_network_connection.confirmed = True
            
                provider_network_connection.put()

            
            # now create an empty user for the provider
            user = self.create_empty_user_for_provider(provider)
            user.language = self.get_language()
            user.last_login = datetime.datetime.now()
            provider.profile_language = user.language
            provider.put()
            
            # set the password for the user
            password = provider_signup_form2.password.data
            password_hash = security.generate_password_hash(password, length=12)    
            user.password = password_hash
            user.put()
            
            # login with new password
            self.login_user(user.get_email(), password)

            # new user
            logging.info('(PasswordHandler.post) New user just set their password: %s' % user.get_email())
                
            self.redirect('/provider/welcome/' + provider.vanity_url)
                    
            self.log_event(user, "New account created for user")            # create a signup token for new user
                                    
            # remove partial provider
            partial_provider = db.get_partial_provider_from_email(provider.email)
            if partial_provider:
                partial_provider.key.delete()
                
            # Send welcome email to provider
            welcome_email_enabled = db.get_site_config().welcome_email_enabled
            if welcome_email_enabled:
                mail.email_provider_welcome(self.jinja2, provider)
            
            
        else:
            self.render_template('user/signup_provider_2.html', provider_signup_form2=provider_signup_form2)
Beispiel #6
0
    def render_template(self, filename, provider=None, **kw):
        '''
            Common template rendering function
        '''
                
        # domain setup
        domain_without_ports = self.request.host.split(":")[0]
        domain = domain_without_www = domain_without_ports.replace("www.", "")
        kw['domain_setup'] = db.get_domain_setup(domain_without_www)
        
        kw['valid_domains'] = util.DOMAINS
        
        # add template arguments common to all templates
        user = self.get_current_user()
        roles = []
        
        # hack for providers 
        # (allows provider pages to be accessed without a user logged in but knowing the provider key)
        kw['provider'] = provider
        kw['provider_from_user'] = None

        # somebody is logged in
        if user:
            logging.info('(BaseHandler.render_template) User logged in: %s with roles %s' % (user.get_email(), user.roles))
            kw['user'] = user
                        
            # extend roles
            roles.extend(user.roles)
            
            # is it a provider?
            if handler.auth.PROVIDER_ROLE in roles:
                provider_from_user = data.db.get_provider_from_user(user)
                logging.info('(BaseHandler.render_template) Provider logged in: ' + user.get_email())
                
                # overwrite for menu from logged in user
                kw['provider_from_user'] = provider_from_user


                # verify user->provider matches request->provider passed as paramater (ie. from request key)
                if provider: 
                    if not provider_from_user == provider:
                        logging.error("(BaseHandler.render_template) Logged in user does not match provider_key. We have a problem.")
                        
          
            if handler.auth.PATIENT_ROLE in roles:
                patient = data.db.get_patient_from_user(user)
                logging.info('(BaseHandler.render_template) Patient logged in: ' + user.get_email())
                if patient:
                    kw['patient'] = patient

        
        google_user = users.get_current_user()
        if google_user:
            logging.info('(BaseHandler.render_template) Google User also logged in: ' + str(google_user))
            kw['google_user'] = google_user

            # check google account for admin, add to roles
            if users.is_current_user_admin():
                roles.append(handler.auth.ADMIN_ROLE)
                
                # add fake login for current user
                kw['provider_from_user'] = kw['provider']

        
        # set the roles
        kw['roles'] = roles
            
        # set the language
        lang = self.get_language()
        logging.debug('(BaseHandler.render_template) Language is %s' % lang)
        kw['lang'] = lang
        kw['other_languages'] = filter(lambda l: l not in lang, util.LANGUAGE_LABELS.keys())

        # Login and logout URLs (why is this coded here? : Beacause historically for google users you had to call a method to get the login and logout urls)
        kw['login_url'] = '/' + lang + '/login'
        kw['logout_url'] = '/logout'
        kw['admin_logout_url'] = users.create_logout_url('/')
        
        kw['language_labels'] = util.LANGUAGE_LABELS
        kw['is_url_translatable'] = language.is_url_translatable(self.request.url)
        if kw['is_url_translatable']:
            kw['url_post_language'] = language.get_url_post_language(self.request.url)
        
        
        # make all session variables available to templates
        kw['session'] = self.session
        kw['host'] = self.request.host
        
        # ---------------
        # Site config
        # ---------------
        
        site_config = db.get_site_config()
        if site_config:
            kw['site_config'] = site_config
            kw['booking_enabled'] = site_config.booking_enabled
            kw['google_analytics_enabled'] = site_config.google_analytics_enabled
            kw['facebook_like_enabled'] = site_config.facebook_like_enabled

        else:
            # no site configuration exists in database, create one
            site_config = SiteConfig()
            
            # take defaul state for booking enabled from util 
            # (so it can be set before the handler is called in unit tests)
            site_config.booking_enabled = util.BOOKING_ENABLED
            
            site_config.put()
            kw['site_config'] = site_config
            kw['booking_enabled'] = site_config.booking_enabled
            kw['google_analytics_enabled'] = site_config.google_analytics_enabled
            kw['facebook_like_enabled'] = site_config.facebook_like_enabled

        # render
                
        # check if we have internet exploder
        kw['internet_explorer_old'] = False
        user_agent = self.request.headers.get('User-Agent')
        if user_agent:
            is_msie = re.search("MSIE ([0-9]{1,}[\.0-9]{0,})", user_agent);
            logging.debug("Browser User-Agent: %s" % user_agent)
    
            if is_msie:
                msie_str = is_msie.group()
                version_str = re.search("([0-9]{1,}[\.0-9]{0,})", msie_str)
    
                if version_str:
                    version = float(version_str.group())
                    if version < 9:
                        kw['internet_explorer_old'] = True
                        
                        #self.response.write(self.jinja2.render_template('internet_explorer.html', **kw))
                        site_counter = db.get_site_counter()
                        site_counter.internet_explorer_hits += 1
                        site_counter.put_async()
                else:
                    logging.error("Unable to parse version string for Internet Explorer: %s" % is_msie.group())
                    
        else:
            logging.error("Unable to parse empty user agent")
        
        self.response.write(self.jinja2.render_template(filename, **kw))
        
        self.log_entry()