Using the Users Service

Google App Engine provides several useful services based on Google infrastructure, accessible by applications using libraries included with the SDK. One such service is the Users service, which lets your application integrate with Google user accounts. With the Users service, your users can use the Google accounts they already have to sign in to your application.

Let's use the Users service to personalize this application's greeting.

大意:在google原有架构的基础上,Google App Engine提供了许多有用的服务。这些服务可以通过使用SDK libraries来获得。其中有一个服务是用户服务,这个服务使你的应用能够与google 用户账户交互。通过这个服务,用户可以使用已有的google账户登录你的应用。

通过使用这个用户服务,使我们的程序实现个性化的问候。

Using Users

Edit src/guestbook/GuestbookServlet.java as indicated to resemble the following:

编辑src/guestbook/GuestbookServlet.java,使其内容与如下相似:

package guestbook;

import java.io.IOException;
import javax.servlet.http.*;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;


public class GuestbookServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
              throws IOException {
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();

        if (user != null) {
            resp.setContentType("text/plain");
            resp.getWriter().println("Hello, " + user.getNickname());
        } else {
            resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
        }
    }

}

If you are using Eclipse and your development server is running in the debugger, when you save your changes to this file, Eclipse compiles the new code automatically, then attempts to insert the new code into the already-running server. Changes to classes, JSPs, static files and appengine-web.xml are reflected immediately in the running server without needing to restart. If you change web.xml or other configuration files, you must stop and start the server to see the changes.

大意:如果你使用的是Eclipse并且你的应用服务器处于debugger模式,当你保存文件时,Eclipse会自动编译新的代码,并尝试把这些代码放入已经在运行的服务器里,原有的类文件,jsp文件,静态文件和appengin-web.xml立即被映射到正在运行的服务器中,你也不用重新启动服务器。如果你改变了web.xml或者其它配置文件,为了看到这些变化,你必须要停止再启动服务。

If you are using Ant, you must stop the server and rebuild the project to see changes made to source code. Changes to JSPs and static files do not require restarting the server.

大意:如果你使用的是Ant,你必须停止服务并重新编译项目才能看到改变。只改变jsp文件和静态文件不需要重启服务。

Rebuild your project and restart the server, if necessary. Test the application by visiting the servlet URL in your browser:

重新创建你的项目,重启服务,如果有必要,在浏览器里通过如下地址测试:

Instead of displaying the message, the server prompts you for an email address. Enter any email address (such as alfred@example.com, then click "Log In." The app displays a message, this time containing the email address you entered.

这时会显示一个消息,服务提示你输入一个email,输入任何email地址,如alfred@example.com,然后点击Log in,这个应用将显示一条消息,这次这条消息中包含你输入的email地址

The new code for the GuestbookServlet class uses the Users API to check if the user is signed in with a Google Account. If not, the user is redirected to the Google Accounts sign-in screen.

大意:这些代码使用Users API确认是否使用google账号登陆,如果没有,则将用户直接转向google账户登录界面。

userService.createLoginURL(...) returns the URL of the sign-in screen. The sign-in facility knows to redirect the user back to the app by the URL passed to createLoginURL(...), which in this case is the URL of the current page.

大意:userService.createLoginURL(...)这个方法返回的是登入界面的URL,这个登录sign-in又提交这个应用到当前页面。

The development server knows how to simulate the Google Accounts sign-in facility. When run on your local machine, the redirect goes to the page where you can enter any email address to simulate an account sign-in. When run on App Engine, the redirect goes to the actual Google Accounts screen.

大意:开发服务器知道如何模拟谷歌帐户登录,当运行在本机上时,直接重定向到当前页面,这个页面能够模拟输入一个email账号,当运行在App Engine时,就直接重定向到真实的google账户登陆界面。

You are now signed in to your test application. If you reload the page, the message will display again.

大意:你现在可以登录你的应用。如果你重新载入页面,这个消息会再显示一遍。

To allow the user to sign out, provide a link to the sign-out screen, generated by the method createLogoutURL(). Note that a sign-out link will sign the user out of all Google services.

大意:通过使用createLogoutURL(),让你的应用提供一个登出界面。必须注意的是,一个sign-out链接将会使得当前用户退出google所有的服务。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
牙科就诊管理系统利用当下成熟完善的SSM框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的Mysql数据库进行程序开发。实现了用户在线查看数据。管理员管理病例管理、字典管理、公告管理、药单管理、药品管理、药品收藏管理、药品评价管理、药品订单管理、牙医管理、牙医收藏管理、牙医评价管理、牙医挂号管理、用户管理、管理员管理等功能。牙科就诊管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 管理员在后台主要管理病例管理、字典管理、公告管理、药单管理、药品管理、药品收藏管理、药品评价管理、药品订单管理、牙医管理、牙医收藏管理、牙医评价管理、牙医挂号管理、用户管理、管理员管理等。 牙医列表页面,此页面提供给管理员的功能有:查看牙医、新增牙医、修改牙医、删除牙医等。公告信息管理页面提供的功能操作有:新增公告,修改公告,删除公告操作。公告类型管理页面显示所有公告类型,在此页面既可以让管理员添加新的公告信息类型,也能对已有的公告类型信息执行编辑更新,失效的公告类型信息也能让管理员快速删除。药品管理页面,此页面提供给管理员的功能有:新增药品,修改药品,删除药品。药品类型管理页面,此页面提供给管理员的功能有:新增药品类型,修改药品类型,删除药品类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值