Package com.google.appengine.api.users

Examples of com.google.appengine.api.users.UserService


@SuppressWarnings("serial")
public class Authentification extends HttpServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
 
     UserService userService = UserServiceFactory.getUserService();
       User user = userService.getCurrentUser();
       OAuthService oauth = OAuthServiceFactory.getOAuthService();
       PersistenceManager pm = PMF.get().getPersistenceManager();
         
       
       if (user != null)
       {
         resp.setContentType("text/html");
            resp.getWriter().println("<body>");
              
            try{
              DAO dao = new DAO();
             UserData userData = dao.findUserByKey(user.getEmail(), pm);
             if(userData == null){
                 dao.createUserRecord(user.getEmail(), pm);
                 dao.incrementer(user.getEmail(), pm);
                 resp.sendRedirect("/mail?objet=Bienvenue&message=Bonjour, vous venez de vous connecter pour la premiere fois.&addrusr="+user.getEmail());
              }else{
                 if(userData.getNumberOfConnections()>=10){ 
                   dao.incrementer(user.getEmail(), pm);
                   resp.sendRedirect(userService.createLogoutURL("/mail?objet="+userData.getNumberOfConnections()+" connexions atteintes&message=Bonjour, vous avez atteint "+userData.getNumberOfConnections()+" connexions.&addrusr="+user.getEmail()));
                 }
                 else
                   dao.incrementer(user.getEmail(), pm);
                
                 }
            
             resp.getWriter().println("<p>Bonjour " + user.getNickname() + ", bienvenue sur ma premi�re application Google App Engine.</p>");
           resp.getWriter().println("<p>Cliquez <a href=\""+ userService.createLogoutURL("/sendchatmessage?message=L'utilisateur \""+ user.getNickname()+"\" s'est d�connect�.")+ "\">ici </a>pour vous d�connecter.</p>");
           
               
             catch(Exception e){
              
             }finally{
               pm.close();
             }
            
             resp.getWriter().println("</body>");
          } else {
                resp.sendRedirect(userService.createLoginURL("/sendchatmessage?message=Connexion de l'utilisateur "));
         }

  }  
View Full Code Here


@SuppressWarnings("serial")
public class Authentification extends HttpServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
 
     UserService userService = UserServiceFactory.getUserService();
       User user = userService.getCurrentUser();
       OAuthService oauth = OAuthServiceFactory.getOAuthService();
       PersistenceManager pm = PMF.get().getPersistenceManager();
         
       
       if (user != null)
       {
         resp.setContentType("text/html");
            resp.getWriter().println("<body>");
              
            try{
              DAO dao = new DAO();
             UserData userData = dao.findUserByKey(user.getEmail(), pm);
             if(userData == null){
                 dao.createUserRecord(user.getEmail(), pm);
                 dao.incrementer(user.getEmail(), pm);
                 resp.sendRedirect("/mail?objet=Bienvenue&message=Bonjour, vous venez de vous connecter pour la premiere fois.&addrusr="+user.getEmail());
              }else{
                 if(userData.getNumberOfConnections()>=10){ 
                   dao.incrementer(user.getEmail(), pm);
                   resp.sendRedirect(userService.createLogoutURL("/mail?objet="+userData.getNumberOfConnections()+" connexions atteintes&message=Bonjour, vous avez atteint "+userData.getNumberOfConnections()+" connexions.&addrusr="+user.getEmail()));
                 }
                 else
                   dao.incrementer(user.getEmail(), pm);
                
                 }
            
             resp.getWriter().println("<p>Bonjour " + user.getNickname() + ", bienvenue sur ma premi�re application Google App Engine.</p>");
           resp.getWriter().println("<p>Cliquez <a href=\""+ userService.createLogoutURL("/sendchatmessage?message=L'utilisateur \""+ user.getNickname()+"\" s'est d�connect�.")+ "\">ici </a>pour vous d�connecter.</p>");
           
               
             catch(Exception e){
              
             }finally{
               pm.close();
             }
            
             resp.getWriter().println("</body>");
          } else {
                resp.sendRedirect(userService.createLoginURL("/sendchatmessage?message=Connexion de l'utilisateur "));
         }

  }  
View Full Code Here

    public void userIsLoggedIn() {
        helper.setEnvIsLoggedIn(true)
            .setEnvEmail("user@togglz.org")
            .setEnvAuthDomain("togglz.org");

        UserService userService = UserServiceFactory.getUserService();
        FeatureUser user = userProvider.getCurrentUser();
        assertFalse(user.isFeatureAdmin());
        assertEquals(userService.getCurrentUser().getUserId(), user.getName());
        assertEquals(userService.getCurrentUser().getEmail(), user.getAttribute("email"));
        assertEquals(userService.getCurrentUser().getNickname(), user.getAttribute("nickname"));
    }
View Full Code Here

        helper.setEnvIsLoggedIn(true)
            .setEnvIsAdmin(true)
            .setEnvEmail("admin@togglz.org")
            .setEnvAuthDomain("togglz.org");

        UserService userService = UserServiceFactory.getUserService();
        FeatureUser user = userProvider.getCurrentUser();
        assertTrue(user.isFeatureAdmin());
        assertEquals(userService.getCurrentUser().getUserId(), user.getName());
        assertEquals(userService.getCurrentUser().getEmail(), user.getAttribute("email"));
        assertEquals(userService.getCurrentUser().getNickname(), user.getAttribute("nickname"));
    }
View Full Code Here

   * @return
   */
  @Override
  public String getServiceSpecificUserId(String notUsed) {
   
    UserService userService = getUserService();
   
    if (!userService.isUserLoggedIn()) {
      return null;
    }
   
    User user = userService.getCurrentUser();
   
    return user.getUserId();
  }
View Full Code Here

   * @return
   */
  @Override
  public String getServiceSpecificUserId(String notUsed) {
   
    UserService userService = getUserService();
   
    if (!userService.isUserLoggedIn()) {
      return null;
    }
   
    String result = super.getServiceSpecificUserId(notUsed);
   
    if (result == null) {
      User user = userService.getCurrentUser();
   
      result = user.getEmail();
    }
   
    return result;
View Full Code Here

   
    return false;
  }
 
  public static Boolean isAdministrator(HttpServletRequest req, HttpServletResponse resp) {
    UserService userService = UserServiceFactory.getUserService();
   
    User user = userService.getCurrentUser();

    try {
      if (null == user) {
        String loginUrl = userService.createLoginURL(req.getRequestURI() + "?" + req.getQueryString());
        _logger.info("Sending redirect to: " + loginUrl);
        resp.sendRedirect(loginUrl);
        return false;
      } else if (userService.isUserAdmin()) {
        return true;
      } else {
        _logger.info("User is logged in, but not an admin");
        resp.getWriter().print(String.format(
            "Please login with an administrator account. <a href=\"%s\">Logout</a>",
            userService.createLogoutURL(req.getRequestURI() + "?" + req.getQueryString())));
      }
    } catch (IOException e) {
      _logger.severe("Failure to write logout info. Exception: " + e);
    }
   
View Full Code Here

    return false;
  }

  public static Boolean isAdministrator(HttpServletRequest req, HttpServletResponse resp) {
    UserService userService = UserServiceFactory.getUserService();

    User user = userService.getCurrentUser();

    try {
      if (null == user) {
        String loginUrl = userService.createLoginURL(req.getRequestURI() + "?" + req.getQueryString());
        _logger.info("Sending redirect to: " + loginUrl);
        resp.sendRedirect(loginUrl);
        return false;
      } else if (userService.isUserAdmin()) {
        return true;
      } else {
        _logger.info("User is logged in, but not an admin");
        resp.getWriter().print(String.format(
            "Please login with an administrator account. <a href=\"%s\">Logout</a>",
            userService.createLogoutURL(req.getRequestURI() + "?" + req.getQueryString())));
      }
    } catch (IOException e) {
      _logger.severe("Failure to write logout info. Exception: " + e);
    }
View Full Code Here

@SuppressWarnings("serial")
public class SignGuestbookServlet extends HttpServlet {
  private static final Logger log = Logger.getLogger(SignGuestbookServlet.class.getName());
 
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException{
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
   
    String content = req.getParameter("content");
   
    Date date = new Date();
   
View Full Code Here

@SuppressWarnings("serial")
public class SignGuestbookServlet extends HttpServlet {
  private static final Logger log = Logger.getLogger(SignGuestbookServlet.class.getName());
 
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException{
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
   
    String content = req.getParameter("content");
   
    Date date = new Date();
   
View Full Code Here

TOP

Related Classes of com.google.appengine.api.users.UserService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.