开发者

display new message to new user App Engine

I'm using Google App engine to allow a user to log in to the site. Once they log in, I create a token for them and use this to check whether the user is logged in. I want to be able to display a different message to first time users and a different one for returning users.

        {% ifequal cookie None %} 


<a  href="https://foursquare.com/oauth2/authenticate?client_id=X&response_type=code&redirect_uri=http://localhost:8080/">Log In</a>

            <hr></hr>  
        {% else %} 

                        {% for user in set %}
                            {% ifequal user.session_ID access_token %}
                                <a  href="/logout">Logout {{user.user_name}}</a>
                                    <hr></h开发者_StackOverflow中文版r>  
                            {% else %}
                            {%endifequal%}
                        {% endfor %}

   <h3 align="center"> 





        {% endifequal %}

Currently, there are only two choices: signed in and not.


Assuming your user profile entity looks something like this:

class UserProfile(db.Model):
    UserID = db.UserProperty()
    FirstSession = db.DateTimeProperty(auto_now_add=True)

Try this:

from google.appengine.api import users

user = users.get_current_user()

is_existing_user = UserProfile.all().filter('UserID = ', user).get()

if is_existing_user:
    #do something
else:
    #do something else


I'd use a boolean variable in the user class for this case:

is_first_time_user = db.BooleanProperty(default=True,verbose_name="is First Time User")

or a function in the user class that the template tag can use.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜