user login URLs in html/javascript

145 views
Skip to first unread message

thebrianschott

unread,
Jan 9, 2009, 1:12:03 AM1/9/09
to Google App Engine
http://code.google.com/appengine/docs/users/loginurls.html

At the link above it explains how to send a user off to sign-in or
register in a python script. The code below does what I want, but I
don't know how to do the same thing as an html hyperlink on my
applications "home" page. Not all users need to login to proceed
further into my application, only those who want to create their own
map.

greeting = ("<a href=\"%s\">Sign in or register</a>." %
users.create_login_url("/"))

self.response.out.write("<html><body>%s</body></html>" % greeting)

Thanks,

Brian in Atlanta

Btw if you want to play with my app, it is at
http://carpoolfinder.appspot.com
There is a sort of a sandbox that does not require a sign-in if you
enter "Tester" (without quotes) in the inital text field.


thebrianschott

unread,
Jan 9, 2009, 1:01:20 PM1/9/09
to Google App Engine
Ok, I am getting no response, so let me say what my attempt was, based
on viewing the source html of a GAE webpage. But this "attempt" does
not work, because I get sent to a nonexistent webpage. Notice that the
return address is the one for my appspot.com application.

<form id="gaia_universallogin"
action="https://www.google.com/accounts/LoginAuth?continue=http
%3A%2F%2Fcarpoolfinder.appspot.com%2F" method="post"
onsubmit="return(gaia_onLoginSubmit());">
<input type="hidden" name="continue" id="continue"
value="http://carpoolfinder.appspot.com" />
<input type="submit" class="gaia le button" name="signIn"
value="Sign in"
/>
</form>

Thanks,

Brian in Atlanta

Gipsy Gopinathan

unread,
Jan 9, 2009, 1:21:03 PM1/9/09
to google-a...@googlegroups.com
I guess you can just do a redirect to the url  generated by users.create_login_url("/") from your handler when user clinks on the link in your home page.
--
cheers
Gipsy

thebrianschott

unread,
Jan 9, 2009, 3:16:07 PM1/9/09
to Google App Engine
Gipsy,

Thanks, but will that work if not everyone at my home page wants/needs
to login?

Geoffrey Spear

unread,
Jan 9, 2009, 4:00:45 PM1/9/09
to Google App Engine
You just create an ordinary link using the value returned by
users.create_login_url("/") as the link location, and display the link
only if users.get_current_user() is None.

thebrianschott

unread,
Jan 9, 2009, 4:31:45 PM1/9/09
to Google App Engine
I don't quite get it. I hope if by seeing the existing form on the
page and my attempt at following your suggestions, you can spell out
more specifically what you mean Geoffrey and Gipsy.

This is the existing form.
<form method="get" action="/">
<input type="text" name="place" id="placename" />
<input type="submit" value="Submit short group name" />
</form>

Is this what your mean? If not, can you correct it, please?
<a href="users.create_login_url("/")"> Sign in or register. </
a> )

On Jan 9, 4:00 pm, Geoffrey Spear <geoffsp...@gmail.com> wrote:
> You just create an ordinary link using the value returned by
> users.create_login_url("/") as the link location, and display the link
> only if users.get_current_user() is None.
>
[snip]
> > On Jan 9, 1:21 pm, "Gipsy Gopinathan" <gipsy.ra...@gmail.com> wrote:
>
> > > I guess you can just do a redirect to the url  generated by
> > > users.create_login_url("/") from your handler when user clinks on the link
> > > in your home page.

Brian in Atlanta

Gipsy Gopinathan

unread,
Jan 9, 2009, 5:57:22 PM1/9/09
to google-a...@googlegroups.com
I assume that,your requirement is ,when the user submit the form:


<form method="get" action="/">
   <input type="text" name="place" id="placename" />
   <input type="submit" value="Submit short group name" />
 </form>

You want them to be taken to the login page if they are not already logged in ?

If my assumption is correct, then as Geoffrey  said ,check if users.get_current_user() is None and if true re-direct to the login url
generated by users.create_login_url("/") else do the stuff the handler suppose to .
--
cheers
Gipsy

thebrianschott

unread,
Jan 9, 2009, 6:27:43 PM1/9/09
to Google App Engine
Gipsy,

No, I want the people who do login to return to this home page. If the
form entry is not empty it would be Ok for them to be sent on "/?
place=<value of place>" but that is more than I expect.

Brian in Atlanta

On Jan 9, 5:57 pm, "Gipsy Gopinathan" <gipsy.ra...@gmail.com> wrote:
> I assume that,your requirement is ,when the user submit the form:
>
> <form method="get" action="/">
>    <input type="text" name="place" id="placename" />
>    <input type="submit" value="Submit short group name" />
>  </form>
>
> You want them to be taken to the login page if they are not already logged
> in ?
>
> If my assumption is correct, then as Geoffrey  said ,check if
> users.get_current_user() is None and if true re-direct to the login url
> generated by users.create_login_url("/") else do the stuff the handler
> suppose to .
>

Gipsy Gopinathan

unread,
Jan 9, 2009, 6:35:45 PM1/9/09
to google-a...@googlegroups.com
Brian,

So you want your home page to be the login page and redirect them back to the form when login is complete?
--
cheers
Gipsy

thebrianschott

unread,
Jan 9, 2009, 7:04:39 PM1/9/09
to Google App Engine
yes, Gipsy.

Gipsy Gopinathan

unread,
Jan 9, 2009, 7:28:27 PM1/9/09
to google-a...@googlegroups.com
Okay.

Then from your handler for '/' check if users.get_current_user() is None if true then redirect
(DO NOT write the response back), to the url generated by users.create_login_url("/")

code will be something like
'
....
...

self.redirect(users.create_login_url("/"))
....


Or you can  write back the below html snippet

"""<html><body onload='location.replace('"""+users.create_login_url("/")+"""')></body></html>"""
--
cheers
Gipsy

thebrianschott

unread,
Jan 9, 2009, 10:51:18 PM1/9/09
to Google App Engine
Gipsy,

I don't think that the first option will work because I cannot assume
that the person who arrives needs to be a user. Non-users can also
arrive at my home page and enter a "place" in the text field, but I
want to treat users differently from non-users.

But I want to give users a chance to login from my home page, because
I don't know what else to tell them to do to login at that point. How
does anyone login at appspot without being invited to do so? Can you
just initiate a login? If so, I can give users instructions for a link
to where they can do so, and tell them when they are through to come
back manually. But I don't know where to tell them to go.

I don't understand the second option, but I assume it does not achieve
my needs, either, does it?

Thanks so much for helping on this.

On Jan 9, 7:28 pm, "Gipsy Gopinathan" <gipsy.ra...@gmail.com> wrote:
> Okay.
>
> Then from your handler for '/' check if users.get_current_user() is None if
> true then redirect
> (DO NOT write the response back), to the url generated by
> users.create_login_url("/")
>
> code will be something like
> '
> ....
> ...
>
> self.redirect(users.create_login_url("/"))
> ....
>
> Or you can  write back the below html snippet
>
> """<html><body
> onload='location.replace('"""+users.create_login_url("/")+"""')></body></ht ml>"""
>

Brian in Atlanta

Geoffrey Spear

unread,
Jan 9, 2009, 11:11:18 PM1/9/09
to Google App Engine
Somewhere in your handler for /:

if users.get_current_user() is None:
self.response.out.write("<a href='" + users.create_login_url('/') +
"'>Click here to login</a>")

When a user clicks the resulting link, they'll go to the login page,
log in, and get sent back to your page, where the login link won't
show anymore.

thebrianschott

unread,
Jan 9, 2009, 11:29:04 PM1/9/09
to Google App Engine
Geoffrey,

Yes, but that seems to assume that the user MUST login, and only users
who need to login for the result they wish to achieve, need to login.

If you can tell me a link to where I can send people who get to my
application home page and wish to login, can go, I can enter that link
for them to click and I can tell them to come back to my page (with
the back button?) when they complete login. But I don't know where to
send: what URL link would I give them?

Thanks,

Brian in Atlanta

Gipsy Gopinathan

unread,
Jan 9, 2009, 11:47:31 PM1/9/09
to google-a...@googlegroups.com
Brian,

If you let your users click the url generated by users.create_login_url('/xyz')  it will take the users to the google' account login page and after successfull completion of login , google automatically redirect the user to the url you have provided ('xyz' in this case). I think this satisfies your requirement. Is it?
--
cheers
Gipsy

thebrianschott

unread,
Jan 10, 2009, 12:00:44 AM1/10/09
to Google App Engine
Gipsy,

I think it may satisfy my requirement, but how do I learn what that
url is ("the_url" below)? It looks like I need to know that url so I
can put it in as hard-coded link [<a href="the_url"> Click here if you
wish to login</a>] on my app's home page.

On Jan 9, 11:47 pm, "Gipsy Gopinathan" <gipsy.ra...@gmail.com> wrote:
> Brian,
>
> If you let your users click the url generated by
> users.create_login_url('/xyz')  it will take the users to the google'
> account login page and after successfull completion of login , google
> automatically redirect the user to the url you have provided ('xyz' in this
> case). I think this satisfies your requirement. Is it?
>
Brian

thebrianschott

unread,
Jan 10, 2009, 12:04:44 AM1/10/09
to Google App Engine
Gipsy,

Let me clarify. Right now a number of non-user people are using my app
and I cannot afford to stick in such code while it its being used,
even by beta-tester types. I don't want to risk losing them.

Brian

Gipsy Gopinathan

unread,
Jan 10, 2009, 12:19:13 AM1/10/09
to google-a...@googlegroups.com
I think now I understood what you want . You want to provide a link in your home page for your users to login if they want to. And if the user is logged in, the application may behave differently. Is my understanding is right?

If yes. Then i don't understand why you are not able provide the login url generated by the users.create_login_url in your home page handler as a link in the home age ? Am I misssing something?

I think I should be able to send you a sample app for this soon.
--
cheers
Gipsy

thebrianschott

unread,
Jan 10, 2009, 12:28:50 AM1/10/09
to Google App Engine
Gipsy,

Could you just run the sample on your webpage and tell me what you
get?

Thanks,

Brian

On Jan 10, 12:19 am, "Gipsy Gopinathan" <gipsy.ra...@gmail.com> wrote:
> I think now I understood what you want . You want to provide a link in your
> home page for your users to login if they want to. And if the user is logged
> in, the application may behave differently. Is my understanding is right?
>
> If yes. Then i don't understand why you are not able provide the login url
> generated by the users.create_login_url in your home page handler as a link
> in the home age ? Am I misssing something?
>
> I think I should be able to send you a sample app for this soon.
>

Gipsy Gopinathan

unread,
Jan 10, 2009, 12:35:36 AM1/10/09
to google-a...@googlegroups.com
check http://kangchenchunga.appspot.com/

is this what you want ?
--
cheers
Gipsy

thebrianschott

unread,
Jan 10, 2009, 12:35:47 AM1/10/09
to Google App Engine
Wait, I think I know how to do it. Give me a few seconds until I can
use my honey's computer and I'll get back to you.

Brian

thebrianschott

unread,
Jan 10, 2009, 12:41:22 AM1/10/09
to Google App Engine
Yes, that's what I want. Your appspot is not kangchenchunga, is it.
You just found it for me, right?

That's great. Thanks a bunch.

Gipsy Gopinathan

unread,
Jan 10, 2009, 12:43:25 AM1/10/09
to google-a...@googlegroups.com
no that is my appspot
--
cheers
Gipsy

Gipsy Gopinathan

unread,
Jan 10, 2009, 12:48:33 AM1/10/09
to google-a...@googlegroups.com
You can find the sample code here http://dpaste.com/107358/
--
cheers
Gipsy

thebrianschott

unread,
Jan 10, 2009, 12:58:12 AM1/10/09
to Google App Engine
Got it. And it takes me back just right.

Thanks so much Gipsy. IOU, big time.

Brian in Atlanta

thebrianschott

unread,
Jan 10, 2009, 10:43:53 PM1/10/09
to Google App Engine
Believe it or not, I now need a link like the other one, but for
logging out.
It seems a little silly to ask Gipsy to run the sample program again,
revised to
get a logout, but I don't quite see how to add such a sample to my
existing
app. Could you tell me how to do so, please?

Gipsy Gopinathan

unread,
Jan 10, 2009, 11:05:54 PM1/10/09
to google-a...@googlegroups.com
go to http://dpaste.com/107358/

You should be able create the logout link by just changing it to
users.create_logout_url("/") instead of users.create_login_url("/")
--
cheers
Gipsy

thebrianschott

unread,
Jan 11, 2009, 5:48:28 PM1/11/09
to Google App Engine
Gipsy,

Yes I finally got the signout link, also. It was tricky because it
never appeared in the address bar, so I had to read it from the status
bar and transcribe it manually into code. For reference sake this is
the link I got. I think anyone could use it but with their own
appspot.com link substituted.

http://carpoolfinder.appspot.com/_ah/logout?continue=https://www.google.com/accounts/Logout%3Fcontinue%3Dhttp://carpoolfinder.appspot.com/%26service%3Dah

Thank you, again for your help.

On Jan 10, 11:05 pm, "Gipsy Gopinathan" <gipsy.ra...@gmail.com> wrote:
> go tohttp://dpaste.com/107358/
>
> You should be able create the logout link by just changing it to
>
> users.create_logout_url("/") instead of users.create_login_url("/")
>
> On Sat, Jan 10, 2009 at 9:43 PM, thebrianschott <schott.br...@gmail.com>wrote:
>


Brian in Atlanta

Gipsy Gopinathan

unread,
Jan 11, 2009, 9:59:15 PM1/11/09
to google-a...@googlegroups.com
I am gald that you have resolved it. But still still wondering why you have to hard code these links
--
cheers
Gipsy

thebrianschott

unread,
Jan 11, 2009, 10:56:20 PM1/11/09
to Google App Engine
Gipsy,

It is a consequence of my chosen design, to allow both "clients" and
"organizers" to enter the app via the same door. This way the
organizers can identify themselves before they enter the app so that
they need not be asked later who they are, because I was having
difficulty coding something like a javascript-confirm-dialog in
python, to ask that question, so I elected to do it this way. I didn't
anticipate that this would be difficult, but it was pretty hard to do,
too, as it turned out. My knowledge of oop and client/server
programming is very limited, as you might have deduced. The only way I
was able to build the organizer's wrapper on this application was that
I stumbled on a coding genius who took me under his wing in an all day
Saturday Google hackathon. All I had coded was the client's system
when I arrived at the hackathon and when I left I had the organizer's
portion, but it did not quite work the way I wanted, so I have been
tweaking it ever since.

Is that more than you wanted to know? Is that an answer to your
question?

On Jan 11, 9:59 pm, "Gipsy Gopinathan" <gipsy.ra...@gmail.com> wrote:
> I am gald that you have resolved it. But still still wondering why you have
> to hard code these links
>

Brian in Atlanta

Geoffrey Spear

unread,
Jan 12, 2009, 12:11:45 PM1/12/09
to Google App Engine


On Jan 11, 10:56 pm, thebrianschott <schott.br...@gmail.com> wrote:
> Gipsy,
>
> It is a consequence of my chosen design, to allow both "clients" and
> "organizers" to enter the app via the same door. This way the
> organizers can identify themselves before they enter the app so that
> they need not be asked later who they are, because I was having
> difficulty coding something like a javascript-confirm-dialog in
> python, to ask that question, so I elected to do it this way.

You still almost certainly want your app to dynamically generate the
links at runtime; I don't believe there's any guarantee that these
hardcoded links will keep working if Google changes the login system,
and the users API specifically includes functions that return the
correct URLs so you don't have to hardcode them.

I'm not sure why you think hardcoding in the link rather than
generating it at runtime has anything to do with the ability to not
require people to click it. It still just shows up as a link on a
webpage.

thebrianschott

unread,
Jan 12, 2009, 1:38:15 PM1/12/09
to Google App Engine
Geoffrey,

It is not my desire to hardcode the urls, but I don't know how not to;
my programming skills are limited. Or maybe I have not understood the
suggests given here by you folks about how to do it in a way that is
not hardcoded.

The path a user takes in my application depends on whether s/he is
logged in or not, and if logged in, whether s/he goes to a map s/he
created or not. If a person has a google account, s/he may not want to
use the app as if s/he does, because s/he will see different results
from her/his users.

On top of that, the users only interface with the app is via html
pages, not python pages, so I don't know how to put links that change
or appear and disappear according to user responses, into an html
page. If I were to wait to ask the user about his/her logging
preference at key times while the python program is in control, that
would be ok, but I don't know how to do that in a way that keeps the
html page visible in the background the way a javascript confirm
dialog produces a little popup dialog window; that's my first choice,
but I don't know how.

My inclination is more toward developing another related app now, but
I would be pleased to learn how to code a softcoded link if you or
others can explain it to me.

Thanks very much for expressing your question.


On Jan 12, 12:11 pm, Geoffrey Spear <geoffsp...@gmail.com> wrote:
>
> You still almost certainly want your app to dynamically generate the
> links at runtime; I don't believe there's any guarantee that these
> hardcoded links will keep working if Google changes the login system,
> and the users API specifically includes functions that return the
> correct URLs so you don't have to hardcode them.
>
> I'm not sure why you think hardcoding in the link rather than
> generating it at runtime has anything to do with the ability to not
> require people to click it.  It still just shows up as a link on a
> webpage.

Brian in Atlanta

djidjadji

unread,
Jan 12, 2009, 7:41:20 PM1/12/09
to google-a...@googlegroups.com
Do you use (Django) templates?
If not start using them, separate the function (code) from the
presentation (html)

Read the GAE example

http://code.google.com/appengine/docs/gettingstarted/templates.html

There they show you how to use the
users.create_logout_url()
users.create_login_url()
methods in templates, read the Django doc about templates for version
0.96 for more things you can do.

2009/1/12 thebrianschott <schott...@gmail.com>:

thebrianschott

unread,
Jan 13, 2009, 9:03:02 PM1/13/09
to Google App Engine
Well, my guru used Django templates, but I just used his {{...}}
tricks and never read the material use recommended. Now I have and I
see what you mean. I'll make a concerted effort to implement that with
my home page as you recommend. Thanks very much.

On Jan 12, 7:41 pm, djidjadji <djidja...@gmail.com> wrote:
> Do you use (Django) templates?
> If not start using them, separate the function (code) from the
> presentation (html)
>
> Read the GAE example
>
> http://code.google.com/appengine/docs/gettingstarted/templates.html
>
> There they show you how to use the
> users.create_logout_url()
> users.create_login_url()
> methods in templates, read the Django doc about templates for version
> 0.96 for more things you can do.
>

Brian in Atlanta
Reply all
Reply to author
Forward
0 new messages