private boolean sendNotification( HttpServletRequest request, HttpServletResponse response, Repository db, String login, String commit, String url, String authorName, String message) throws ServletException, URISyntaxException, IOException, JSONException, CoreException, Exception { UserEmailUtil util = UserEmailUtil.getUtil(); if (!util.isEmailConfigured()) { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Smpt server not configured", null)); } IOrionCredentialsService userAdmin = UserServiceHelper.getDefault().getUserStore(); User user = (User) userAdmin.getUser(UserConstants.KEY_LOGIN, login); try { if (reviewRequestEmail == null) { reviewRequestEmail = new EmailContent(EMAIL_REVIEW_REQUEST_FILE); } String emailAdress = user.getEmail(); util.sendEmail( reviewRequestEmail.getTitle(), reviewRequestEmail .getContent() .replaceAll(EMAIL_COMMITER_NAME, authorName) .replaceAll(EMAIL_URL_LINK, url) .replaceAll(EMAIL_COMMIT_MESSAGE, message), emailAdress); JSONObject result = new JSONObject(); result.put(GitConstants.KEY_RESULT, "Email sent"); OrionServlet.writeJSONResponse( request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT); return true; } catch (Exception e) { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "User doesn't exist", null)); } };
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { UserService userService = UserServiceFactory.getUserService(); String retUrl = req.getParameter("url"); if (retUrl == null) retUrl = "/"; String pathInfo = req.getPathInfo(); if (pathInfo.equals("/current")) { User user = userService.getCurrentUser(); if (user == null) { res.setStatus(401); res.setContentType("text/plain; charset=utf-8"); res.getWriter().write("Not login"); return; } UserBean ub = getByEmail(user.getEmail()); res.setContentType("application/json; charset=utf-8"); res.setHeader("Cache-control", "no-cache"); res.getWriter().write("{\"email\":\"" + user.getEmail() + "\""); if (ub != null) { res.getWriter().write(",\"nickName\":\"" + ub.getNickName() + "\""); res.getWriter().write(",\"isRegister\":true"); } else { String nn = user.getNickname(); if (nn == null) nn = user.getEmail(); res.getWriter().write(",\"nickName\":\"" + nn + "\""); res.getWriter().write(",\"isRegister\":false"); } res.getWriter().write("}"); } else if (pathInfo.equals("/login")) { String url = userService.createLoginURL(retUrl); res.sendRedirect(url); } else if (pathInfo.equals("/logout")) { String url = userService.createLogoutURL(retUrl); res.sendRedirect(url); } else if (pathInfo.equals("/register")) { User user = userService.getCurrentUser(); if (user == null) { res.setStatus(401); res.setContentType("text/plain; charset=utf-8"); res.getWriter().write("Not login"); return; } String nickName = req.getParameter("nickName"); UserBean ub = getByNeckName(nickName); if (ub != null) { res.setStatus(403); res.setContentType("text/plain; charset=utf-8"); res.getWriter().write("ニックネーム(" + nickName + ")は既に使われています。"); return; } ub = new UserBean(); ub.setEmail(user.getEmail()); ub.setNickName(nickName); usbs.put(user.getEmail(), ub); ursbs.put(nickName, ub); FileBean fb = new FileBean(); fb.setParentName(""); fb.setLastName(nickName); fb.setDirectory(true); fb.setLastModified(System.currentTimeMillis()); fb.setOwner(user.getEmail()); fb.setNickName(nickName); sbs.put("/" + nickName, fb); res.sendRedirect(retUrl); } }