Пример #1
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)
Пример #2
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)