文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Catalyst::Manual::Tutorial::05_Authentication

Catalyst::Manual::Tutorial::05_Authentication

时间:2010-08-23  来源:horsley

Catalyst::Manual::Tutorial::05_Authentication 学习笔记 (2010-08-23 星期一)     概述:   本章分成两部分:
  • 1) basic, cleartext authentication and
  • 2) hash-based authentication.
  基本身份验证:   在数据库中添加用户和角色   sql 脚本如下:  

--
-- Add user and role tables, along with a many-to-many join table
--
PRAGMA foreign_keys = ON;
CREATE TABLE user (
        id INTEGER PRIMARY KEY,
        username TEXT,
        password TEXT,
        email_address TEXT,
        first_name TEXT,
        last_name TEXT,
        active INTEGER
);
CREATE TABLE role (
        id INTEGER PRIMARY KEY,
        role TEXT
);
CREATE TABLE user_role (
        user_id INTEGER REFERENCES user(id) ON DELETE CASCADE ON UPDATE CASCADE,
        role_id INTEGER REFERENCES role(id) ON DELETE CASCADE ON UPDATE CASCADE,
        PRIMARY KEY (user_id, role_id)
);
--
-- Load up some initial test data
--
INSERT INTO user VALUES (1, 'test01', 'mypass', '[email protected]', 'Joe', 'Blow', 1);
INSERT INTO user VALUES (2, 'test02', 'mypass', '[email protected]', 'Jane', 'Doe', 1);
INSERT INTO user VALUES (3, 'test03', 'mypass', '[email protected]', 'No', 'Go', 0);
INSERT INTO role VALUES (1, 'user');
INSERT INTO role VALUES (2, 'admin');
INSERT INTO user_role VALUES (1, 1);
INSERT INTO user_role VALUES (1, 2);
INSERT INTO user_role VALUES (2, 1);
INSERT INTO user_role VALUES (3, 1);

执行脚本

$ sqlite3 myapp.db < myapp02.sql


Add User and Role Information to DBIC Schema

$ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema \
    create=static components=TimeStamp dbi:SQLite:myapp.db \
    on_connect_do="PRAGMA foreign_keys = ON"
 exists "/root/dev/MyApp/script/../lib/MyApp/Model"
 exists "/root/dev/MyApp/script/../t"
Dumping manual schema for MyApp::Schema to directory /root/dev/MyApp/script/../lib ...
Schema dump completed.
 exists "/root/dev/MyApp/script/../lib/MyApp/Model/DB.pm"
$
$ ls lib/MyApp/Schema/Result
Author.pm BookAuthor.pm Book.pm Role.pm User.pm UserRole.pmx


运行后 lib/MyApp/Schema/Result  目录下新增三个表,已经自动生成了 has_many ,belongs_to 关系。我们需要手工添加  many_to_many 关系(参考第三章)。

这里我们编辑 lib/MyApp/Schema/Result/User.pm :

# many_to_many():
# args:
# 1) Name of relationship, DBIC will create accessor with this name
# 2) Name of has_many() relationship this many_to_many() is shortcut for
# 3) Name of belongs_to() relationship in model class of has_many() above
# You must already have the has_many() defined to use a many_to_many().
__PACKAGE__->many_to_many(roles => 'user_roles', 'role');


相关阅读 更多 +
排行榜 更多 +
翌日波奇狗的历险记手机版下载

翌日波奇狗的历险记手机版下载

休闲益智 下载
怪兽远征安卓版下载

怪兽远征安卓版下载

角色扮演 下载
谷歌卫星地图免费版下载

谷歌卫星地图免费版下载

生活实用 下载