From e536f4b4e06ef1ee62f8cca971cfc2916badd9a8 Mon Sep 17 00:00:00 2001 From: "OHASHI, Norikazu" Date: Sat, 13 Apr 2019 22:32:02 +0900 Subject: [PATCH] =?utf8?q?=E4=BE=8B=E5=A4=96=E3=81=AE=E4=BF=AE=E6=AD=A3?= =?utf8?q?=E3=81=8A=E3=82=88=E3=81=B3=E3=80=81=E3=83=86=E3=83=BC=E3=83=96?= =?utf8?q?=E3=83=AB=E8=A8=AD=E8=A8=88=E3=81=AE=E8=A8=98=E8=BF=B0=E8=BF=BD?= =?utf8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++ readme.md | 61 +++++++++++++++++++++++------- sinatra/app/controllers/web_gui.rb | 2 +- sinatra/app/models/users_db.rb | 20 +++++----- 4 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..47b948f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.yardoc/ +/doc/ +.markdown-preview.html diff --git a/readme.md b/readme.md index d28c8e5..c0d9691 100644 --- a/readme.md +++ b/readme.md @@ -21,18 +21,53 @@ database.yml # dtabase config users_db.rb # access to users table books_db.rb # access to book table - views/ - layout.erb # layout of html view - main.erb # start up view - signup.erb # sign up user view - login.erb # user login view - logout.erb # user logout view - user_home.erb # user default home view - account.erb # setup account view - list.erb # list of books view - search.erb # search books view - detail.erb # detail of book parameter view - find_isbn.erb # search books parameter with isbn view - setup.erb # setup book parameter view + views/ # views + layout.haml # layout of html view + main.haml # start up view + signup.haml # sign up user view + login.haml # user login view + logout.haml # user logout view + user_home.haml # user default home view + account.haml # setup account view + list.haml # list of books view + search.haml # search books view + detail.haml # detail of book parameter view + find_isbn.haml # search books parameter with isbn view + setup.haml # setup book parameter view ``` +## テーブル設計 + +### ユーザ管理テーブル (users) + +| 項番 | カラム名 | 型 | 属性 | 概要 | +| --: | --- | --- | --- | --- | +| 1 | user_id | INTEGER | NOT NULL, AUTO_INCREMENT, PRIMARY KEY | ユーザID | +| 2 | user_name | VARCHAR(10) | NOT NULL, UNIQUE | ユーザ名 | +| 3 | full_name | VARCHAR(127) | | ユーザフルネーム | +| 4 | passwd_hash | VARCHA(60) | NOT NULL | パスワードハッシュ | +| 5 | passwd_salt | VARCHA(60) | NOT NULL | パスワードSALT | +| 6 | email | VARCHAR(127) | NOT NULL | Eメールアドレス | +| 7 | role | INTEGER | NOT NULL | 権限 | +| 8 | create_at | DATETIME | NOT NULL | 登録日時 | +| 9 | update_at | DATETIME | NOT NULL | 更新日時 | + +### 書籍管理テーブル (books) + +| 項番 | カラム名 | 型 | 属性 | 概要 | +| --: | --- | --- | --- | --- | +| 1 | isbn | VARCHAR(14) | NOT NULL | ISBNコード | +| 2 | title | VARCHAR(255) | NOT NULL | 書名 | +| 3 | volume | INTEGER | | 巻数 | +| 4 | author | VARCHAR(127) | | 著者名 | +| 5 | orignal_author | VARCHAR(127) | | 原著者 | +| 6 | translator | VARCHAR(127) | | 翻訳者 | +| 7 | publisher | VARCHAR(127) | | 出版社 | +| 8 | summary | VARCHAR(511) | | 概要 | +| 9 | book_shadow | BLOB | | 書影 | +| 10 | user_id | INTEGER | NOT NULL | ユーザID | +| 11 | rank | INTEGER | | 評価 +| 12 | creat_at | DATETIME | NOT NULL | 登録日時 | +| 13 | update_at | DATETIME | NOT NULL | 更新日時 | + +注: isdn + user_id で複合キーとする。 diff --git a/sinatra/app/controllers/web_gui.rb b/sinatra/app/controllers/web_gui.rb index fadc6a3..f170ec9 100644 --- a/sinatra/app/controllers/web_gui.rb +++ b/sinatra/app/controllers/web_gui.rb @@ -92,7 +92,7 @@ class WebGui < Sinatra::Base id = UserAccount.checkPasswd(name, passwd); session[:userId] = id; redirect "/user_home" - rescue UserAccount::NotfondInstanceError, + rescue UserAccount::NotfoundInstanceError, UserAccount::AuthenticationError raise WebError.new(401), "認証に失敗しました アカウント、 パスワードを確認してください。" diff --git a/sinatra/app/models/users_db.rb b/sinatra/app/models/users_db.rb index 784116e..0a997ed 100644 --- a/sinatra/app/models/users_db.rb +++ b/sinatra/app/models/users_db.rb @@ -19,19 +19,19 @@ end class UserAccount # ユーザロール - ROLE_AUTH = 0 #管理者権限 + ROLE_ADMIN = 0 #管理者権限 ROLE_NORMAL = 8 #一般権限 - # 認証エラー + # ユーザ認証エラー class AuthenticationError < SecurityError end - # すでに存在している + # 対象のユーザがすでに存在している class AlreadyInstanceError < StandardError end - # 存在していない - class NotfondInstanceError < StandardError + # 対象のユーザが存在していない + class NotFoundInstanceError < StandardError end # DBアクセス失敗 @@ -78,14 +78,14 @@ class UserAccount # @param [String] name ユーザ名 # @param [String] passwd パスワード # @return [Integer] 認証されたユーザID - # @raise [NotfoundInstanceError] ユーザ情報の取得に失敗 - # @raise [AutenticationError] 認証失敗 + # @raise [NotFoundInstanceError] ユーザ情報の取得に失敗 + # @raise [AuthenticationError] 認証失敗 def self.checkPasswd(name, passwd) user = User.find_by(user_name: name) # ユーザの有無をチェック if (user == nil) - raise NotfondInstanceError + raise NotFoundInstanceError end # パスワードハッシュを取得 @@ -102,11 +102,11 @@ class UserAccount # ユーザ情報取得 # @param [Integer] id 対象ユーザID # @return [User] ユーザ情報 - # @raise [NotfoundInstanceError] ユーザ情報の取得に失敗 + # @raise [NotFoundInstanceError] ユーザ情報の取得に失敗 def self.getUser(id) user = User.find_by(user_id: id) if (user == nil) - raise NotfondInstanceError + raise NotFoundInstanceError end return user end -- 2.19.2