Ejemplo n.º 1
0
    def get(self):
        self.current_user = users.GetCurrentUser()

        if not self.current_user:
            template_values = {
                'login_url': users.CreateLoginURL(self.request.uri),
                'app_name': APP_NAME,
                'css_link': CSS_LINK,
                'app_info': APP_INFO
            }
            template_file = 'login.html'
        else:
            self.token = self.request.get('token')

            # Manage our Authentication for the user
            self.ManageAuth()
            self.LookupToken()

            if self.client.GetAuthSubToken() is not None:
                template_values = {}
                template_file = 'index.html'
            else:
                template_values = {
                    'authsub_url':
                    self.client.GenerateAuthSubURL(
                        'http://%s/' % (HOST_NAME),
                        '%s %s' % ('http://www.google.com/m8/feeds/',
                                   'http://www.google.com/calendar/feeds'),
                        secure=False,
                        session=True),
                    'app_name':
                    APP_NAME,
                    'css_link':
                    CSS_LINK
                }
                template_file = 'authorize_access.html'

        path = os.path.join(os.path.dirname(__file__), 'main_templates',
                            template_file)
        self.response.out.write(template.render(path, template_values))
Ejemplo n.º 2
0
    def get(self):
        """GET handler that serves environment data."""
        environment_variables_output = [html_for_env_var(key)
                                        for key in sorted(os.environ)]

        cgi_arguments_output = []
        if os.getenv('CONTENT_TYPE') == 'application/x-www-form-urlencoded':
            # Note: a blank Content-type header will still sometimes
            # (in dev_appserver) show up as 'application/x-www-form-urlencoded'
            form = cgi.FieldStorage()
            if not form:
                cgi_arguments_output.append('No CGI arguments given...')
            else:
                for cgi_argument in form:
                    cgi_arguments_output.append(
                            html_for_cgi_argument(cgi_argument, form))
        else:
            data = ''
            cgi_arguments_output.append(STDIN_TEMPLATE.format(len(data)))
            cgi_arguments_output.append(cgi.escape(data))

        modules_api_output = [
            html_for_modules_method('get_current_module_name'),
            html_for_modules_method('get_current_version_name'),
            html_for_modules_method('get_current_instance_id'),
            html_for_modules_method('get_modules'),
            html_for_modules_method('get_versions'),
            html_for_modules_method('get_default_version'),
            html_for_modules_method('get_hostname'),
        ]

        result = PAGE_TEMPLATE.format(
            users.CreateLoginURL(self.request.url),
            users.CreateLogoutURL(self.request.url),
            '<br>\n'.join(environment_variables_output),
            '<br>\n'.join(cgi_arguments_output),
            '<br>\n'.join(modules_api_output),
        )

        self.response.write(result)
Ejemplo n.º 3
0
def ItemEdit(request, item_id=None):
    """Create or edit a item.  GET shows a blank form, POST processes it."""
    user, _, _ = common.GetUser(request)
    if user is None:
        return http.HttpResponseRedirect(users.CreateLoginURL(request.path))

    item = None
    original_unit_cost = None
    if item_id:
        item = models.Item.get(
            db.Key.from_path(models.Item.kind(), int(item_id)))
        if item is None:
            return http.HttpResponseNotFound(
                'No item exists with that key (%r)' % item_id)
        what = 'Changing existing Item'
        original_unit_cost = item.unit_cost
    else:
        what = 'Adding new Item'

    form = forms.ItemForm(data=request.POST or None,
                          files=request.FILES or None,
                          instance=item)

    if not request.POST:
        return common.Respond(request, 'item', {
            'form': form,
            'item': item,
            'what_you_are_doing': what
        })

    errors = form.errors
    if not errors:
        try:
            item = form.save(commit=False)
        except ValueError, err:
            errors['__all__'] = unicode(err)
Ejemplo n.º 4
0
    def get(self):
        user = users.get_current_user()
        id = self.request.get('id')

        template = jinja_environment.get_template('book.html')
        if user:
            notes = Note.query(
                ndb.AND(Note.book_id == id,
                        Note.user_key == user.user_id())).fetch()
            template_values = {'id': id, 'notes': notes, 'user': user}
            email = user.email()
            logout_url = users.CreateLogoutURL('/book?id=' + id)
            template1 = jinja_environment.get_template('sign-out.html')
            template_values1 = {'email': email, 'logout_url': logout_url}
            self.response.out.write(
                template.render(template_values) +
                template1.render(template_values1))
        else:
            login_url = users.CreateLoginURL('/book?id=' + id)
            template1 = jinja_environment.get_template('sign-in.html')
            template_values = {'login_url': login_url}
            self.response.out.write(
                template.render({'id': id}) +
                template1.render(template_values))
Ejemplo n.º 5
0
 def get(self):
     if users.GetCurrentUser() is None:
         login_url = users.CreateLoginURL(self.request.uri)
         self.redirect(login_url)
     else:
         _write_html(self.response)
Ejemplo n.º 6
0
def commonUserCode(params, url):
    #user = users.get_current_user()  #for Google  user

    mySession = Session()  #our own user is stored in Session variable

    if 'username' in mySession:
        user = mySession['username']
    else:
        user = ""

    if 'userDomain' in mySession:
        userDomain = mySession['userDomain']
    else:
        userDomain = ""

    if 'OneCloudStatus' in mySession:
        OneCloudStatus = mySession['OneCloudStatus']
    else:
        OneCloudStatus = ""

    isAdmin = False
    if 'isAdmin' in mySession:
        isAdmin = mySession['isAdmin']

    if (url.lower().find("8080")) > -1:
        environment = "test"
    else:
        environment = "production"

    params['environment'] = environment

    #if user:
    if 'username' in mySession:
        params['userMessage'] = "Signed in"
        params['user'] = user
        params['sign_out'] = users.CreateLogoutURL('/')
        #params['is_admin'] = (users.IsCurrentUserAdmin() and 'Dev' in os.getenv('SERVER_SOFTWARE'))
        params['is_admin'] = isAdmin
        #get session variables to display on form
        #domainKey = users.get_current_user().email() + ":customerDomain";
        domainKey = user + ":customerDomain"
        params['customerDomain'] = memcache.get(domainKey)
        #domainKey = user + ":startTime";
        #params['startedDateTime'] = memcache.get(domainKey);
        params['sign_in'] = None
        params['userDomain'] = userDomain
        params['OneCloudStatus'] = OneCloudStatus
    else:
        #params['sign_in'] = users.CreateLoginURL(self.request.path)
        params['sign_in'] = users.CreateLoginURL(url)
        params['userMessage'] = "Not signed in"
        params['user'] = None
        params['is_admin'] = None
        params['customerDomain'] = None
        params['startedDateTime'] = None
        params['sign_out'] = None
        params['userDomain'] = None
        params['OneCloudStatus'] = None
        #self.response.out.write(
        #   "<h3> self.request.path = " + self.request.path + "</h3>" +
        #   "<h3>Debug LoginURL=" + users.CreateLoginURL(self.request.path) + "</h3>");
        #return;
    return params
Ejemplo n.º 7
0
def login():
    return redirect(users.CreateLoginURL('/dashboard'))