return badRequest(loginForm.errorsAsJson());
}
Login login = loginForm.get();
User user = DaoManager.getUserDao().findByLoginAndPassword(login.login, login.password);
if (user == null) {
return unauthorized();
} else {
Logger.debug("User login " + user.getLogin() + " and pass " + user.getPassword());
user.setAuthToken(Utilities.createToken());
try {
DaoManager.getUserDao().persist(user);
} catch (DataAccessException e) {
Logger.error("failed to persist user after token creation", e);
return internalServerError();
}
ObjectNode authTokenJson = Json.newObject();
authTokenJson.put(AUTH_TOKEN, user.getAuthToken());
response().setCookie(AUTH_TOKEN, user.getAuthToken());
return ok(authTokenJson);
}
}