public static Result doRegistrieren() { Map<String, String[]> parameters = request().body().asFormUrlEncoded(); Form<User> form = Form.form(User.class); form = form.bindFromRequest(); if (form.hasErrors()) { return badRequest(views.html.registrieren.render("war nix. Fehler: " + form.errors())); } else { User user = form.get(); if (!user.password.equals(parameters.get("password2")[0])) { return badRequest(views.html.registrieren.render("Passwörter stimmen nicht überein")); } // UserDB.init(); // DBUser users = DBUser.get(); // TimeZone.setDefault(TimeZone.getTimeZone("UTC")); Date date = new Date(); Date d = new Date(); try { // 30-07-1987 SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); sdf.setTimeZone(TimeZone.getTimeZone("GMT+1:00")); Logger.info("date from js " + parameters.get("datepicker")[0]); String datefromForm = parameters.get("datepicker")[0]; // String datefromForm = "2013-05-04"; date = sdf.parse(datefromForm); Logger.info(date.toString()); } catch (Exception e) { Logger.info("Fehler beim Date \n" + e); } if (date == null) { return badRequest(views.html.registrieren.render("Date geht noch nicht...oder war leer!")); } // Date date = sdf.parse(user.date); User newUser = users.create(new User(user.email, user.password, user.nickname, user.fahrer, date)); // +" remember: " +user.remember); // UserDB userDB = UserDB.get(); // User userDB = UserDB.get().validateUser(user.email, // user.password); if (newUser != null) { return ok(views.html.loginform.render("")); } else { // return badRequest("falsche Angaben"); return badRequest(views.html.registrieren.render("E-Mail existiert bereits")); } } }
/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub System.out.println("dopost"); String userName = request.getParameter("userName"); String password = request.getParameter("password"); // set default userRole Todouser user = new Todouser(); user.setUserName(userName); user.setUserPassword(password); if (DBUser.isAvailable(user)) { DBUser.insert(user); request.setAttribute("goodMessage", "Congratz! Account created"); getServletContext().getRequestDispatcher("/LoginForm.jsp").forward(request, response); } else { request.setAttribute("errorMessage", "Error! Username and Email have already taken"); getServletContext().getRequestDispatcher("/RegisterUser.jsp").forward(request, response); } }