Fix major update integrating with external wisemapping frond end
This commit is contained in:
@@ -19,29 +19,19 @@ package com.wisemapping.webmvc;
|
||||
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
import org.springframework.core.env.PropertiesPropertySource;
|
||||
import org.springframework.core.env.PropertySourcesPropertyResolver;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.core.io.support.ResourcePropertySource;
|
||||
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||
import org.springframework.web.context.support.ServletContextResource;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ApplicationContextInitializer implements org.springframework.context.ApplicationContextInitializer<ConfigurableWebApplicationContext> {
|
||||
|
||||
public void initialize(@NotNull ConfigurableWebApplicationContext ctx) {
|
||||
try {
|
||||
final Resource resource = new ServletContextResource(ctx.getServletContext(), "/WEB-INF/app.properties");
|
||||
final Resource resource = new ServletContextResource(Objects.requireNonNull(ctx.getServletContext()), "/WEB-INF/app.properties");
|
||||
final ResourcePropertySource resourcePropertySource = new ResourcePropertySource(resource);
|
||||
ctx.getEnvironment().getPropertySources().addFirst(resourcePropertySource);
|
||||
} catch (IOException e) {
|
||||
|
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright [2015] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.webmvc;
|
||||
|
||||
import com.wisemapping.service.MindmapService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@Controller
|
||||
public class ExtensionsController {
|
||||
@Qualifier("mindmapService")
|
||||
@Autowired
|
||||
private MindmapService mindmapService;
|
||||
|
||||
@RequestMapping(value = "privacyPolicy")
|
||||
public ModelAndView privacyPolicy() {
|
||||
return new ModelAndView("privacyPolicy");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "faq")
|
||||
public ModelAndView faq() {
|
||||
return new ModelAndView("faq");
|
||||
}
|
||||
}
|
@@ -44,17 +44,4 @@ public class LoginController {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// @RequestMapping(value = "loginopenid", method = RequestMethod.GET)
|
||||
// protected ModelAndView showLoginOpenIdPage() {
|
||||
// final User user = Utils.getUser(false);
|
||||
// ModelAndView result;
|
||||
// if (user != null) {
|
||||
// result = new ModelAndView("forward:/c/maps/");
|
||||
// } else {
|
||||
// result = new ModelAndView("loginopenid");
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
}
|
||||
|
@@ -40,8 +40,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
@Controller
|
||||
@@ -52,19 +50,6 @@ public class MindmapController {
|
||||
@Autowired
|
||||
private MindmapService mindmapService;
|
||||
|
||||
@RequestMapping(value = "maps/import")
|
||||
public String showImportPage() {
|
||||
return "mindmapImport";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/{id}/details")
|
||||
public String showDetails(@PathVariable int id, @NotNull Model model, @NotNull HttpServletRequest request) throws MapCouldNotFoundException {
|
||||
final MindMapBean mindmap = findMindmapBean(id);
|
||||
model.addAttribute("mindmap", mindmap);
|
||||
model.addAttribute("baseUrl", request.getAttribute("site.baseurl"));
|
||||
return "mindmapDetail";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/{id}/print")
|
||||
public String showPrintPage(@PathVariable int id, @NotNull Model model) throws MapCouldNotFoundException {
|
||||
final MindMapBean mindmap = findMindmapBean(id);
|
||||
@@ -75,19 +60,6 @@ public class MindmapController {
|
||||
return "mindmapPrint";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/{id}/export")
|
||||
public String showExportPage(@PathVariable int id, @NotNull Model model) throws IOException, MapCouldNotFoundException {
|
||||
final Mindmap mindmap = findMindmap(id);
|
||||
model.addAttribute("mindmap", mindmap);
|
||||
return "mindmapExport";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/{id}/exportf")
|
||||
public String showExportPageFull(@PathVariable int id, @NotNull Model model) throws IOException, MapCouldNotFoundException {
|
||||
showExportPage(id, model);
|
||||
return "mindmapExportFull";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/{id}/share")
|
||||
public String showSharePage(@PathVariable int id, @NotNull Model model) throws MapCouldNotFoundException {
|
||||
final Mindmap mindmap = findMindmap(id);
|
||||
@@ -101,41 +73,8 @@ public class MindmapController {
|
||||
return "mindmapShareFull";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/{id}/publish")
|
||||
public String showPublishPage(@PathVariable int id, @NotNull Model model, @NotNull HttpServletRequest request) throws MapCouldNotFoundException {
|
||||
final Mindmap mindmap = findMindmap(id);
|
||||
model.addAttribute("mindmap", mindmap);
|
||||
model.addAttribute("baseUrl", request.getAttribute("site.baseurl"));
|
||||
return "mindmapPublish";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/{id}/publishf")
|
||||
public String showPublishPageFull(@PathVariable int id, @NotNull Model model, @NotNull HttpServletRequest request) throws MapCouldNotFoundException {
|
||||
showPublishPage(id, model, request);
|
||||
return "mindmapPublishFull";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/{id}/history", method = RequestMethod.GET)
|
||||
public String showHistoryPage(@PathVariable int id, @NotNull Model model) {
|
||||
model.addAttribute("mindmapId", id);
|
||||
return "mindmapHistory";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/{id}/historyf", method = RequestMethod.GET)
|
||||
public String showHistoryPageFull(@PathVariable int id, @NotNull Model model) {
|
||||
showHistoryPage(id, model);
|
||||
return "mindmapHistoryFull";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/")
|
||||
public String showListPage(@NotNull Model model) {
|
||||
final Locale locale = LocaleContextHolder.getLocale();
|
||||
// @Todo: This should be more flexible ...
|
||||
String localeStr = locale.toString().toLowerCase();
|
||||
if ("es".equals(locale.getLanguage()) || "pt".equals(locale.getLanguage())) {
|
||||
localeStr = locale.getLanguage();
|
||||
}
|
||||
model.addAttribute("locale", localeStr);
|
||||
return "mindmapList";
|
||||
}
|
||||
|
||||
|
@@ -32,22 +32,6 @@ public class PublicPagesController {
|
||||
@Autowired
|
||||
private MindmapService mindmapService;
|
||||
|
||||
|
||||
@RequestMapping(value = "aboutUs")
|
||||
public String aboutUs() {
|
||||
return "aboutUs";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "termsOfUse")
|
||||
public String showTermsOfUse() {
|
||||
return "termsOfUse";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "crew")
|
||||
public String crew() {
|
||||
return "crew";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "keyboard")
|
||||
public String newsPage() {
|
||||
return "keyboard";
|
||||
|
@@ -19,33 +19,17 @@
|
||||
package com.wisemapping.webmvc;
|
||||
|
||||
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.model.AuthenticationType;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.security.Utils;
|
||||
import com.wisemapping.service.InvalidAuthSchemaException;
|
||||
import com.wisemapping.service.InvalidUserEmailException;
|
||||
import com.wisemapping.service.RecaptchaService;
|
||||
import com.wisemapping.service.UserService;
|
||||
import com.wisemapping.validator.Messages;
|
||||
import com.wisemapping.validator.UserValidator;
|
||||
import com.wisemapping.view.UserBean;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Properties;
|
||||
|
||||
@Controller
|
||||
public class UsersController {
|
||||
|
||||
@@ -53,99 +37,14 @@ public class UsersController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private RecaptchaService captchaService;
|
||||
|
||||
@Value("${google.recaptcha2.enabled}")
|
||||
private boolean captchaEnabled;
|
||||
|
||||
@Value("${google.recaptcha2.siteKey}")
|
||||
private String recaptchaSiteKey;
|
||||
|
||||
@RequestMapping(value = "user/resetPassword", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "forgot-password", method = RequestMethod.GET)
|
||||
public ModelAndView showResetPasswordPage() {
|
||||
return new ModelAndView("forgotPassword");
|
||||
return new ModelAndView("forgot-password");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "user/resetPassword", method = RequestMethod.POST)
|
||||
public ModelAndView resetPassword(@RequestParam(required = true) String email) {
|
||||
|
||||
ModelAndView result;
|
||||
try {
|
||||
userService.resetPassword(email);
|
||||
result = new ModelAndView("forgotPasswordSuccess");
|
||||
|
||||
} catch (InvalidUserEmailException | InvalidAuthSchemaException e) {
|
||||
result = new ModelAndView("forgotPasswordError");
|
||||
}
|
||||
return result;
|
||||
@RequestMapping(value = "registration", method = RequestMethod.GET)
|
||||
public ModelAndView showRegistrationPage() {
|
||||
return new ModelAndView("registration");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "user/registration", method = RequestMethod.GET)
|
||||
public ModelAndView showRegistrationPage(@NotNull HttpServletRequest request) {
|
||||
if (captchaEnabled) {
|
||||
// If captcha is enabled, generate it ...
|
||||
final Properties prop = new Properties();
|
||||
prop.put("theme", "white");
|
||||
request.setAttribute("recaptchaSiteKey", recaptchaSiteKey);
|
||||
request.setAttribute("recaptchaEnabled", true);
|
||||
}
|
||||
return new ModelAndView("userRegistration", "user", new UserBean());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "user/registration", method = RequestMethod.POST)
|
||||
public ModelAndView registerUser(@ModelAttribute("user") UserBean userBean, @NotNull HttpServletRequest request, @NotNull BindingResult bindingResult) throws WiseMappingException {
|
||||
ModelAndView result;
|
||||
validateRegistrationForm(userBean, request, bindingResult);
|
||||
if (bindingResult.hasErrors()) {
|
||||
result = this.showRegistrationPage(request);
|
||||
result.addObject("user", userBean);
|
||||
} else {
|
||||
final User user = new User();
|
||||
|
||||
// trim() the email email in order to remove spaces ...
|
||||
user.setEmail(userBean.getEmail().trim());
|
||||
user.setFirstname(userBean.getFirstname());
|
||||
user.setLastname(userBean.getLastname());
|
||||
user.setPassword(userBean.getPassword());
|
||||
|
||||
boolean confirmRegistrationByEmail = false;
|
||||
user.setAuthenticationType(AuthenticationType.DATABASE);
|
||||
userService.createUser(user, confirmRegistrationByEmail, true);
|
||||
|
||||
// Forward to the success view ...
|
||||
result = new ModelAndView("userRegistrationSuccess");
|
||||
result.addObject("confirmByEmail", confirmRegistrationByEmail);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "account/settings", method = RequestMethod.GET)
|
||||
public String showUserSettingsPage(@NotNull Model model) {
|
||||
model.addAttribute("user", Utils.getUser());
|
||||
return "accountSettings";
|
||||
}
|
||||
|
||||
private void validateRegistrationForm(@NotNull UserBean userBean, @NotNull HttpServletRequest request, @NotNull BindingResult bindingResult) {
|
||||
final UserValidator userValidator = new UserValidator();
|
||||
userValidator.setUserService(userService);
|
||||
userValidator.setCaptchaService(captchaService);
|
||||
userValidator.validate(userBean, bindingResult);
|
||||
|
||||
// If captcha is enabled, generate it ...
|
||||
if (captchaEnabled) {
|
||||
final String gReponse = request.getParameter("g-recaptcha-response");
|
||||
|
||||
if (gReponse != null) {
|
||||
final String remoteAddr = request.getRemoteAddr();
|
||||
final String reCaptchaResponse = captchaService.verifyRecaptcha(remoteAddr, gReponse);
|
||||
if (!reCaptchaResponse.isEmpty()) {
|
||||
bindingResult.rejectValue("captcha", reCaptchaResponse);
|
||||
}
|
||||
|
||||
} else {
|
||||
bindingResult.rejectValue("captcha", Messages.CAPTCHA_LOADING_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user