Почему бы не создать логический флаг acceptTAC для типа клиента?Если кто-то запрашивает страницу в вашей витрине магазина, для которой этот флаг установлен в null или false, вы можете показать это всплывающее окно.Когда пользователь нажимает кнопку подтверждения, отправьте запрос AJAX на сервер и установите для флага acceptTAC значение true.
Таким образом, у вас даже есть «доказательство» того, что пользователь принял TAC.Кроме того, вы можете запросить вашу базу данных для пользователей, которые еще не приняли TAC.
Однако обычным способом заставить пользователя принять TAC будет регистрация.Пользователь может зарегистрироваться только тогда, когда он / она принимает TAC.
Вот необходимые шаги:
myextension-items.xml
<itemtype code="Customer" ...>
<attributes>
<attribute name="acceptedTermsAndConditions" type="java.lang.Boolean">
..
</attribute>
<attributes>
</itemtype>
ShowTermsAndConditionsPopupBeforeViewHandler
public class ShowTermsAndConditionsPopupBeforeViewHandler implements BeforeViewHandler {
@Resource
UserService userService;
@Override
public void beforeView(HttpServletRequest request, HttpServletResponse response, ModelAndView modelAndView) {
UserModel user = userService.getCurrentUser();
if (user instanceof CustomerModel && !userService.isAnonymousUser(user)) {
CustomerModel customer = (CustomerModel) user;
modelAndView.addObject("showTermsAndConditionsPopup", BooleanUtils.isNotTrue(customer.isTermsAndConditionsAccepted()));
} else {
modelAndView.addObject("showTermsAndConditionsPopup", false);
}
}
}
Зарегистрировать BeforeViewHandler в spring-mvc-config.xml
...
<util:list id="defaultBeforeViewHandlersList">
...
<bean class="my.package.ShowTermsAndConditionsPopupBeforeViewHandler"/>
...
</util:list>
...
Создание переменной JavaScript в javaScriptVariables.tag
...
ACC.config.showTermsAndConditionsPopup=${showTermsAndConditionsPopup};
...
Добавление логики для открытия всплывающего окна в JavaScript
...
if(ACC.config.showTermsAndConditionsPopup) {
showPopup();
}
...
Создание всплывающего содержимого с помощью формы:
<c:url var="url" value="/acceptTermsAndConditions" />
<form action="${url}" method="POST">
<label for="acceptTermsAndConditions">I accept Terms and Conditions</label>
<input type="checkbox" id="acceptTermsAndConditions" name="acceptTermsAndConditions" />
<button type="submit>Submit</button>
</form>
Создать условияAndConditionsController
@Controller
public TermsAndConditionsController {
@Resource
private UserService userService;
@Resource
private ModelService modelService;
@RequestMapping(value = "/acceptTermsAndConditions", method = RequestMethod.POST)
@ResponseBody
@ResponseStatus(value = HttpStatus.OK)
public void acceptTermsAndConditions() {
UserModel user = userService.getCurrentUser();
if (user instanceof CustomerModel && !userService.isAnonymousUser(user)) {
CustomerModel customer = (CustomerModel) user;
customer.setAcceptedTermsAndConditions(true);
modelService.save(customer);
}
}
}