From 5ff7a83cfd5f03085121e8ef68c5033a86cc5b36 Mon Sep 17 00:00:00 2001 From: Yuzo Hebishima Date: Thu, 17 Jan 2013 19:04:35 +0900 Subject: [PATCH] =?UTF-8?q?=E5=85=A5=E5=8A=9B=E3=83=81=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=81=AE=E4=BD=9C=E6=88=90=E3=81=A8=E3=83=A1=E3=83=83?= =?UTF-8?q?=E3=82=BB=E3=83=BC=E3=82=B8=E9=83=A8=E5=88=86=E3=81=AE=E4=BD=9C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/application_ja.properties | 11 +++- .../controller/login/RegisterController.java | 50 +++++++----------- .../validator/login/RegisterValidators.java | 28 ++++++++++ .../validator/login/SameActorValidator.java | 49 +++++++++++++++++ .../login/SamePasswordValidator.java | 37 +++++++++++++ src/jp/dogrun/ileaflet/meta/ActorMeta.java | 2 +- .../datastore-indexes-auto.xml | 2 +- war/WEB-INF/appengine-generated/local_db.bin | Bin 3249 -> 3152 bytes war/WEB-INF/classes/application_ja.properties | 11 +++- war/mainFrame.jsp | 7 +++ 10 files changed, 163 insertions(+), 34 deletions(-) create mode 100644 src/jp/dogrun/ileaflet/controller/validator/login/RegisterValidators.java create mode 100644 src/jp/dogrun/ileaflet/controller/validator/login/SameActorValidator.java create mode 100644 src/jp/dogrun/ileaflet/controller/validator/login/SamePasswordValidator.java diff --git a/resources/application_ja.properties b/resources/application_ja.properties index 45d0f63..08f1b94 100644 --- a/resources/application_ja.properties +++ b/resources/application_ja.properties @@ -10,4 +10,13 @@ validator.dateType={0}\u306f\u65e5\u4ed8({1})\u3067\u306f\u3042\u308a\u307e\u305 validator.minlength={0}\u306e\u9577\u3055\u304c\u6700\u5c0f\u5024({1})\u672a\u6e80\u3067\u3059\u3002 validator.maxlength={0}\u306e\u9577\u3055\u304c\u6700\u5927\u5024({1})\u3092\u8d85\u3048\u3066\u3044\u307e\u3059\u3002 validator.range={0}\u306f{1}\u3068{2}\u306e\u9593\u3067\u306a\u3051\u308c\u3070\u3044\u3051\u307e\u305b\u3093\u3002 -validator.regexp={0}\u304c\u4e0d\u6b63\u3067\u3059\u3002 \ No newline at end of file +validator.regexp={0}\u304c\u4e0d\u6b63\u3067\u3059\u3002 + +validator.samePassword={0}\u304c\u4e00\u81f4\u3057\u307e\u305b\u3093\u3002 +validator.sameIdentity=\u540c\u4e00\u306e{0}\u306e\u30e6\u30fc\u30b6\u304c\u5b58\u5728\u3057\u307e\u3059\u3002 +validator.sameMail=\u540c\u4e00\u306e{0}\u306e\u30e6\u30fc\u30b6\u304c\u5b58\u5728\u3057\u307e\u3059\u3002 + +label.identity=ID +label.password=\u30d1\u30b9\u30ef\u30fc\u30c9 +label.mail=\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9 +label.name=\u8868\u793a\u540d \ No newline at end of file diff --git a/src/jp/dogrun/ileaflet/controller/login/RegisterController.java b/src/jp/dogrun/ileaflet/controller/login/RegisterController.java index 4085826..e0cd61d 100644 --- a/src/jp/dogrun/ileaflet/controller/login/RegisterController.java +++ b/src/jp/dogrun/ileaflet/controller/login/RegisterController.java @@ -1,11 +1,13 @@ package jp.dogrun.ileaflet.controller.login; +import jp.dogrun.ileaflet.controller.validator.login.RegisterValidators; import jp.dogrun.ileaflet.dao.ActorDao; import jp.dogrun.ileaflet.model.Actor; import jp.dogrun.ileaflet.util.ApplicationUtil; import org.slim3.controller.Controller; import org.slim3.controller.Navigation; +import org.slim3.controller.validator.Validators; import org.slim3.datastore.Datastore; import org.slim3.util.StringUtil; @@ -13,56 +15,44 @@ public class RegisterController extends Controller { @Override public Navigation run() throws Exception { - - Actor actor = createActor(); - if ( actor == null ) { + + if ( !validate() ) { return forward("./create.jsp"); } - + + Actor actor = createActor(); Datastore.put(actor); sessionScope(Actor.class.getName(),actor); return redirect("/dashboard/"); } - + + private boolean validate() { + RegisterValidators v = new RegisterValidators(request); + v.add("identity",v.required()); + v.add("name",v.required()); + v.add("mail",v.required()); + v.add("password",v.required(),v.samePassword()); + v.add("actor",v.sameUser()); + return v.validate(); + } + private Actor createActor() { + //入力チェック String identity = requestScope("identity"); String name = requestScope("name"); String mail = requestScope("mail"); String pass1 = requestScope("password"); - String pass2 = requestScope("password2"); - - if ( - StringUtil.isEmpty(identity) || - StringUtil.isEmpty(name) || - StringUtil.isEmpty(mail) || - StringUtil.isEmpty(pass1) - ) { - return null; - } - if ( !pass1.equals(pass2) ) { - return null; - } - - ActorDao dao = new ActorDao(); - Actor actor = dao.findById(identity); - if ( actor == null ) { - actor = dao.findByMail(mail); - } - if ( actor != null ) { - return null; - } - //ユーザを作成 - actor = new Actor(); + Actor actor = new Actor(); actor.setIdentity(identity); actor.setName(name); actor.setEmail(mail); String enPass = ApplicationUtil.changeMD5(identity + "-" + pass1); actor.setPassword(enPass); - + return actor; } diff --git a/src/jp/dogrun/ileaflet/controller/validator/login/RegisterValidators.java b/src/jp/dogrun/ileaflet/controller/validator/login/RegisterValidators.java new file mode 100644 index 0000000..c014897 --- /dev/null +++ b/src/jp/dogrun/ileaflet/controller/validator/login/RegisterValidators.java @@ -0,0 +1,28 @@ +package jp.dogrun.ileaflet.controller.validator.login; + +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.slim3.controller.validator.Validators; + +public class RegisterValidators extends Validators { + + public RegisterValidators(HttpServletRequest request) { + super(request); + } + + public RegisterValidators(Map parameters) + throws NullPointerException { + super(parameters); + } + + public SamePasswordValidator samePassword() { + return SamePasswordValidator.INSTANCE; + } + + public SameActorValidator sameUser() { + return SameActorValidator.INSTANCE; + } + +} diff --git a/src/jp/dogrun/ileaflet/controller/validator/login/SameActorValidator.java b/src/jp/dogrun/ileaflet/controller/validator/login/SameActorValidator.java new file mode 100644 index 0000000..9610f34 --- /dev/null +++ b/src/jp/dogrun/ileaflet/controller/validator/login/SameActorValidator.java @@ -0,0 +1,49 @@ +package jp.dogrun.ileaflet.controller.validator.login; + +import java.util.Map; + +import jp.dogrun.ileaflet.dao.ActorDao; +import jp.dogrun.ileaflet.model.Actor; + +import org.slim3.controller.validator.AbstractValidator; +import org.slim3.util.ApplicationMessage; + +public class SameActorValidator extends AbstractValidator { + + public static SameActorValidator INSTANCE = new SameActorValidator(); + public SameActorValidator() { + } + + public SameActorValidator(String message) { + super(message); + } + + public String validate(Map parameters, String name) { + String identity = (String)parameters.get("identity"); + String mail = (String)parameters.get("mail"); + + ActorDao dao = new ActorDao(); + Actor actor = dao.findById(identity); + if ( actor != null ) { + if (message != null) { + return message; + } + return ApplicationMessage.get("validator.sameIdentity", getLabel("identity")); + } + + actor = dao.findByMail(mail); + if ( actor != null ){ + if (message != null) { + return message; + } + return ApplicationMessage.get("validator.sameMail", getLabel("mail")); + } + return null; + } + + @Override + protected String getMessageKey() { + return "validator.sameActor"; + } + +} diff --git a/src/jp/dogrun/ileaflet/controller/validator/login/SamePasswordValidator.java b/src/jp/dogrun/ileaflet/controller/validator/login/SamePasswordValidator.java new file mode 100644 index 0000000..e8a78cb --- /dev/null +++ b/src/jp/dogrun/ileaflet/controller/validator/login/SamePasswordValidator.java @@ -0,0 +1,37 @@ +package jp.dogrun.ileaflet.controller.validator.login; + +import java.util.Map; + +import org.slim3.controller.validator.AbstractValidator; +import org.slim3.util.ApplicationMessage; + +public class SamePasswordValidator extends AbstractValidator { + + public static SamePasswordValidator INSTANCE = new SamePasswordValidator(); + public SamePasswordValidator() { + super(); + } + + public SamePasswordValidator(String message) { + super(message); + } + + public String validate(Map parameters, String name) { + Object value1 = parameters.get("password"); + Object value2 = parameters.get("password2"); + if ( value1 != null && + !value1.equals(value2) ) { + if (message != null) { + return message; + } + return ApplicationMessage.get(getMessageKey(), getLabel(name)); + } + return null; + } + + @Override + protected String getMessageKey() { + return "validator.samePassword"; + } + +} diff --git a/src/jp/dogrun/ileaflet/meta/ActorMeta.java b/src/jp/dogrun/ileaflet/meta/ActorMeta.java index faf4336..65ae6fb 100644 --- a/src/jp/dogrun/ileaflet/meta/ActorMeta.java +++ b/src/jp/dogrun/ileaflet/meta/ActorMeta.java @@ -1,6 +1,6 @@ package jp.dogrun.ileaflet.meta; -//@javax.annotation.Generated(value = { "slim3-gen", "@VERSION@" }, date = "2013-01-16 19:48:15") +//@javax.annotation.Generated(value = { "slim3-gen", "@VERSION@" }, date = "2013-01-17 18:00:55") /** */ public final class ActorMeta extends org.slim3.datastore.ModelMeta { diff --git a/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml b/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml index dda9bab..f57b476 100644 --- a/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml +++ b/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml @@ -1,4 +1,4 @@ - + diff --git a/war/WEB-INF/appengine-generated/local_db.bin b/war/WEB-INF/appengine-generated/local_db.bin index ddb5986e0f4ff296fd0ce958c13abe7ed4df5607..d69d761d9c1b274d9f9e1f562f4c0b5164e13de0 100644 GIT binary patch delta 1201 zcmbW0&rcIU6vt=wM|W$XiKP`$8ug-yCf$~{l!k*Ks3B>TM52e1lwo(QYqq;%ccJS= z{sIp$HxK#`aL{luF`hVjA@RbI#2+U)>4E4$W@aH4j4AOQ-tJ7_`@HwQZ~JCw>uhp; z7pNT_L^isbe4C8BUIP)*ur0q0rq|@m>W;DUt&{qdHKsNtAk~0|!vMR1{{%b(um<`c zE;-H|yPI(>=D~Q)^jb#K^O_De7zw*g+vRVzVW9x|f!D@{g_n(*XCmiTck*~h1QiIc zT%Qnq^>ye3OvKbllcmyGcv~;`y#pIBwtvu9Z~?+K>1Ixy0SS);w&xH$E=XT1Th8Y5t9z55BmhFf3aLwN9=`s4a4)9M?HpeJ(PN3{ z4${Z+G?eIjc|=Qx{3b(x$}f|tI#7eB0sV!I;PB*F6}OP>9B}w-B{7@H ztVcr%*S9NiOe8Kc>yfAvf*(6umQ^Nit2UCT(efP!Lksu&@z{T7>}tZBja^OCtKQNRWm%_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