-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ff7a83
commit 437e492
Showing
15 changed files
with
267 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
package jp.dogrun.ileaflet.controller.login; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.util.Date; | ||
import java.util.Properties; | ||
import java.util.Random; | ||
|
||
import javax.mail.Message; | ||
import javax.mail.MessagingException; | ||
import javax.mail.Session; | ||
import javax.mail.Transport; | ||
import javax.mail.internet.InternetAddress; | ||
import javax.mail.internet.MimeMessage; | ||
|
||
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; | ||
|
||
import com.google.appengine.api.datastore.Transaction; | ||
|
||
public class RegisterController extends Controller { | ||
|
||
|
@@ -21,22 +33,43 @@ public Navigation run() throws Exception { | |
} | ||
|
||
Actor actor = createActor(); | ||
Datastore.put(actor); | ||
sessionScope(Actor.class.getName(),actor); | ||
return redirect("/dashboard/"); | ||
|
||
Transaction tx = Datastore.beginTransaction(); | ||
try { | ||
String serverUrl = ApplicationUtil.getHost(request); | ||
String registUrl = serverUrl + "/login/registration?registerCode=" + actor.getKeyword(); | ||
//メールを送信する | ||
sendRegistMail(actor.getName(),actor.getEmail(),registUrl); | ||
Datastore.put(actor); | ||
tx.commit(); | ||
} catch ( Exception ex ) { | ||
tx.rollback(); | ||
throw ex; | ||
} | ||
//TODO メールを送信しましたメッセージ | ||
return forward("../index.jsp"); | ||
} | ||
|
||
private boolean validate() { | ||
RegisterValidators v = new RegisterValidators(request); | ||
v.add("identity",v.required()); | ||
v.add("identity",v.required(),v.keyword()); | ||
v.add("name",v.required()); | ||
v.add("mail",v.required()); | ||
v.add("mail",v.required(),v.regexp("[\\w\\.\\-]+@(?:[\\w\\-]+\\.)+[\\w\\-]+")); | ||
v.add("password",v.required(),v.samePassword()); | ||
v.add("actor",v.sameUser()); | ||
return v.validate(); | ||
} | ||
|
||
private Actor createActor() { | ||
|
||
String keyword = null; | ||
while (true) { | ||
keyword = createKeyword(); | ||
System.out.println(keyword); | ||
ActorDao dao = new ActorDao(); | ||
Actor actor = dao.findByKeyword(keyword); | ||
if ( actor == null ) break; | ||
} | ||
|
||
//入力チェック | ||
String identity = requestScope("identity"); | ||
|
@@ -50,10 +83,35 @@ private Actor createActor() { | |
actor.setName(name); | ||
actor.setEmail(mail); | ||
|
||
String enPass = ApplicationUtil.changeMD5(identity + "-" + pass1); | ||
String enPass = ApplicationUtil.changeMD5(pass1); | ||
actor.setPassword(enPass); | ||
actor.setPurchase(null); | ||
actor.setKeyword(keyword); | ||
|
||
return actor; | ||
} | ||
|
||
private String createKeyword() { | ||
Random r = new Random(); | ||
r.setSeed((new Date()).getTime()); | ||
double xxx = r.nextDouble(); | ||
return ApplicationUtil.changeMD5(String.valueOf(xxx)); | ||
} | ||
|
||
public void sendRegistMail(String name,String email,String url) throws MessagingException, UnsupportedEncodingException { | ||
|
||
InternetAddress ToAddress = new InternetAddress(email,name, "ISO-2022-JP"); | ||
InternetAddress FromAddress = new InternetAddress("[email protected]", "iLeaflet管理者", "ISO-2022-JP"); | ||
|
||
Properties props = new Properties(); | ||
Session session = Session.getDefaultInstance(props, null); | ||
MimeMessage message = new MimeMessage(session); | ||
message.setFrom(FromAddress); | ||
message.addRecipient(Message.RecipientType.TO, ToAddress); | ||
message.setSubject("iLeaflet仮登録のお知らせ", "ISO-2022-JP"); | ||
|
||
message.setText(url); | ||
Transport.send(message); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/jp/dogrun/ileaflet/controller/login/RegistrationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package jp.dogrun.ileaflet.controller.login; | ||
|
||
import jp.dogrun.ileaflet.dao.ActorDao; | ||
import jp.dogrun.ileaflet.model.Actor; | ||
|
||
import org.slim3.controller.Controller; | ||
import org.slim3.controller.Navigation; | ||
import org.slim3.datastore.Datastore; | ||
|
||
public class RegistrationController extends Controller { | ||
|
||
@Override | ||
public Navigation run() throws Exception { | ||
|
||
String code = requestScope("registerCode"); | ||
ActorDao dao = new ActorDao(); | ||
Actor actor = dao.findByKeyword(code); | ||
if ( actor == null ) { | ||
//TODO 存在しないメッセージ | ||
return forward("index.jsp"); | ||
} | ||
if ( actor.getPurchase() != null ) { | ||
//TODO 既に登録済メッセージ | ||
return forward("index.jsp"); | ||
} | ||
|
||
actor.setPurchase(0); | ||
Datastore.put(actor); | ||
|
||
//セッションに設定する | ||
sessionScope(Actor.class.getName(),actor); | ||
return redirect("/dashboard/"); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/jp/dogrun/ileaflet/controller/validator/login/KeywordValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 org.slim3.controller.validator.AbstractValidator; | ||
import org.slim3.util.ApplicationMessage; | ||
import org.slim3.util.StringUtil; | ||
|
||
public class KeywordValidator extends AbstractValidator { | ||
|
||
public static KeywordValidator INSTANCE = new KeywordValidator(); | ||
public KeywordValidator() { | ||
super(); | ||
} | ||
|
||
public KeywordValidator(String message) { | ||
super(message); | ||
} | ||
|
||
public String validate(Map<String, Object> parameters, String name) { | ||
String value = (String)parameters.get(name); | ||
if ( isKeyword(value) ) { | ||
if (message != null) { | ||
return message; | ||
} | ||
return ApplicationMessage.get(getMessageKey(), getLabel(name)); | ||
} | ||
return null; | ||
} | ||
|
||
private boolean isKeyword(String value) { | ||
if ( StringUtil.isEmpty(value)) return false; | ||
if( | ||
value.equals("dashboard") || | ||
value.equals("dashboard") || | ||
value.equals("dashboard") | ||
) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
protected String getMessageKey() { | ||
return "validator.keyword"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.