package coreservlets;

import javax.servlet.http.*;
import org.apache.struts.action.*;

/** Obiekt Action, który może zwrócić jeden z trzech warunków:
 *    bad-address  jeżeli nie podano adresu email albo adres nia zawiera znaku @
 *    bad-password jeżeli nie podano hasła albo jest ono krótsze niż sześć znaków
 *    success      jeżeli adres email oraz hasło są prawidłowe
 *  <P>
 *  Taken from Core Servlets and JavaServer Pages Volume II
 *  from Prentice Hall and Sun Microsystems Press,
 *  http://volume2.coreservlets.com/.
 *  (C) 2007 Marty Hall, Larry Brown, and Yaakov Chaikin;
 *  may be freely used or adapted.
 */

public class RegisterAction2 extends Action {
  public ActionForward execute(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
      throws Exception {
    String email = request.getParameter("email");
    String password = request.getParameter("password");
    if ((email == null) ||
        (email.trim().length() < 3) ||
        (email.indexOf("@") == -1)) {
      return(mapping.findForward("bad-address"));
    } else if ((password == null) ||
               (password.trim().length() < 6)) {
      return(mapping.findForward("bad-password"));
    } else {
      return(mapping.findForward("success"));
    }
  }
}
