Exemplo n.º 1
0
    def post(self):
        # Get the posted values
        username, password = hu.getQueryValues(
            self,
            [ 'i_username',
              'i_password' ])

        # Check the username and password
        success = uau.doesUsernameAndPasswordMatch(username, password)

        # If they were correct, log in
        if success:
            uau.setCookieForUser(username, self)

            # Get the redirect page if possible
            redirectPage = '/'
            redirectQueryValue = hu.getQueryValue(self, redirectQueryKey)
            if redirectQueryValue != None and redirectQueryValue != "":
                redirectPage = urllib.unquote(redirectQueryValue)

            self.redirect(redirectPage)
            
        # Otherwise, let the user know that there was an error
        else:
            contentTemplateValues = {
                'error_message': jtr.getRenderedErrorMessage('Invalid username or password.'),
                'password': '',
                'username': username
            }

            jtr.renderContentAndPage(self, pathToContent, contentFilename, contentTemplateValues, pageTemplateValues)
Exemplo n.º 2
0
    def post(self):
        # Ensuer the user can add an outing
        if not hu.userIsAuthorized(self, uau.poster):
            return

        # Get the data
        outingName, description, departureTime, returnTime, meetLocation, outingLocation, showcase = hu.getQueryValues(
            self,
            [ 'i_outing_name',
              'ta_description',
              'i_departure_time',
              'i_return_time',
              'i_meet_location',
              'i_outing_location',
              'i_showcase' ])

        departureTime = du.tryHtmlDatetimeToPythonDatetime(departureTime)
        returnTime = du.tryHtmlDatetimeToPythonDatetime(returnTime)
        showcase = True if showcase == 'True' else False

        valid, errorMessage = ou.outingParametersAreValid(outingName, description, departureTime, returnTime, meetLocation, outingLocation, showcase)

        # If all parameters are valid, then create and store the outing
        if valid:
            creatorId = ''
            try:
                uau.getLoggedInUser(self).key().id()
            except:
                logging.info('Warning: could not determine logged in user when creating outing.')

            newOuting = ou.createOuting(outingName, description, departureTime, returnTime, meetLocation, outingLocation, showcase, creatorId)
            newOuting.put()

            time.sleep(0.25)
            self.redirect('/outings')
            return

        # Otherwise, tell the user what the errors are
        else:    
            departureTime = du.tryPythonDatetimeToHtmlDatetime(departureTime)
            returnTime = du.tryPythonDatetimeToHtmlDatetime(returnTime)

            contentTemplateValues = {
                'outings_buttons_top': ou.getOutingButtonsTop(self),
                'outing_name': outingName,
                'description': description,
                'departure_time': departureTime,
                'error_message': jtr.getRenderedErrorMessage(errorMessage),
                'meet_location': meetLocation,
                'outing_location': outingLocation,
                'return_time': returnTime,
                'showcase': showcase
            }

            # Render the page
            jtr.renderContentAndPage(self, pathToContent, contentFilename, contentTemplateValues, pageTemplateValues)