Python google.appengine.api.users.create_login_url() Examples
The following are 30
code examples of google.appengine.api.users.create_login_url().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
google.appengine.api.users
, or try the search function
.
Example #1
Source File: util.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def login_required(handler_method): """A decorator to require that a user be logged in to access a handler. To use it, decorate your get() method like this: @login_required def get(self): user = users.get_current_user(self) self.response.out.write('Hello, ' + user.nickname()) We will redirect to a login page if the user is not logged in. We always redirect to the request URI, and Google Accounts only redirects back as a GET request, so this should not be used for POSTs. """ def check_login(self, *args): if self.request.method != 'GET': raise webapp.Error('The check_login decorator can only be used for GET ' 'requests') user = users.get_current_user() if not user: self.redirect(users.create_login_url(self.request.uri)) return else: handler_method(self, *args) return check_login
Example #2
Source File: dschat.py From dschat with MIT License | 6 votes |
def post(self): user = users.get_current_user() if not user: # This should never happen, as AppEngine should only run this # handler if the user is signed in. But defense in depth applies... self.redirect(users.create_login_url(self.request.uri)) return older_than_id = self.request.get('older_than') older_than = datetime.datetime.strptime(older_than_id, "%Y-%m-%dT%H:%M:%S.%f") query = Message.query(ancestor=messages_key()).filter(Message.date < older_than ).order(-Message.date) # Limit query to 50 messages: query_results = query.fetch(50) if len(query_results) > 0: broadcast = MessagesBroadcast(query_results) broadcast.send_messages(user.user_id())
Example #3
Source File: main.py From datastore-ndb-python with Apache License 2.0 | 6 votes |
def get(self): user = users.get_current_user() if not user: self.redirect(users.create_login_url('/account')) return email = user.email() action = 'Create' account, nickname = yield (get_account(user.user_id()), get_nickname(user.user_id())) if account is not None: action = 'Update' if account: proposed_nickname = account.nickname or account.email else: proposed_nickname = email values = {'email': email, 'nickname': nickname, 'proposed_nickname': proposed_nickname, 'login': users.create_login_url('/home'), 'logout': users.create_logout_url('/home'), 'action': action, } self.response.out.write(ACCOUNT_PAGE % values)
Example #4
Source File: main.py From datastore-ndb-python with Apache License 2.0 | 6 votes |
def post(self): # TODO: XSRF protection. @ndb.tasklet def helper(): user = users.get_current_user() if not user: self.redirect(users.create_login_url('/account')) return account = yield get_account(user.user_id()) if self.request.get('delete'): if account: yield account.key.delete_async() self.redirect('/account') return if not account: account = Account(key=account_key(user.user_id()), email=user.email(), userid=user.user_id()) nickname = self.request.get('nickname') if nickname: account.nickname = nickname yield account.put_async() self.redirect('/account') yield ndb.transaction_async(helper)
Example #5
Source File: main.py From danforth-east with MIT License | 6 votes |
def get(self): user = users.get_current_user() if not user: self.redirect(users.create_login_url(self.request.uri)) return elif not gapps.is_user_authorized(user): self.redirect('/bad-user') return csrf_token = helpers.get_csrf_token(self.request) volunteer_interests = gapps.get_volunteer_interests() skills_categories = gapps.get_skills_categories() template_values = { 'FIELDS': config.FIELDS, 'csrf_token': csrf_token, 'volunteer_interests': volunteer_interests, 'skills_categories': skills_categories, 'config': config, } template = JINJA_ENVIRONMENT.get_template('new-member.jinja') helpers.set_csrf_cookie(self.response, csrf_token) self.response.write(template.render(template_values))
Example #6
Source File: main.py From danforth-east with MIT License | 6 votes |
def get(self): user = users.get_current_user() if not user: self.redirect(users.create_login_url(self.request.uri)) return elif not gapps.is_user_authorized(user): self.redirect('/bad-user') return csrf_token = helpers.get_csrf_token(self.request) volunteer_interests = gapps.get_volunteer_interests() skills_categories = gapps.get_skills_categories() template_values = { 'FIELDS': config.FIELDS, 'csrf_token': csrf_token, 'volunteer_interests': volunteer_interests, 'skills_categories': skills_categories, 'config': config, } template = JINJA_ENVIRONMENT.get_template('renew-member.jinja') helpers.set_csrf_cookie(self.response, csrf_token) self.response.write(template.render(template_values))
Example #7
Source File: main.py From danforth-east with MIT License | 6 votes |
def get(self): user = users.get_current_user() if not user: self.redirect(users.create_login_url(self.request.uri)) return elif not gapps.is_user_authorized(user): self.redirect('/bad-user') return csrf_token = helpers.get_csrf_token(self.request) template_values = { 'FIELDS': config.FIELDS, 'csrf_token': csrf_token, 'config': config, } template = JINJA_ENVIRONMENT.get_template('authorize-user.jinja') helpers.set_csrf_cookie(self.response, csrf_token) self.response.write(template.render(template_values))
Example #8
Source File: main.py From python-docs-samples with Apache License 2.0 | 6 votes |
def index(): user = users.get_current_user() if user: logged_in = True nickname = user.nickname() logout_url = users.create_logout_url('/') login_url = None else: logged_in = False nickname = None logout_url = None login_url = users.create_login_url('/') template_values = { 'logged_in': logged_in, 'nickname': nickname, 'logout_url': logout_url, 'login_url': login_url, } return flask.render_template('index.html', **template_values) # Fake status
Example #9
Source File: blogapp.py From python-for-android with Apache License 2.0 | 6 votes |
def get(self): template_values = { 'sign_out': users.create_logout_url('/') } # See if we have an auth token for this user. token = get_auth_token(self.request) if token is None: template_values['auth_url'] = gdata.gauth.generate_auth_sub_url( self.request.url, ['http://www.blogger.com/feeds/']) path = os.path.join(os.path.dirname(__file__), 'auth_required.html') self.response.out.write(template.render(path, template_values)) return elif token == False: self.response.out.write( '<html><body><a href="%s">You must sign in first</a>' '</body></html>' % users.create_login_url('/blogs')) return client = gdata.blogger.client.BloggerClient() feed = client.get_blogs(auth_token=token) template_values['feed'] = feed path = os.path.join(os.path.dirname(__file__), 'list_blogs.html') self.response.out.write(template.render(path, template_values))
Example #10
Source File: helloworld.py From cloud-playground with Apache License 2.0 | 6 votes |
def get(self): # pylint:disable-msg=invalid-name """Handle GET requests.""" guestbook_name = self.request.get('guestbook_name') greetings_query = Greeting.all().ancestor( _GuestbookKey(guestbook_name)).order('-date') greetings = greetings_query.fetch(10) if users.get_current_user(): url = users.create_logout_url(self.request.uri) url_linktext = 'Logout' else: url = users.create_login_url(self.request.uri) url_linktext = 'Login' template_values = { 'greetings': greetings, 'url': url, 'url_linktext': url_linktext, } template = jinja_environment.get_template('index.html') self.response.out.write(template.render(template_values))
Example #11
Source File: status_ui.py From browserscope with Apache License 2.0 | 6 votes |
def get(self, resource=''): import pipeline # Break circular dependency if pipeline._ENFORCE_AUTH: if users.get_current_user() is None: self.redirect(users.create_login_url(self.request.url)) return if not users.is_current_user_admin(): self.response.out.write('Forbidden') self.response.set_status(403) return if resource not in self._RESOURCE_MAP: logging.info('Could not find: %s', resource) self.response.set_status(404) self.response.out.write("Resource not found.") self.response.headers['Content-Type'] = 'text/plain' return relative_path, content_type = self._RESOURCE_MAP[resource] path = os.path.join(os.path.dirname(__file__), relative_path) if not pipeline._DEBUG: self.response.headers["Cache-Control"] = "public, max-age=300" self.response.headers["Content-Type"] = content_type self.response.out.write(open(path, 'rb').read())
Example #12
Source File: main_hmac.py From python-for-android with Apache License 2.0 | 5 votes |
def get(self): if not users.get_current_user(): self.redirect(users.create_login_url(self.request.uri)) access_token = gdocs.token_store.find_token('%20'.join(SETTINGS['SCOPES'])) if isinstance(access_token, gdata.auth.OAuthToken): form_action = '/fetch_data' form_value = 'Now fetch my docs!' revoke_token_link = True else: form_action = '/get_oauth_token' form_value = 'Give this website access to my Google Docs' revoke_token_link = None template_values = { 'form_action': form_action, 'form_value': form_value, 'user': users.get_current_user(), 'revoke_token_link': revoke_token_link, 'oauth_token': access_token, 'consumer': gdocs.GetOAuthInputParameters().GetConsumer(), 'sig_method': gdocs.GetOAuthInputParameters().GetSignatureMethod().get_name() } path = os.path.join(os.path.dirname(__file__), 'index.html') self.response.out.write(template.render(path, template_values))
Example #13
Source File: main.py From arithmancer with Apache License 2.0 | 5 votes |
def CheckSignIn(): user = users.get_current_user() if not user: login_url = users.create_login_url('/') greeting = '<a href="{}">Sign in</a>'.format(login_url) return render_template('splash.html', login=login_url) else: profile = check_if_user_profile(user.user_id()) return redirect('/predictions')
Example #14
Source File: ui.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def __call__(self, environ, start_response): if not environ.get('SERVER_SOFTWARE', '').startswith('Dev'): if not users.is_current_user_admin(): if users.get_current_user() is None: start_response('302 Found', [('Location', users.create_login_url(os.getenv('PATH_INFO', '')))]) return [] else: start_response('403 Forbidden', []) return ['Forbidden\n'] return self._application(environ, start_response)
Example #15
Source File: appengine.py From luci-py with Apache License 2.0 | 5 votes |
def oauth_aware(self, method): """Decorator that sets up for OAuth 2.0 dance, but doesn't do it. Does all the setup for the OAuth dance, but doesn't initiate it. This decorator is useful if you want to create a page that knows whether or not the user has granted access to this application. From within a method decorated with @oauth_aware the has_credentials() and authorize_url() methods can be called. Args: method: callable, to be decorated method of a webapp.RequestHandler instance. """ def setup_oauth(request_handler, *args, **kwargs): if self._in_error: self._display_error_message(request_handler) return user = users.get_current_user() # Don't use @login_decorator as this could be used in a # POST request. if not user: request_handler.redirect(users.create_login_url( request_handler.request.uri)) return self._create_flow(request_handler) self.flow.params['state'] = _build_state_value(request_handler, user) self.credentials = self._storage_class( self._credentials_class, None, self._credentials_property_name, user=user).get() try: resp = method(request_handler, *args, **kwargs) finally: self.credentials = None return resp return setup_oauth
Example #16
Source File: handler.py From luci-py with Apache License 2.0 | 5 votes |
def create_login_url(request, dest_url): # pylint: disable=unused-argument return users.create_login_url(dest_url)
Example #17
Source File: handler.py From luci-py with Apache License 2.0 | 5 votes |
def create_login_url(self, dest_url): """When cookie auth is used returns URL to redirect user to login.""" return self._get_users_api().create_login_url(self.request, dest_url)
Example #18
Source File: main.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def get(self): target = self.request.get('continue') if not target: self.error(400) return login_url = users.create_login_url(target) self.redirect(login_url)
Example #19
Source File: main_rsa.py From python-for-android with Apache License 2.0 | 5 votes |
def get(self): if not users.get_current_user(): self.redirect(users.create_login_url(self.request.uri)) access_token = gdocs.token_store.find_token('%20'.join(SETTINGS['SCOPES'])) if isinstance(access_token, gdata.auth.OAuthToken): form_action = '/fetch_data' form_value = 'Now fetch my docs!' revoke_token_link = True else: form_action = '/get_oauth_token' form_value = 'Give this website access to my Google Docs' revoke_token_link = None template_values = { 'form_action': form_action, 'form_value': form_value, 'user': users.get_current_user(), 'revoke_token_link': revoke_token_link, 'oauth_token': access_token, 'consumer': gdocs.GetOAuthInputParameters().GetConsumer(), 'sig_method': gdocs.GetOAuthInputParameters().GetSignatureMethod().get_name() } path = os.path.join(os.path.dirname(__file__), 'index.html') self.response.out.write(template.render(path, template_values))
Example #20
Source File: playground.py From cloud-playground with Apache License 2.0 | 5 votes |
def get(self): # pylint:disable-msg=invalid-name """Handles HTTP GET requests.""" self.redirect(users.create_login_url('/playground'))
Example #21
Source File: handler.py From luci-py with Apache License 2.0 | 5 votes |
def create_login_url(request, dest_url): # pylint: disable=unused-argument return users.create_login_url(dest_url)
Example #22
Source File: appengine.py From luci-py with Apache License 2.0 | 5 votes |
def oauth_aware(self, method): """Decorator that sets up for OAuth 2.0 dance, but doesn't do it. Does all the setup for the OAuth dance, but doesn't initiate it. This decorator is useful if you want to create a page that knows whether or not the user has granted access to this application. From within a method decorated with @oauth_aware the has_credentials() and authorize_url() methods can be called. Args: method: callable, to be decorated method of a webapp.RequestHandler instance. """ def setup_oauth(request_handler, *args, **kwargs): if self._in_error: self._display_error_message(request_handler) return user = users.get_current_user() # Don't use @login_decorator as this could be used in a # POST request. if not user: request_handler.redirect(users.create_login_url( request_handler.request.uri)) return self._create_flow(request_handler) self.flow.params['state'] = _build_state_value(request_handler, user) self.credentials = self._storage_class( self._credentials_class, None, self._credentials_property_name, user=user).get() try: resp = method(request_handler, *args, **kwargs) finally: self.credentials = None return resp return setup_oauth
Example #23
Source File: handler.py From luci-py with Apache License 2.0 | 5 votes |
def create_login_url(request, dest_url): # pylint: disable=unused-argument return users.create_login_url(dest_url)
Example #24
Source File: handler.py From luci-py with Apache License 2.0 | 5 votes |
def create_login_url(self, dest_url): """When cookie auth is used returns URL to redirect user to login.""" return self._get_users_api().create_login_url(self.request, dest_url)
Example #25
Source File: template.py From luci-py with Apache License 2.0 | 5 votes |
def _get_defaults(): """Returns parameters used by most templates/base.html.""" account = users.get_current_user() return { 'nickname': account.email() if account else 'Sign in', 'now': utils.utcnow(), # Hack to enable multi-login. 'signin_link': users.create_login_url('/').replace( '/accounts/ServiceLogin', '/a/SelectSession', 1), }
Example #26
Source File: handler.py From luci-py with Apache License 2.0 | 5 votes |
def create_login_url(self, dest_url): """When cookie auth is used returns URL to redirect user to login.""" return self._get_users_api().create_login_url(self.request, dest_url)
Example #27
Source File: template.py From luci-py with Apache License 2.0 | 5 votes |
def _get_defaults(): """Returns parameters used by most templates/base.html.""" account = users.get_current_user() return { 'nickname': account.email() if account else 'Sign in', 'now': utils.utcnow(), # Hack to enable multi-login. 'signin_link': users.create_login_url('/').replace( '/accounts/ServiceLogin', '/a/SelectSession', 1), }
Example #28
Source File: appengine.py From luci-py with Apache License 2.0 | 5 votes |
def oauth_aware(self, method): """Decorator that sets up for OAuth 2.0 dance, but doesn't do it. Does all the setup for the OAuth dance, but doesn't initiate it. This decorator is useful if you want to create a page that knows whether or not the user has granted access to this application. From within a method decorated with @oauth_aware the has_credentials() and authorize_url() methods can be called. Args: method: callable, to be decorated method of a webapp.RequestHandler instance. """ def setup_oauth(request_handler, *args, **kwargs): if self._in_error: self._display_error_message(request_handler) return user = users.get_current_user() # Don't use @login_decorator as this could be used in a # POST request. if not user: request_handler.redirect(users.create_login_url( request_handler.request.uri)) return self._create_flow(request_handler) self.flow.params['state'] = _build_state_value(request_handler, user) self.credentials = self._storage_class( self._credentials_class, None, self._credentials_property_name, user=user).get() try: resp = method(request_handler, *args, **kwargs) finally: self.credentials = None return resp return setup_oauth
Example #29
Source File: appengine.py From luci-py with Apache License 2.0 | 5 votes |
def oauth_aware(self, method): """Decorator that sets up for OAuth 2.0 dance, but doesn't do it. Does all the setup for the OAuth dance, but doesn't initiate it. This decorator is useful if you want to create a page that knows whether or not the user has granted access to this application. From within a method decorated with @oauth_aware the has_credentials() and authorize_url() methods can be called. Args: method: callable, to be decorated method of a webapp.RequestHandler instance. """ def setup_oauth(request_handler, *args, **kwargs): if self._in_error: self._display_error_message(request_handler) return user = users.get_current_user() # Don't use @login_decorator as this could be used in a # POST request. if not user: request_handler.redirect(users.create_login_url( request_handler.request.uri)) return self._create_flow(request_handler) self.flow.params['state'] = _build_state_value(request_handler, user) self.credentials = self._storage_class( self._credentials_class, None, self._credentials_property_name, user=user).get() try: resp = method(request_handler, *args, **kwargs) finally: self.credentials = None return resp return setup_oauth
Example #30
Source File: handler.py From luci-py with Apache License 2.0 | 5 votes |
def create_login_url(self, dest_url): """When cookie auth is used returns URL to redirect user to login.""" return self._get_users_api().create_login_url(self.request, dest_url)