use of org.thymeleaf.context.Context in project jlineup by otto-de.
the class HTMLReportWriter method renderReport.
String renderReport(String template, List<ScreenshotComparisonResult> screenshotComparisonResults) throws FileNotFoundException {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setTemplateMode("HTML");
templateResolver.setPrefix("templates/");
templateResolver.setSuffix(".html");
TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
final Map<String, Object> variables = prepareVariablesForReportTemplate(screenshotComparisonResults);
return templateEngine.process(template, new Context(Locale.US, variables));
}
use of org.thymeleaf.context.Context in project judge by zjnu-acm.
the class ResetPasswordController method doPost.
@PostMapping("/resetPassword")
public void doPost(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "action", required = false) String action, @RequestParam(value = "verify", required = false) String verify, @RequestParam(value = "username", required = false) String username, Locale locale) throws IOException {
response.setContentType("text/javascript;charset=UTF-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession(false);
String word = null;
if (session != null) {
word = (String) session.getAttribute("word");
session.removeAttribute("word");
}
if (word == null || !word.equalsIgnoreCase(verify)) {
out.print("alert('验证码错误');");
return;
}
User user = userMapper.findOne(username);
if (user == null) {
out.print("alert('用户不存在');");
return;
}
String email = user.getEmail();
if (email == null || !email.toLowerCase().matches(ValueCheck.EMAIL_PATTERN)) {
out.print("alert('该用户未设置邮箱或邮箱格式不对,如需重置密码,请联系管理员!');");
return;
}
try {
String vc = resetPasswordService.getOrCreate(user.getId());
String url = getPath(request, "/resetPassword.html?vc=", vc + "&u=", user.getId());
String title = systemService.getResetPasswordTitle();
Map<String, Object> map = ImmutableMap.of("url", url, "title", Objects.toString(title, ""));
String content = templateEngine.process("users/password", new Context(locale, map));
emailService.send(email, title, content);
} catch (MailException | MessagingException ex) {
log.error("fail to send email", ex);
out.print("alert('邮件发送失败,请稍后再试')");
return;
}
out.print("alert('已经将邮件发送到" + user.getEmail() + ",请点击链接重设密码');");
}
use of org.thymeleaf.context.Context in project DisCal-Discord-Bot by NovaFox161.
the class ThymeleafTemplateEngine method render.
/**
* Process the specified template (usually the template name).
* Output will be written into a String that will be returned from calling this method,
* once template processing has finished.
*
* @param modelAndView model and view
* @param locale A Locale object represents a specific geographical, political, or cultural region
* @return processed template
*/
public String render(ModelAndView modelAndView, Locale locale) {
Object model = modelAndView.getModel();
if (model instanceof Map) {
Context context = new Context(locale);
context.setVariables((Map<String, Object>) model);
return templateEngine.process(modelAndView.getViewName(), context);
} else {
throw new IllegalArgumentException("modelAndView.getModel() must return a java.util.Map");
}
}
use of org.thymeleaf.context.Context in project tutorials by eugenp.
the class MailService method sendActivationEmail.
@Async
public void sendActivationEmail(User user) {
log.debug("Sending activation e-mail to '{}'", user.getEmail());
Locale locale = Locale.forLanguageTag(user.getLangKey());
Context context = new Context(locale);
context.setVariable(USER, user);
context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
String content = templateEngine.process("activationEmail", context);
String subject = messageSource.getMessage("email.activation.title", null, locale);
sendEmail(user.getEmail(), subject, content, false, true);
}
use of org.thymeleaf.context.Context in project tutorials by eugenp.
the class MailService method sendActivationEmail.
@Async
public void sendActivationEmail(User user) {
log.debug("Sending activation e-mail to '{}'", user.getEmail());
Locale locale = Locale.forLanguageTag(user.getLangKey());
Context context = new Context(locale);
context.setVariable(USER, user);
context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
String content = templateEngine.process("activationEmail", context);
String subject = messageSource.getMessage("email.activation.title", null, locale);
sendEmail(user.getEmail(), subject, content, false, true);
}
Aggregations