Kaptcha & E-mail 10. díl
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 23 Mar 2010 15:09:19 +0100
changeset 836767606d6342
parent 82 df86ad0c0e55
child 84 bafba5e82cb6
Kaptcha & E-mail
java/nekurak.net-web/nbproject/build-impl.xml
java/nekurak.net-web/nbproject/genfiles.properties
java/nekurak.net-web/nbproject/project.properties
java/nekurak.net-web/nbproject/project.xml
java/nekurak.net-web/web/WEB-INF/web.xml
java/nekurak.net-web/web/grafika/info.png
java/nekurak.net-web/web/kaptcha.jsp
java/nekurak.net-web/web/styl.css
     1.1 --- a/java/nekurak.net-web/nbproject/build-impl.xml	Tue Mar 23 12:11:04 2010 +0100
     1.2 +++ b/java/nekurak.net-web/nbproject/build-impl.xml	Tue Mar 23 15:09:19 2010 +0100
     1.3 @@ -537,13 +537,13 @@
     1.4      <target depends="init,compile,compile-jsps,-pre-dist,-do-dist-with-manifest,-do-dist-without-manifest" name="do-dist"/>
     1.5      <target depends="init" if="dist.ear.dir" name="library-inclusion-in-manifest">
     1.6          <copyfiles files="${reference.nekurak_net-lib.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
     1.7 -        <copyfiles files="${libs.restlib_gfv3ee6.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
     1.8 +        <copyfiles files="${libs.Kaptcha.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
     1.9          <mkdir dir="${build.web.dir}/META-INF"/>
    1.10          <manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update"/>
    1.11      </target>
    1.12      <target depends="init" name="library-inclusion-in-archive" unless="dist.ear.dir">
    1.13          <copyfiles files="${reference.nekurak_net-lib.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
    1.14 -        <copyfiles files="${libs.restlib_gfv3ee6.classpath}" todir="${build.web.dir}/WEB-INF/lib"/>
    1.15 +        <copyfiles files="${libs.Kaptcha.classpath}" todir="${build.web.dir}/WEB-INF/lib"/>
    1.16      </target>
    1.17      <target depends="init" if="dist.ear.dir" name="-clean-webinf-lib">
    1.18          <delete dir="${build.web.dir}/WEB-INF/lib"/>
     2.1 --- a/java/nekurak.net-web/nbproject/genfiles.properties	Tue Mar 23 12:11:04 2010 +0100
     2.2 +++ b/java/nekurak.net-web/nbproject/genfiles.properties	Tue Mar 23 15:09:19 2010 +0100
     2.3 @@ -3,8 +3,8 @@
     2.4  build.xml.stylesheet.CRC32=c0ebde35@1.21.2.1
     2.5  # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
     2.6  # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
     2.7 -nbproject/build-impl.xml.data.CRC32=44af31d0
     2.8 -nbproject/build-impl.xml.script.CRC32=aefcc545
     2.9 +nbproject/build-impl.xml.data.CRC32=28fc3c5a
    2.10 +nbproject/build-impl.xml.script.CRC32=cdc87d62
    2.11  nbproject/build-impl.xml.stylesheet.CRC32=b139b33b@1.21.2.1
    2.12  nbproject/rest-build.xml.data.CRC32=84da1c7b
    2.13  nbproject/rest-build.xml.script.CRC32=3db088b3
     3.1 --- a/java/nekurak.net-web/nbproject/project.properties	Tue Mar 23 12:11:04 2010 +0100
     3.2 +++ b/java/nekurak.net-web/nbproject/project.properties	Tue Mar 23 15:09:19 2010 +0100
     3.3 @@ -27,7 +27,7 @@
     3.4  jar.compress=false
     3.5  javac.classpath=\
     3.6      ${reference.nekurak_net-lib.jar}:\
     3.7 -    ${libs.restlib_gfv3ee6.classpath}
     3.8 +    ${libs.Kaptcha.classpath}
     3.9  # Space-separated list of extra javac options
    3.10  javac.compilerargs=
    3.11  javac.debug=true
     4.1 --- a/java/nekurak.net-web/nbproject/project.xml	Tue Mar 23 12:11:04 2010 +0100
     4.2 +++ b/java/nekurak.net-web/nbproject/project.xml	Tue Mar 23 15:09:19 2010 +0100
     4.3 @@ -16,7 +16,7 @@
     4.4                      <path-in-war>WEB-INF/lib</path-in-war>
     4.5                  </library>
     4.6                  <library dirs="200">
     4.7 -                    <file>${libs.restlib_gfv3ee6.classpath}</file>
     4.8 +                    <file>${libs.Kaptcha.classpath}</file>
     4.9                      <path-in-war>WEB-INF/lib</path-in-war>
    4.10                  </library>
    4.11              </web-module-libraries>
     5.1 --- a/java/nekurak.net-web/web/WEB-INF/web.xml	Tue Mar 23 12:11:04 2010 +0100
     5.2 +++ b/java/nekurak.net-web/web/WEB-INF/web.xml	Tue Mar 23 15:09:19 2010 +0100
     5.3 @@ -1,81 +1,89 @@
     5.4  <?xml version="1.0" encoding="UTF-8"?>
     5.5  <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
     5.6      <session-config>
     5.7 -        <session-timeout>30</session-timeout>
     5.8 +	<session-timeout>30</session-timeout>
     5.9      </session-config>
    5.10      <welcome-file-list>
    5.11 -        <welcome-file>index.jsp</welcome-file>
    5.12 +	<welcome-file>index.jsp</welcome-file>
    5.13      </welcome-file-list>
    5.14      <!-- <chybovéStránky> -->
    5.15      <error-page>
    5.16 -        <!-- Stránka nenalezena -->
    5.17 -        <error-code>404</error-code>
    5.18 -        <location>/WEB-INF/chyby/404.jsp</location>
    5.19 +	<!-- Stránka nenalezena -->
    5.20 +	<error-code>404</error-code>
    5.21 +	<location>/WEB-INF/chyby/404.jsp</location>
    5.22      </error-page>
    5.23      <error-page>
    5.24 -        <!-- Interní chyba serveru -->
    5.25 -        <error-code>500</error-code>
    5.26 -        <location>/WEB-INF/chyby/500.jsp</location>
    5.27 +	<!-- Interní chyba serveru -->
    5.28 +	<error-code>500</error-code>
    5.29 +	<location>/WEB-INF/chyby/500.jsp</location>
    5.30      </error-page>
    5.31      <!-- </chybovéStránky> -->
    5.32      <!-- <definiceServletů> -->
    5.33      <servlet>
    5.34 -        <servlet-name>atom</servlet-name>
    5.35 -        <jsp-file>/WEB-INF/atom/atom.jsp</jsp-file>
    5.36 +	<servlet-name>atom</servlet-name>
    5.37 +	<jsp-file>/WEB-INF/atom/atom.jsp</jsp-file>
    5.38      </servlet>
    5.39      <servlet>
    5.40 -        <description>
    5.41 +	<description>
    5.42  	    Servlet zpřístupňující fotky umístěné ve zvláštním adresáři
    5.43  	    (data oddělená od aplikace).
    5.44  	</description>
    5.45 -        <servlet-name>fotky</servlet-name>
    5.46 -        <servlet-class>cz.frantovo.nekurak.servlet.Fotky</servlet-class>
    5.47 -        <init-param>
    5.48 -            <description>
    5.49 +	<servlet-name>fotky</servlet-name>
    5.50 +	<servlet-class>cz.frantovo.nekurak.servlet.Fotky</servlet-class>
    5.51 +	<init-param>
    5.52 +	    <description>
    5.53  		Adresář na disku, který obsahuje fotky podniků.
    5.54  		Musí existovat při startu aplikace.
    5.55  	    </description>
    5.56 -            <param-name>adresar</param-name>
    5.57 -            <param-value>/var/www/nekurak.net/fotky</param-value>
    5.58 -        </init-param>
    5.59 -        <load-on-startup>1</load-on-startup>
    5.60 +	    <param-name>adresar</param-name>
    5.61 +	    <param-value>/var/www/nekurak.net/fotky</param-value>
    5.62 +	</init-param>
    5.63 +	<load-on-startup>1</load-on-startup>
    5.64 +    </servlet>
    5.65 +    <servlet>
    5.66 +	<servlet-name>Kaptcha</servlet-name>
    5.67 +	<servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
    5.68      </servlet>
    5.69      <!-- </definiceServletů> -->
    5.70      <!-- <mapováníServletů> -->
    5.71      <servlet-mapping>
    5.72 -        <servlet-name>fotky</servlet-name>
    5.73 -        <url-pattern>/fotky/*</url-pattern>
    5.74 +	<servlet-name>fotky</servlet-name>
    5.75 +	<url-pattern>/fotky/*</url-pattern>
    5.76      </servlet-mapping>
    5.77      <servlet-mapping>
    5.78 -        <servlet-name>atom</servlet-name>
    5.79 -        <url-pattern>/atom/*</url-pattern>
    5.80 +	<servlet-name>atom</servlet-name>
    5.81 +	<url-pattern>/atom/*</url-pattern>
    5.82 +    </servlet-mapping>
    5.83 +    <servlet-mapping>
    5.84 +	<servlet-name>Kaptcha</servlet-name>
    5.85 +	<url-pattern>/kaptcha.jpg</url-pattern>
    5.86      </servlet-mapping>
    5.87      <!-- </mapováníServletů> -->
    5.88      <context-param>
    5.89 -        <!-- Pro případ, že chybí hlavička „Accept-language“ v HTTP požadavku -->
    5.90 -        <param-name>javax.servlet.jsp.jstl.fmt.fallbackLocale</param-name>
    5.91 -        <param-value>cs</param-value>
    5.92 +	<!-- Pro případ, že chybí hlavička „Accept-language“ v HTTP požadavku -->
    5.93 +	<param-name>javax.servlet.jsp.jstl.fmt.fallbackLocale</param-name>
    5.94 +	<param-value>cs</param-value>
    5.95      </context-param>
    5.96      <!--  <zabezpečení> -->
    5.97      <security-role>
    5.98 -        <role-name>opravneny</role-name>
    5.99 +	<role-name>opravneny</role-name>
   5.100      </security-role>
   5.101      <security-constraint>
   5.102 -        <web-resource-collection>
   5.103 -            <web-resource-name>Správa Nekuřák.net</web-resource-name>
   5.104 -            <url-pattern>/sprava/*</url-pattern>
   5.105 -        </web-resource-collection>
   5.106 -        <auth-constraint>
   5.107 -            <role-name>opravneny</role-name>
   5.108 -        </auth-constraint>
   5.109 +	<web-resource-collection>
   5.110 +	    <web-resource-name>Správa Nekuřák.net</web-resource-name>
   5.111 +	    <url-pattern>/sprava/*</url-pattern>
   5.112 +	</web-resource-collection>
   5.113 +	<auth-constraint>
   5.114 +	    <role-name>opravneny</role-name>
   5.115 +	</auth-constraint>
   5.116      </security-constraint>
   5.117      <login-config>
   5.118 -        <auth-method>FORM</auth-method>
   5.119 -        <realm-name>nekurakNET</realm-name>
   5.120 -        <form-login-config>
   5.121 -            <form-login-page>/?akce=prihlaseni</form-login-page>
   5.122 -            <form-error-page>/?akce=prihlaseni&amp;chyba=ano</form-error-page>
   5.123 -        </form-login-config>
   5.124 +	<auth-method>FORM</auth-method>
   5.125 +	<realm-name>nekurakNET</realm-name>
   5.126 +	<form-login-config>
   5.127 +	    <form-login-page>/?akce=prihlaseni</form-login-page>
   5.128 +	    <form-error-page>/?akce=prihlaseni&amp;chyba=ano</form-error-page>
   5.129 +	</form-login-config>
   5.130      </login-config>
   5.131      <!--  </zabezpečení> -->
   5.132  </web-app>
     6.1 Binary file java/nekurak.net-web/web/grafika/info.png has changed
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/java/nekurak.net-web/web/kaptcha.jsp	Tue Mar 23 15:09:19 2010 +0100
     7.3 @@ -0,0 +1,72 @@
     7.4 +<?xml version="1.0" encoding="UTF-8"?>
     7.5 +<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
     7.6 +	  xmlns:c="http://java.sun.com/jsp/jstl/core"
     7.7 +	  xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
     7.8 +	  xmlns:fn="http://java.sun.com/jsp/jstl/functions"
     7.9 +	  xmlns:nk="urn:jsptagdir:/WEB-INF/tags/nekurak"
    7.10 +	  version="2.0">
    7.11 +
    7.12 +    <jsp:directive.page contentType="application/xhtml+xml"/>
    7.13 +
    7.14 +    <!-- <lokalizace> -->
    7.15 +    <c:if test="${param.jazyk != null}">
    7.16 +	<fmt:setLocale value="${param.jazyk}" scope="session"/>
    7.17 +    </c:if>
    7.18 +    <fmt:setBundle basename="cz.frantovo.nekurak.preklady" scope="application"/>
    7.19 +    <!-- </lokalizace> -->
    7.20 +
    7.21 +    <nk:stranka titulek="Kaptcha">
    7.22 +
    7.23 +	<h1><c:out value="Kaptcha – ukázka"/></h1>
    7.24 +
    7.25 +	<c:choose>
    7.26 +	    <c:when test="${param.akce == 'odeslat'}">
    7.27 +		<p>Odeslané údaje:</p>
    7.28 +
    7.29 +		<p>Políčko 1: <c:out value="${param.policko1}"/></p>
    7.30 +		<p>Políčko 2: <c:out value="${param.policko2}"/></p>
    7.31 +		<p>Kaptcha: <c:out value="${param.kaptcha}"/></p>
    7.32 +
    7.33 +		<p>Očekávaná hodnota: <c:out value="${sessionScope['KAPTCHA_SESSION_KEY']}"/></p>
    7.34 +
    7.35 +		<c:choose>
    7.36 +		    <c:when test="${sessionScope['KAPTCHA_SESSION_KEY'] == param.kaptcha}">
    7.37 +			<p class="informacniHlaska">Správně opsaný kód z obrázku.</p>
    7.38 +		    </c:when>
    7.39 +		    <c:otherwise>
    7.40 +			<p class="chybovaHlaska">Špatně obsaný kód z obrázku.</p>
    7.41 +		    </c:otherwise>
    7.42 +		</c:choose>
    7.43 +
    7.44 +
    7.45 +
    7.46 +	    </c:when>
    7.47 +	    <c:otherwise>
    7.48 +		<!-- Zobrazíme uživateli registrační formulář. -->
    7.49 +		<p>Nějaký formulář, který chceme ochránit proti spamu:</p>
    7.50 +		<form method="post" action="kaptcha.jsp?akce=odeslat">
    7.51 +		    <fieldset>
    7.52 +			<label>Políčko 1: <input type="text" name="policko1" maxlength="255"/></label><br/>
    7.53 +			<label>Políčko 2: <input type="text" name="policko2" maxlength="255"/></label><br/>
    7.54 +		    </fieldset>
    7.55 +		    <fieldset>
    7.56 +			<!-- Kaptcha -->
    7.57 +			<img src="kaptcha.jpg" alt="ochrana proti spamu" id="kaptchaIMG" title="klikněte pro vygenerování nového obrázku"/><br/>
    7.58 +			<script type="text/javascript">
    7.59 +			    $(function(){
    7.60 +				$('#kaptchaIMG').click(function () { $(this).attr('src', 'kaptcha.jpg?' + Math.floor(Math.random()*100) ); })
    7.61 +			    });
    7.62 +			</script>
    7.63 +
    7.64 +			<label>Opište: <input type="text" name="kaptcha" maxlength="255"/></label><br/>
    7.65 +		    </fieldset>
    7.66 +		    <fieldset>
    7.67 +			<button value="submit">Odeslat</button>
    7.68 +		    </fieldset>
    7.69 +		</form>
    7.70 +	    </c:otherwise>
    7.71 +	</c:choose>
    7.72 +
    7.73 +    </nk:stranka>
    7.74 +
    7.75 +</jsp:root>
     8.1 --- a/java/nekurak.net-web/web/styl.css	Tue Mar 23 12:11:04 2010 +0100
     8.2 +++ b/java/nekurak.net-web/web/styl.css	Tue Mar 23 15:09:19 2010 +0100
     8.3 @@ -142,6 +142,19 @@
     8.4      background-color: #ffc65e;
     8.5  }
     8.6  
     8.7 +.informacniHlaska {
     8.8 +    background-image: url('grafika/info.png');
     8.9 +    background-repeat: no-repeat;
    8.10 +    background-position: 8px 8px;
    8.11 +    min-height: 33px;
    8.12 +    padding-top: 15px;
    8.13 +    padding-left: 50px;
    8.14 +    margin-top: 10px;
    8.15 +    margin-bottom: 10px;
    8.16 +    border: 2px solid #99ccff;
    8.17 +    background-color: #bfdfff;
    8.18 +}
    8.19 +
    8.20  .registraceKontrolaUdaju {
    8.21      color: gray;
    8.22  }