@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
UserService userService = UserServiceFactory.getUserService();
String thisURL = req.getRequestURI();
Principal p = req.getUserPrincipal();
User u = userService.getCurrentUser();
if (p != null) {
WebdavUser wu = ofy.find(WebdavUser.class, u.getUserId());
if (wu == null) {
wu = new WebdavUser();
wu.setPassword((new RandPass(RandPass.NONCONFUSING_ALPHABET).getPass(6)));
wu.setUserId(u.getUserId());
wu.setUsername(u.getNickname());
Key<WebdavUser> wuKey = ofy.put(wu);
WebdavFolder root = new WebdavFolder();
root.setParent(wuKey);
ofy.put(root);
}
resp.getWriter().println(
String.format(
"<p>Hello, %s! You can log in to http://freewebdav.appspot.com/webdav/ as %s/%s" +
"<br><br> You can <a href=\"%s\">sign out</a>.</p>",
u.toString(),
wu.getUsername(),
wu.getPassword(),
userService.createLogoutURL(thisURL) ));
} else {
resp.sendRedirect("login");