Various fixes

db4
Slava Pestov 2008-05-27 01:18:38 -05:00
parent 5f4ffa998f
commit 8278ac5b28
7 changed files with 41 additions and 10 deletions

View File

@ -10,7 +10,7 @@
<tr> <tr>
<th class="field-label">User name:</th> <th class="field-label">User name:</th>
<td><t:field t:name="username" /></td> <td><t:label t:name="username" /></td>
</tr> </tr>
<tr> <tr>

View File

@ -63,7 +63,7 @@
<p> <p>
<input type="submit" value="Register" /> <input type="submit" value="Register" />
<t:validation-message /> <t:validation-messages />
</p> </p>

View File

@ -47,6 +47,21 @@ namespaces assocs ;
[ "http:/www.factorcode.org" v-url ] [ "http:/www.factorcode.org" v-url ]
[ "invalid URL" = ] must-fail-with [ "invalid URL" = ] must-fail-with
[ 4561261212345467 ] [ "4561261212345467" v-credit-card ] unit-test
[ 4561261212345467 ] [ "4561-2612-1234-5467" v-credit-card ] unit-test
[ 0 ] [ "0000000000000000" v-credit-card ] unit-test
[ "000000000" v-credit-card ] must-fail
[ "0000000000000000000000000" v-credit-card ] must-fail
[ "4561_2612_1234_5467" v-credit-card ] must-fail
[ "4561-2621-1234-5467" v-credit-card ] must-fail
[ 14 V{ } ] [ [ 14 V{ } ] [
[ [
"14" "age" [ v-number 13 v-min-value 100 v-max-value ] validate "14" "age" [ v-number 13 v-min-value 100 v-max-value ] validate

View File

@ -1,9 +1,9 @@
! Copyright (C) 2006, 2008 Slava Pestov ! Copyright (C) 2006, 2008 Slava Pestov
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel continuations sequences math namespaces sets USING: kernel continuations sequences sequences.lib math
math.parser assocs regexp fry unicode.categories sequences namespaces sets math.parser math.ranges assocs regexp fry
arrays hashtables words combinators mirrors classes quotations unicode.categories arrays hashtables words combinators mirrors
xmode.catalog ; classes quotations xmode.catalog ;
IN: validators IN: validators
: v-default ( str def -- str ) : v-default ( str def -- str )
@ -91,6 +91,23 @@ IN: validators
"not a valid syntax mode" throw "not a valid syntax mode" throw
] unless ; ] unless ;
: luhn? ( n -- ? )
string>digits <reversed>
[ odd? [ 2 * 10 /mod + ] when ] map-index
sum 10 mod 0 = ;
: v-credit-card ( str -- n )
"- " diff
dup CHAR: 0 CHAR: 9 [a,b] diff empty? [
13 v-min-length
16 v-max-length
dup luhn? [ string>number ] [
"card number check failed" throw
] if
] [
"invalid credit card number format" throw
] if ;
SYMBOL: validation-messages SYMBOL: validation-messages
SYMBOL: named-validation-messages SYMBOL: named-validation-messages

View File

@ -12,7 +12,6 @@ http.server.auth.login
http.server.auth http.server.auth
http.server.sessions http.server.sessions
http.server.actions http.server.actions
http.server.crud
http.server ; http.server ;
IN: webapps.user-admin IN: webapps.user-admin

View File

@ -166,10 +166,10 @@ TUPLE: wiki < dispatcher ;
<main-article-action> "" add-responder <main-article-action> "" add-responder
<view-article-action> "view" add-responder <view-article-action> "view" add-responder
<view-revision-action> "revision" add-responder <view-revision-action> "revision" add-responder
<edit-article-action> { } <protected> "edit" add-responder
<list-revisions-action> "revisions" add-responder <list-revisions-action> "revisions" add-responder
<delete-action> "delete" add-responder
<diff-action> "diff" add-responder <diff-action> "diff" add-responder
<list-articles-action> "articles" add-responder <list-articles-action> "articles" add-responder
<edit-article-action> { } <protected> "edit" add-responder
<delete-action> { } <protected> "delete" add-responder
<boilerplate> <boilerplate>
"wiki-common" wiki-template >>template ; "wiki-common" wiki-template >>template ;

View File

@ -1,4 +1,4 @@
USING: xmode.tokens xmode.marker xmode.catalog kernel html USING: xmode.tokens xmode.marker xmode.catalog kernel
html.elements io io.files sequences words io.encodings.utf8 html.elements io io.files sequences words io.encodings.utf8
namespaces xml.entities ; namespaces xml.entities ;
IN: xmode.code2html IN: xmode.code2html