Myページ
ホーム
コミュニティの人々
ソフトウェア
技術紹介
適用分野
Tyzohとは
ご意見お問い合わせ

V.S.A. III

[Secure-SBM:009] データベース管理処理 (2)

こんにちは,五十嵐です.前回は管理のトップページを作成しました.今回は実際の処理に入っていきます.

その前に,エラー画面がそのままでしたし,ページにはタイトルが付いていません.このふたつをやっつけてしまいましょう.default 処理用に default.tt を用意し,今まで作成した三つの処理 default, index, Admin でそれぞれページのタイトルが付けられるようにします.

まず,derault.tt
[% INCLUDE top.tt %]
<div class="left" id="left">[% INCLUDE index_left.tt %]
</div><!-- end of left -->
<div class="center" id="center">
[% IF error_message %][% error_message %][% END %]
</div><!-- end of center -->
<div class="right" id="right">[% INCLUDE index_right.tt %]
</div><!-- end of right -->
[% INCLUDE bottom.tt %]

[%#
This Program is distributed under version 1.0 of the Rinza Public
License Agreement, that is bundled with this package in the file
LICENSE, and is available through the website at the following URL:
http://www.tyzoh.jp/rinza/licenses/LICENSE-1.0.txt.

This is the Original Program.
The Initial Developer of the Original Program is Nihon Unisys, Ltd.
The Original Program is copyrighted (C) 2006-2007 by Nihon Unisys, Ltd. with
all rights reserved.
There is NO WARRANTY OF ANY KIND by the Initial Developer of the
Original Program.
%]

center ブロックにファイルを読み込むのではなく,default アクションで指定する error_messsage を出力するようにしました.

 

root/template/top.tt の の間に以下を挿入.
[% IF pagetitle -%]
<title>[% pagetitle %]</title>
[% END -%]
各アクションで pagetitle を指定できるようにしました.

lib/SecureSBM.pm
--- lib/SecureSBM.pm
+++ lib/SecureSBM.pm
@@ -56,8 +56,10 @@
 sub default : Private {
     my ( $self, $c ) = @_;
 
-    # Hello World
-    $c->response->body( '要求されたページは存在しません.' );
+       $c->stash->{pagetitle} = "Secure-SBM Error Page";
+       $c->stash->{error_message}
+               = "<h1>Error</h1><span style='color:#ff0000'>
+                       要求されたページは存在しません.</span>";
 }
 
 #
"$c->stash->{pagetitle} でタイトルを設定し,エラーメッセージを設定して"$c->stash->{error_message}" の内容を出力させます.

lib/SecureSBM/Controller/Admin.pm
--- lib/SecureSBM/Controller/Admin.pm
+++ lib/SecureSBM/Controller/Admin.pm
@@ -29,6 +29,7 @@
 sub index : Private {
        my ( $self, $c ) = @_;
 
+       $c->stash->{pagetitle} = "Secure-SBM Admin Page";
        $c->stash->{template} = 'admin.tt';
 }
 

lib/SecureSBM/Controller/Root.pm
--- lib/SecureSBM/Controller/Root.pm
+++ lib/SecureSBM/Controller/Root.pm
@@ -27,8 +27,12 @@
 Index of SecureSBM
 
 =cut
-sub index : Private { }
+sub index : Private {
+       my ( $self, $c ) = @_;
 
+       $c->stash->{pagetitle} = "Secure-SBM Top Page";
+}
+
 =head2 end
 
 Attempt to render a view, if needed.

これで,各ページにページタイトルが表示されるようになりました.

さて,ユーザのリストの表示を作成します.データベースのスキーマが設定されていますので,アクション側の設定は非常に簡単です.lib/SecureSBM/Controller
sub listusers : Local {
       my ( $self, $c ) = @_;

       $c->stash->{pagetitle} = "Secure-SBM Admin User List";
       $c->stash->{users} = [$c->model('SecureSBMDB::User')->all];
       $c->stash->{template} = 'admin/listusers.tt';
}

これだけで,テンプレート側で users としてテーブルを参照することができます.管理用ですので,無条件で全てのユーザを閲覧します.root/template/admin/listusers.tt のポイントは以下のようになります.
<table>
<tr><th></th><th></th><th>ID</th><th>Email (login 名)</th>
   <th>姓</th><th>名</th></tr>
[% FOREACH user_v IN users -%]
<tr><td>
   <button id="edituser_button[% user_v.user_id  %]">編集</button></td>
        <td><button id="deleteuser_button[% user_v.user_id %]">
                     削除</button></td>
        <td align="right">[% user_v.user_id %]</td>
        <td>[% user_v.user_email %]</td>
        <td>[% user_v.user_surname %]</td><td>[% user_v.user_name %]</td>
</tr>
...
(省略)
[% END -%]

これで,コントロール側で "users" に設定した内容がすべて表示されます.この段階では,"admin" だけ登録されていますので,一件しか表示されません.

簡単に説明しておきます."[% FOREACH 変数 IN ハッシュ %]...[% END %]" で,変数に順番にハッシュの中身が与えられます.この場合は,listusers アクションで設定した users にテーブルが入っていますので,変数 user_v に入れながら,処理を行っていきます.テーブルのそれぞれのカラムは user_v.user_email といった具合に指定します.これだけで一覧ができてしまいます.

どのような SQL が発行されているのか気になります.そこで,次のような環境変数を設定して server.pl を実行すると,select 文などが見えるようになります.
$ export DBIC_TRACE=1

私は,こんな風に実行しています.
$ env DBIC_TRACE=1 ./script/securesbm_server.pl -r

これで admin/listusers にアクセスすると,以下のようなデバッグメッセージが見えます."-r" オプションは,ファイルに変更があると自動的に再起動してくれる便利なオプションです.
SELECT me.user_id, me.user_email, me.user_password, me.user_name, 
me.user_surname FROM users me: 
[info] *** Request 1 (0.011/s) [27860] [Thu Mar 22 11:09:52 2007] ***
[debug] "GET" request for "admin/listusers" from "127.0.0.1"
(以下略)


またしても長くなってしまいましたので,次回に続きます.次回は,registuser に挑戦です.

2007/03/21 記


参考:



Keyword: Perl Catalyst Secure-SBM SSBM セキュア・ソーシャル・ブックマーク

 

カテゴリ:SBM , 開発日記

タグ:

いかちょー (2007-05-30 21:48) | コメント(0)| トラックバック(1)

トラックバック(1)

トラックバックURL:

Cheap soma watson. - Buy cheap soma. (2010年11月 9日 04:19)

Buy cheap soma. Cheap soma. 続きを読む

コメント

コメントを投稿

名前

電子メール

URL

ログイン情報を記憶

コメント

プロフィール

いかちょー

いかちょーこと五十嵐智です。
情報セキュリティ分野に興味があります。
一応、CISSP ホルダー。

SF者です。どうぞよろしく。

プロフィール詳細 (Google プロフィール)

RSSフィード

コミュニティの人々 | ソフトウェア | 技術紹介 | 適用分野 | Tyzohとは | ご意見お問い合わせ

Copyright (C) 2004-2011 Nihon Unisys, Ltd. All Rights Reserved.
Powered by Movable Type Open Source