如何检查用户是否登录Google&显示一个链接/按钮,如果他不是? [英] How to check if a user is logged in to Google & display a link/button if he is not?

查看:139
本文介绍了如何检查用户是否登录Google&显示一个链接/按钮,如果他不是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写我的第一个Google App Engine应用程序,主要是作为一种学习体验,它是一种非常简单的Pastebin ...我不想处理垃圾邮件,因此认为要求用户登录将是足够安全的选择。

在这一点上,这是我想要的:


  • 如果访客已登录,访客会看到主页他看到了保存粘贴按钮,如果用户没有登录,他会看到一个链接/按钮登录到Google



我阅读了一些文章和教程( 1 ),但他们给了我认为我会锁定每个人,除了几个允许的人之外,或者这种身份验证是管理我的应用程序,而不是仅仅检查用户是否登录。



另一方面,如果您可以建议使用垃圾邮件检查程序或类似程序,那么很容易实现,请告诉我。



我觉得特别困惑的是,我们必须在创建应用程序时定义身份验证的类型,因为这将通过我不明白的代码来实现。



所以总结一下:如何检查用户是否登录Google并显示链接/按钮(如果他不是)?



注意:使用 Java

解决方案

您提到的用户API 只是你需要什么。只需按照该页面提供的示例进行操作即可。



您获取用户,如果用户不为空,则显示Save paste按钮,您还应该设置保存粘贴操作以要求登录。如果用户为空,则显示登录网址。如果用户未登录,则会显示登录页面。

认证系统有三种类型:


  1. Google帐户:可用于任何拥有Google帐户的人(甚至可以是非Gmail帐户)这可能是您想要使用的选项。

  2. Google Apps:仅适用于特定的Google Apps域(例如yourcompany。开放标识:任何拥有OpenId标识(Google,Yahoo,MySpace等)的人都可以使用


I am writing my very first Google App Engine application, mostly as a learning experience, its a sort of Pastebin very simple... I dont want to deal with spam so figured that requiring users to log in would be a safe enough choice.
At this point this is what I want:

  • Visitor sees main page, if visitor is logged in to Google he sees the "Save paste" button, if user is not logged in he sees a link/button to log in to Google

I have read a few articles and tutorials (1) but they give me the idea that I would be locking everyone out except a few allowed ones or that this sort of authentication is to manage my application instead of just checking if a user is logged in or not.

If on the other hand you can suggest a spam checker or similar, that is easy to implement please let me know.

I find particularly confusing that we have to define the type of authentication when creating the app, since this is going to be implemented by code I dont understand this.

So to summarize: How can I check if a user is logged in to Google and display a link/button if he is not?

Note: Im using Java

解决方案

The Users API you mention is just what you need. Just follow the example provided in that page.

You fetch the user, if the user is not null you show the Save paste button, you should also set the url of the save paste action to require login. If the user is null you show the login url. In case the user is not logged in a login page will be shown.

There are three types of authentication systems:

  1. Google Accounts: available to anyone with a Google Account (can even be a non gmail account) This is probably the option you want to use.
  2. Google Apps: available only to a specific Google Apps domain (example yourcompany.com)
  3. Open Id: available to anyone with an OpenId identity (Google, Yahoo, MySpace, etc.)

这篇关于如何检查用户是否登录Google&显示一个链接/按钮,如果他不是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆