示例#1
0
 def link_user_to_new_patient(self, appointment_details_form, user, booking):
     # user but no patient
     # create a patient and link it to existing user
     patient = Patient() 
     
     # set the properties (just email)
     appointment_details_form.populate_obj(patient)
     self.set_gae_geography_from_headers(patient)
     
     # link to logged in user
     patient.user = user.key
     patient.email = user.get_email()
     
     # if it's a provider, copy over details like name, etc.
     provider = db.get_provider_from_user(user)
     if provider:
         patient.first_name = provider.first_name
         patient.last_name = provider.last_name        
     
     patient.put()
     
     booking.patient = patient.key
     booking.put()
     
     # add patient role to user
     user.roles.append(auth.PATIENT_ROLE)
     user.put()
示例#2
0
    def link_user_to_new_patient(self, appointment_details_form, user,
                                 booking):
        # user but no patient
        # create a patient and link it to existing user
        patient = Patient()

        # set the properties (just email)
        appointment_details_form.populate_obj(patient)
        self.set_gae_geography_from_headers(patient)

        # link to logged in user
        patient.user = user.key
        patient.email = user.get_email()

        # if it's a provider, copy over details like name, etc.
        provider = db.get_provider_from_user(user)
        if provider:
            patient.first_name = provider.first_name
            patient.last_name = provider.last_name

        patient.put()

        booking.patient = patient.key
        booking.put()

        # add patient role to user
        user.roles.append(auth.PATIENT_ROLE)
        user.put()
示例#3
0
    def get(self, vanity_url=None):
        provider_target = db.get_provider_from_vanity_url(vanity_url)
        
        user_source = self.get_current_user()
        if user_source and auth.PROVIDER_ROLE in user_source.roles:
            provider_source = db.get_provider_from_user(user_source)
            
            # check if there is already a pending request
            
            if provider_source in provider_target.get_provider_network_pending():
                message = _("Connection pending...")
                self.render_public_profile(provider=provider_target, success_message=message)
            elif provider_source in provider_target.get_provider_network():
                message = _("Already connected!")
                self.render_public_profile(provider=provider_target, success_message=message)
            elif provider_source == provider_target:
                message = _("You can't connect to yourself!")
                self.render_public_profile(provider=provider_target, success_message=message)
            else:
                provider_network_connection = None
                
                if provider_source in provider_target.get_provider_network_rejected():
                    # this connection was rejected before.
                    provider_network_connection = db.get_provider_network_connection(provider_source.key, provider_target.key)
                    # what the hell...let them try again!
                    provider_network_connection.rejected = False
                else:
                    # no pending request, let's make one        
                    provider_network_connection = ProviderNetworkConnection()
                    provider_network_connection.source_provider = provider_source.key
                    provider_network_connection.target_provider = provider_target.key
                    
                provider_network_connection.confirmed = False

                try:
                    provider_network_connection.put()

                    message = _("Connection requested")
                    self.render_public_profile(provider=provider_target, success_message=message)
                    
                    # now send out an email
                    # the url for accepting for target_provider
                    url_obj = urlparse.urlparse(self.request.url)
                    accept_url = urlparse.urlunparse((url_obj.scheme, url_obj.netloc, '/login/accept/' + provider_network_connection.key.urlsafe(), '', '', ''))
                        
                    mail.email_connect_request(self.jinja2, from_provider=provider_source, target_provider=provider_target, accept_url=accept_url)
                    
                except Exception as e:
                    error_message = 'Error making connection: ' + e.message
                    self.render_public_profile(provider=provider_target, error_message=error_message)

                    
        else:
            # redirect to login page if not logged in, then send back here after creditials are verified
            self.redirect("/login/connect/" + provider_target.key.urlsafe())
示例#4
0
文件: patient.py 项目: phiiil/veosan
 def get(self, patient_key=None):
     patient = ndb.Key(urlsafe=patient_key).get()
     user = db.get_user_from_email(patient.email)
     if patient:
         if auth.PROVIDER_ROLE in user.roles:
             provider = db.get_provider_from_user(user)
             self.render_bookings(self, provider=provider, patient=patient)
         else:
             self.render_bookings(self, patient=patient)
     else:
         logging.info("(ListPatientBookings) No patient associated to logged in user: %s" % user.get_email())
         self.redirect("/")
示例#5
0
    def post(self, token=None):
        password_form = PasswordForm().get_form(self.request.POST)
        
        user = self.validate_token(token)
        
        if user and password_form.validate():        
            # get password from request
            password = self.request.get('password')
                
            # hash password (same as passing password_raw to user_create)
            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)
               
            # clear the tokens to prevent further shenanigans
            provider = db.get_provider_from_user(user)
            
            redirect_url = None
            if user.resetpassword_token:
                self.delete_token(token, 'reset')
                redirect_url = '/provider/message/reset/' + provider.vanity_url
            
            elif user.claim_url:
                self.delete_token(token)
                redirect_url = '/provider/welcome/' + provider.vanity_url
            
            
            # redirect patient or provider
            if auth.PROVIDER_ROLE in user.roles:
                self.redirect(redirect_url)
                self.log_event(user, "User claimed their profile")
            
            elif auth.PATIENT_ROLE in user.roles:
                patient = db.get_patient_from_user(user)
                self.redirect('/patient/bookings/' + patient.key.urlsafe())

        # password form was not validate, re-render and try again!
        else:
            self.render_template('user/password.html', form=password_form, token=token)
示例#6
0
    def get(self, next_action=None, key=None):
        ''' Show login page '''

        user = self.get_current_user()
        if user and next_action and key:
            # if already logged in
            provider_from_user = db.get_provider_from_user(user)
            patient_from_user = db.get_patient_from_user(user)

            # check if logged in provider is the provider from
            # already logged in, don't login again
            if next_action == 'accept':
                provider_network_connection = ndb.Key(urlsafe=key).get()
                target_provider_key = provider_network_connection.target_provider

                if provider_from_user.key == target_provider_key:
                    # the target provider is logged in, accept the connection bypassing login
                    target_url = '/provider/network/' + provider_from_user.vanity_url + '/accept/' + key
                    self.redirect(target_url)
                else:
                    self.render_login(next_action=next_action, key=key)

            elif next_action == 'booking':
                booking = ndb.Key(urlsafe=key).get()

                if patient_from_user.key == booking.patient:
                    self.email_and_confirm_booking(booking)

                    self.redirect('/patient/bookings/' +
                                  patient_from_user.key.urlsafe())
                else:
                    self.render_login(next_action=next_action, key=key)

        else:
            # check if an admin is logged in, if so don't proceed
            google_user = users.get_current_user()
            if google_user and users.is_current_user_admin():
                self.render_login(error_message='Logged in as admin already.')
            else:
                # no admin, not next_action, show the plain ol' login screen
                self.render_login(next_action=next_action, key=key)
示例#7
0
    def get(self, next_action=None, key=None):
        ''' Show login page '''
        
        user = self.get_current_user()
        if user and next_action and key:
            # if already logged in
            provider_from_user = db.get_provider_from_user(user)
            patient_from_user = db.get_patient_from_user(user)
            
            # check if logged in provider is the provider from
            # already logged in, don't login again
            if next_action == 'accept':
                provider_network_connection = ndb.Key(urlsafe=key).get()
                target_provider_key = provider_network_connection.target_provider

                if provider_from_user.key == target_provider_key:
                    # the target provider is logged in, accept the connection bypassing login
                    target_url = '/provider/network/' + provider_from_user.vanity_url + '/accept/' + key
                    self.redirect(target_url)
                else:
                    self.render_login(next_action=next_action, key=key)
            
            elif next_action == 'booking':
                booking = ndb.Key(urlsafe=key).get()
                
                if patient_from_user.key == booking.patient:
                    self.email_and_confirm_booking(booking)

                    self.redirect('/patient/bookings/' + patient_from_user.key.urlsafe())
                else:
                    self.render_login(next_action=next_action, key=key)
                
        else:
            # check if an admin is logged in, if so don't proceed
            google_user = users.get_current_user()
            if google_user and users.is_current_user_admin():
                self.render_login(error_message='Logged in as admin already.')
            else:
                # no admin, not next_action, show the plain ol' login screen
                self.render_login(next_action=next_action, key=key)
示例#8
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)
示例#9
0
    def post(self, next_action=None, key=None):
        ''' checks username, password, logs in user and redirect to start page '''

        login_form = LoginForm().get_form(self.request.POST)
        if login_form.validate():
            email = login_form['email'].data
            password = login_form['password'].data
            remember_me = login_form['remember_me'].data

            logging.info('(LoginHandler.post) Trying to login email: %s' %
                         email)

            # Username and password check
            try:
                user = self.login_user(email, password, remember_me)
                user.last_login = datetime.datetime.now()
                user.put()

                # set the language from user profile
                self.set_language(user.language)

                # login was succesful, User is in the session
                if next_action == 'booking':
                    # moved booking up here since it can come from any role (provider or patient)
                    booking = ndb.Key(urlsafe=key).get()
                    patient_from_user = db.get_patient_from_user(user)

                    if patient_from_user.key == booking.patient:
                        self.email_and_confirm_booking(booking)
                        self.redirect('/patient/bookings/' +
                                      patient_from_user.key.urlsafe())

                else:
                    # check role of user, redirect to appropriate page after login
                    if auth.PROVIDER_ROLE in user.roles:
                        provider = db.get_provider_from_user(user)
                        logging.info(
                            '(LoginHandler.post) User %s logged in as provider, redirecting to profile page',
                            user.get_email())

                        # check the action, if it's from a connection do that first
                        # and then redirect back to profile page with a message
                        if next_action == 'connect':
                            connected_provider_key = ndb.Key(urlsafe=key)
                            connected_provider = connected_provider_key.get()
                            target_url = '/' + connected_provider.vanity_url + '/connect'
                            self.redirect(target_url)

                        elif next_action == 'accept':
                            target_url = '/provider/network/' + provider.vanity_url + '/accept/' + key
                            self.redirect(target_url)

                        elif provider.display_welcome_page:
                            self.redirect('/provider/welcome/' +
                                          provider.vanity_url)
                        else:
                            self.redirect('/provider/profile/%s' %
                                          provider.vanity_url)

                        # log the event
                        self.log_event(user, "Provider Logged In")

                    elif auth.PATIENT_ROLE in user.roles:
                        patient = db.get_patient_from_user(user)

                        logging.info(
                            '(LoginHandler.post) User %s logged in as patient, redirecting to / page',
                            user.get_email())
                        self.redirect('/patient/bookings/' +
                                      patient.key.urlsafe())

                    else:
                        logging.error(
                            '(LoginHandler.post) User %s logged in without roles',
                            user.get_email())
                        error_message = 'Your account is not activated. Please check your email for an activation message or <a href="/contact">contact us</a> if you require assistance.'
                        self.render_template('user/login.html',
                                             login_form=login_form,
                                             error_message=error_message)

            except (InvalidAuthIdError, InvalidPasswordError), e:
                # throws InvalidAuthIdError if user is not found, throws InvalidPasswordError if provided password doesn't match with specified user
                error_message = _(u'Login failed. Try again.')
                self.render_template('user/login.html',
                                     login_form=login_form,
                                     error_message=error_message)
            except AttributeError, ae:
                logging.warn('User has not password, authentication fails %s' %
                             ae)
示例#10
0
    def post(self, next_action=None, key=None):
        ''' checks username, password, logs in user and redirect to start page '''
        
        login_form = LoginForm().get_form(self.request.POST)
        if login_form.validate():
            email = login_form['email'].data
            password = login_form['password'].data
            remember_me = login_form['remember_me'].data
            
            logging.info('(LoginHandler.post) Trying to login email: %s' % email)

            # Username and password check
            try:
                user = self.login_user(email, password, remember_me)
                user.last_login = datetime.datetime.now()
                user.put()
                
                # set the language from user profile
                self.set_language(user.language)

                # login was succesful, User is in the session
                if next_action == 'booking':
                    # moved booking up here since it can come from any role (provider or patient)
                    booking = ndb.Key(urlsafe=key).get()
                    patient_from_user = db.get_patient_from_user(user)

                    if patient_from_user.key == booking.patient:
                        self.email_and_confirm_booking(booking)
                        self.redirect('/patient/bookings/' + patient_from_user.key.urlsafe())
                
                else:
                    # check role of user, redirect to appropriate page after login
                    if auth.PROVIDER_ROLE in user.roles:
                        provider = db.get_provider_from_user(user)
                        logging.info('(LoginHandler.post) User %s logged in as provider, redirecting to profile page', user.get_email())

                        # check the action, if it's from a connection do that first
                        # and then redirect back to profile page with a message
                        if next_action == 'connect':
                            connected_provider_key = ndb.Key(urlsafe=key)
                            connected_provider = connected_provider_key.get()
                            target_url = '/' + connected_provider.vanity_url + '/connect'
                            self.redirect(target_url)

                        elif next_action == 'accept':
                            target_url = '/provider/network/' + provider.vanity_url + '/accept/' + key
                            self.redirect(target_url)

                        elif provider.display_welcome_page:     
                            self.redirect('/provider/welcome/' + provider.vanity_url)
                        else:
                            self.redirect('/provider/profile/%s' % provider.vanity_url)

                        # log the event
                        self.log_event(user, "Provider Logged In")

                    elif auth.PATIENT_ROLE in user.roles:
                        patient = db.get_patient_from_user(user)
                        
                        logging.info('(LoginHandler.post) User %s logged in as patient, redirecting to / page', user.get_email())
                        self.redirect('/patient/bookings/' + patient.key.urlsafe())
                        
                    else:
                        logging.error('(LoginHandler.post) User %s logged in without roles', user.get_email())
                        error_message = 'Your account is not activated. Please check your email for an activation message or <a href="/contact">contact us</a> if you require assistance.'
                        self.render_template('user/login.html', login_form=login_form, error_message=error_message)
                
            except (InvalidAuthIdError, InvalidPasswordError), e:
                # throws InvalidAuthIdError if user is not found, throws InvalidPasswordError if provided password doesn't match with specified user
                error_message = _(u'Login failed. Try again.')
                self.render_template('user/login.html', login_form=login_form, error_message=error_message)
            except AttributeError, ae:
                logging.warn('User has not password, authentication fails %s' % ae)
示例#11
0
    def get(self, vanity_url=None):
        provider_target = db.get_provider_from_vanity_url(vanity_url)

        user_source = self.get_current_user()
        if user_source and auth.PROVIDER_ROLE in user_source.roles:
            provider_source = db.get_provider_from_user(user_source)

            # check if there is already a pending request

            if provider_source in provider_target.get_provider_network_pending(
            ):
                message = _("Connection pending...")
                self.render_public_profile(provider=provider_target,
                                           success_message=message)
            elif provider_source in provider_target.get_provider_network():
                message = _("Already connected!")
                self.render_public_profile(provider=provider_target,
                                           success_message=message)
            elif provider_source == provider_target:
                message = _("You can't connect to yourself!")
                self.render_public_profile(provider=provider_target,
                                           success_message=message)
            else:
                provider_network_connection = None

                if provider_source in provider_target.get_provider_network_rejected(
                ):
                    # this connection was rejected before.
                    provider_network_connection = db.get_provider_network_connection(
                        provider_source.key, provider_target.key)
                    # what the hell...let them try again!
                    provider_network_connection.rejected = False
                else:
                    # no pending request, let's make one
                    provider_network_connection = ProviderNetworkConnection()
                    provider_network_connection.source_provider = provider_source.key
                    provider_network_connection.target_provider = provider_target.key

                provider_network_connection.confirmed = False

                try:
                    provider_network_connection.put()

                    message = _("Connection requested")
                    self.render_public_profile(provider=provider_target,
                                               success_message=message)

                    # now send out an email
                    # the url for accepting for target_provider
                    url_obj = urlparse.urlparse(self.request.url)
                    accept_url = urlparse.urlunparse(
                        (url_obj.scheme, url_obj.netloc, '/login/accept/' +
                         provider_network_connection.key.urlsafe(), '', '',
                         ''))

                    mail.email_connect_request(self.jinja2,
                                               from_provider=provider_source,
                                               target_provider=provider_target,
                                               accept_url=accept_url)

                except Exception as e:
                    error_message = 'Error making connection: ' + e.message
                    self.render_public_profile(provider=provider_target,
                                               error_message=error_message)

        else:
            # redirect to login page if not logged in, then send back here after creditials are verified
            self.redirect("/login/connect/" + provider_target.key.urlsafe())
示例#12
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)