Skip to content

Commit

Permalink
userName add
Browse files Browse the repository at this point in the history
  • Loading branch information
sickboy authored and sickboy committed Feb 11, 2013
1 parent f89b77a commit a21986a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
13 changes: 7 additions & 6 deletions src/jp/dogrun/ileaflet/controller/AppRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jp.dogrun.ileaflet.model.Actor;

import org.slim3.controller.router.RouterImpl;
import org.slim3.util.ByteUtil;

public class AppRouter extends RouterImpl {

Expand All @@ -28,14 +29,14 @@ public boolean isStatic(String path) throws NullPointerException {

@Override
public String route(HttpServletRequest request, String path) {
System.out.println("きとるよー");

HttpSession session = request.getSession();
if ( session != null ) {
//Actor actor = (Actor)session.getAttribute(Actor.class.getName());
//if ( actor != null ) {
//request.setAttribute("userName", actor.getName());
//}
Object actorObj = session.getAttribute(Actor.class.getName());
if ( actorObj != null ) {
byte[] bytes = ByteUtil.toByteArray(actorObj);
Actor actor = ByteUtil.toObject(bytes, getClass().getClassLoader());
request.setAttribute("userName", actor.getName());
}
}

if ( isFilter(path,"/dashboard") ) return path;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package jp.dogrun.ileaflet.controller.dashboard;

import jp.dogrun.ileaflet.model.Actor;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

public abstract class DashboardController extends Controller {

@Override
protected Navigation run() throws Exception {
// TODO Auto-generated method stub
return null;
Actor actor = getActor();
//ログイン状態を取得
if ( actor == null ) {
return redirect("../login/");
}
return process();
}

protected abstract Navigation process() throws Exception;

protected Actor getActor() {
return sessionScope(Actor.class.getName());
}

}
13 changes: 3 additions & 10 deletions src/jp/dogrun/ileaflet/controller/dashboard/IndexController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,18 @@
import jp.dogrun.ileaflet.model.Actor;
import jp.dogrun.ileaflet.model.Content;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

public class IndexController extends Controller {
public class IndexController extends DashboardController {

@Override
public Navigation run() throws Exception {
public Navigation process() throws Exception {

Actor actor = sessionScope(Actor.class.getName());
//ログイン状態を取得
if ( actor == null ) {
return redirect("../login/");
}

Actor actor = getActor();
ContentDao dao = new ContentDao();
List<Content> contentList =dao.findByIdentity(actor.getIdentity());

requestScope("contentList",contentList);

return forward("index.jsp");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import jp.dogrun.ileaflet.model.Actor;
import jp.dogrun.ileaflet.model.Content;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.controller.upload.FileItem;
import org.slim3.controller.validator.Validators;
Expand All @@ -21,10 +20,10 @@
import com.google.appengine.api.files.FileWriteChannel;
import com.google.appengine.api.files.GSFileOptions.GSFileOptionsBuilder;

public class UploadController extends Controller {
public class UploadController extends DashboardController {

@Override
public Navigation run() throws Exception {
public Navigation process() throws Exception {

if ( !validate() ) {
return forward("index.jsp");
Expand All @@ -34,13 +33,13 @@ public Navigation run() throws Exception {

EpubLogic logic = new EpubLogic();
byte[] epubData = fileItem.getData();

if ( !logic.isCheck(epubData) ) {
this.errors.put("errors", ApplicationMessage.get("message.epubCheck",ApplicationMessage.get("label.epubFile")));
//TODO メッセージ
return forward("index.jsp");
}
Actor actor = sessionScope(Actor.class.getName());

Actor actor = getActor();

//コンテンツデータを設定
Content content = new Content();
Expand Down Expand Up @@ -75,6 +74,7 @@ public Navigation run() throws Exception {
tx.rollback();
throw ex;
}

//TODO アップロードしました。
return redirect("/dashboard/");
}
Expand Down
11 changes: 10 additions & 1 deletion war/mainFrame.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@

<ul class="nav pull-right">

<li><a href="/login/">ログイン</a></li>
<li>
<c:if test="${empty userName}">
<a href="/login/">ログイン</a>
</c:if>
<c:if test="${not empty userName}">
<a href="/dashboard/">${userName}</a>
</c:if>
</li>
<c:if test="${not empty userName}">
<li><a href="/login/logout">ログアウト</a></li>
</c:if>
</ul>
</div>
</div>
Expand Down

0 comments on commit a21986a

Please sign in to comment.