Package controller

Source Code of controller.LostPassWordCTRL

package controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import manager.PersonalInfoManager;

import org.springframework.validation.BindException;
import org.springframework.validation.ValidationUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import util.MailSenDer;
import domain.PersonalInfo;

public class LostPassWordCTRL extends SimpleFormController {

  private PersonalInfoManager pimng;

  public PersonalInfoManager getPimng() {
    return pimng;
  }

  public void setPimng(PersonalInfoManager pimng) {
    this.pimng = pimng;
  }

  public LostPassWordCTRL() {
    setFormView("email-form");
    setCommandClass(PersonalInfo.class);
    setCommandName("pi");
  }

  @Override
  protected ModelAndView onSubmit(HttpServletRequest request,
      HttpServletResponse response, Object command, BindException be)
      throws Exception {
    Map model = new HashMap();
    String email = request.getParameter("email");
    PersonalInfo pi = pimng.findPassForEmail(email);

   
    if (!email.equals("")) {
      if (!email
          .matches("^\\w[_\\-\\.\\w]*\\@\\w[_\\-\\.\\w]*\\.(\\w){2,5}$")) {
        be.rejectValue("email", "email.invalid", "Email invalide");
        return showForm(request, response, be);
      }
    }else{
      ValidationUtils.rejectIfEmpty(be, "email", "email.required",
      "Email requis");
      return showForm(request, response, be);
    }

    if (pi == null) {
      be.rejectValue("email", "email.invalid", "Adresse inconnue");
      return showForm(request, response, be);
    } else {
      String path = request.getSession().getServletContext().getRealPath(
          "/");
      MailSenDer ms = new MailSenDer(path + "mail.properties");
      ms.senLostPass(email, pi.getLastname() + " " + pi.getFirstname(),
          pi.getPassword());
      model.put("email", email);
      return new ModelAndView("pass-sent", model);
    }

  }

}
TOP

Related Classes of controller.LostPassWordCTRL

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.