Skip to content

Commit

Permalink
入力チェックの作成とメッセージ部分の作成
Browse files Browse the repository at this point in the history
  • Loading branch information
secondarykey committed Jan 17, 2013
1 parent f385fe6 commit 5ff7a83
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 34 deletions.
11 changes: 10 additions & 1 deletion resources/application_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
50 changes: 20 additions & 30 deletions src/jp/dogrun/ileaflet/controller/login/RegisterController.java
Original file line number Diff line number Diff line change
@@ -1,68 +1,58 @@
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;

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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Object> parameters)
throws NullPointerException {
super(parameters);
}

public SamePasswordValidator samePassword() {
return SamePasswordValidator.INSTANCE;
}

public SameActorValidator sameUser() {
return SameActorValidator.INSTANCE;
}

}
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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";
}

}
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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";
}

}
2 changes: 1 addition & 1 deletion src/jp/dogrun/ileaflet/meta/ActorMeta.java
Original file line number Diff line number Diff line change
@@ -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<jp.dogrun.ileaflet.model.Actor> {

Expand Down
2 changes: 1 addition & 1 deletion war/WEB-INF/appengine-generated/datastore-indexes-auto.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Indices written at Sat, 30 May 2009 05:54:22 UTC -->
<!-- Indices written at Thu, 17 Jan 2013 10:03:34 UTC -->

<datastore-indexes/>

Binary file modified war/WEB-INF/appengine-generated/local_db.bin
Binary file not shown.
11 changes: 10 additions & 1 deletion war/WEB-INF/classes/application_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
7 changes: 7 additions & 0 deletions war/mainFrame.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@

<div id="mainMenu">
${param.mainMenu}
<c:if test="${not empty errors}">
<ul>
<c:forEach var="e" items="${f:errors()}">
<li><span class="error">${f:h(e)}</span></li>
</c:forEach>
</ul>
</c:if>
</div>
</div>

Expand Down

0 comments on commit 5ff7a83

Please sign in to comment.