Skip to content

Instantly share code, notes, and snippets.

Created September 18, 2012 17:05
Show Gist options
  • Save anonymous/3744326 to your computer and use it in GitHub Desktop.
Save anonymous/3744326 to your computer and use it in GitHub Desktop.
createUser servelt code
String name = req.getParameter("name");
String email = req.getParameter("email");
String pass = req.getParameter("passwd");
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key userKey = KeyFactory.createKey("User",email);
System.out.println(userKey.getId()+" "+userKey.getKind()+" "+userKey.getName());
//create an email filter to check if already exists
Filter emailfil = new FilterPredicate("email",FilterOperator.EQUAL,email);
Query q = new Query("User").setFilter(emailfil);
PreparedQuery pq = datastore.prepare(q);
if(pq.asIterator().hasNext())
{
resp.sendRedirect("/index.jsp?status=001");
} else {
// TODO Auto-generated catch block
Entity user = new Entity("User",userKey);
user.setProperty("name", name);
user.setProperty("passwd", pass);
user.setProperty("email", email);
datastore.put(user);
HttpSession session = req.getSession();
if(session.isNew()){
session.setAttribute("uname", name);
session.setAttribute("email", email);
}
resp.sendRedirect("/auth/home.jsp");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment