ボタン系の整理と画面ID対応
authorOHASHI, Norikazu <katz@neko-mori.sakura.ne.jp>
Sun, 28 Apr 2019 09:36:32 +0000 (18:36 +0900)
committerOHASHI, Norikazu <katz@neko-mori.sakura.ne.jp>
Sun, 28 Apr 2019 09:36:32 +0000 (18:36 +0900)
13 files changed:
create_table.sql
readme.md
sinatra/app/controllers/web_gui.rb
sinatra/app/models/users_db.rb
sinatra/app/views/error.haml
sinatra/app/views/login.haml
sinatra/app/views/logout.haml
sinatra/app/views/main.haml
sinatra/app/views/scss/style.scss
sinatra/app/views/signup.haml
sinatra/app/views/user_edit.haml
sinatra/app/views/user_home.haml
sinatra/create_admin.rb [new file with mode: 0644]

index 2a56326..d0c60f5 100644 (file)
@@ -8,3 +8,35 @@ CREATE TABLE users (
        user_role INTEGER NOT NULL,
        create_at DATETIME NOT NULL,
        update_at DATETIME NOT NULL);
+
+CREATE TABLE books (
+       isbn VARCHAR(14) NOT NULL PRIMARY KEY,
+       title VARCHAR(255) NOT NULL,
+       volume INTEGER,
+       series VARCHAR(255),
+       author VARCHAR(127),
+       orignal_author VARCHAR(127),
+       translator VARCHAR(127),
+       supervisor VARCHAR(127),
+       publisher VARCHAR(127),
+       pubdate DATE,
+       cover TEXT,
+       create_at DATETIME NOT NULL,
+       update_at DATETIME NOT NULL);
+       
+CREATE TABLE book_collections (
+       isbn VARCHAR(14) NOT NULL,
+       user_id INTEGER NOT NULL,
+       summary TEXT,
+       rank INTEGER,
+       create_at DATETIME NOT NULL,
+       update_at DATETIME NOT NULL
+       PRIMARY KEY(isbn, user_id));
+       
+CREATE TABLE book_covers (
+       key_hash VARCHAR(60) NOT NULL PRIMARY KEY,
+       isbn VARCHAR(14) NOT NULL UNIQUE,
+       mime_type VARCHAR(255) NOT NULL,
+       shadow LONGBLOB NOT NULL,
+       create_at DATETIME NOT NULL,
+       update_at DATETIME NOT NULL);
index bdc5b0b..6c32561 100644 (file)
--- a/readme.md
+++ b/readme.md
 |  1 | isbn | VARCHAR(14) | NOT NULL, PRIMARY KEY | 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 | book_shadow | TEXT | | 書影(URL) |
-|  9 | creat_at | DATETIME | NOT NULL | 登録日時 |
-| 10 | update_at | DATETIME | NOT NULL | 更新日時 |
+|  4 | series | VARCHAR(255) | | シリーズ名 |
+|  5 | author | VARCHAR(127) | | 著者名 |
+|  6 | orignal_author | VARCHAR(127) | | 原著者 |
+|  7 | translator | VARCHAR(127) | | 翻訳者 |
+|  8 | supervisor | VARCHAR(127) | | 監修者 |
+|  9 | publisher | VARCHAR(127) | | 出版社 |
+| 10 | pubdate | DATE | | 出版日 |
+| 11 | cover | TEXT | | 書影(URL) |
+| 12 | creat_at | DATETIME | NOT NULL | 登録日時 |
+| 13 | update_at | DATETIME | NOT NULL | 更新日時 |
 
 ### 蔵書管理テーブル (book\_collections)
 | 項番 | カラム名 | 型 | 属性 | 概要 |
@@ -79,7 +82,7 @@
 注: isdn + user_id で複合キーとする。
 
 
-### 書影管理テーブル (book\_shadows)
+### 書影管理テーブル (book\_covers)
 | 項番 | カラム名 | 型 | 属性 | 概要 |
 | --: | --- | --- | --- | --- |
 |  1 | key_hash | VARCHAR(60) | NOT NULL, PRIMARY KEY | SHA125 HASH (アクセスキー) |
 |  6 | update_at | DATETIME | NOT NULL | 更新日時 |
 
 注: 画像をロードした場合の管理用
+
+### NewsReleaseテーブル (news\_Relases)
+| 項番 | カラム名 | 型 | 属性 | 概要 |
+| --: | --- | --- | --- | --- |
+|  1 | id | INTAGER | NOT NULL, AUTO_INCREMENT, PRIMARY KEY | ReleaseId |
+|  2 | message | TEXT | NOT NULL | メッセージ |
+|  3 | creat_at | DATETIME | NOT NULL | 登録日時 |
+|  4 | update_at | DATETIME | NOT NULL | 更新日時 |
+
+## 使用RestAPI
+### openBD
+
+#### 参照URI
+[openBD](https://openbd.jp)
+
+#### API仕様
+ * 書誌情報取得:
+   /get?isbn=ISBN,ISBN
+ * 収録範囲の取得:
+   /coverage
+ * JSONスキーマの取得:
+   /schema
index f064e82..3f52c76 100644 (file)
@@ -22,6 +22,15 @@ class WebGui < Sinatra::Base
       @params = params
     end
   end
+
+  helpers do
+    # ページIDを保存して、viewに渡す
+    # @params [Simbole] pageId 表示するページID 
+    def goPage(pageId)
+      @pageId = pageId
+      haml pageId
+    end
+  end
   
   set :root, File.join(File.dirname(__FILE__), '..')
   set :views, Proc.new {File.join(root, "views")}
@@ -40,12 +49,12 @@ class WebGui < Sinatra::Base
   
   # メインページ
   get '/' do
-    haml :main
+    goPage :main
   end
 
   # サインアップページ
   get '/signup' do
-    haml :signup
+    goPage :signup
   end
 
   # サインアップページ(POST)
@@ -72,7 +81,7 @@ class WebGui < Sinatra::Base
 
   # ログインページ
   get '/login' do
-    haml :login
+    goPage :login
   end
 
   # ログインページ(POST)
@@ -106,7 +115,7 @@ class WebGui < Sinatra::Base
     @username = user.full_name
     @is_addmin = user.isAddmin
     @newest_list = [ "書籍1", "書籍2", "書籍3"]
-    haml :user_home
+    goPage :user_home
   end
 
   # ユーザ情報編集ページ
@@ -119,6 +128,7 @@ class WebGui < Sinatra::Base
     end
     begin
       user = UserAccount.getUser(id)
+      @admin_f = false
       @id = id
       @username = user.full_name
       @account = user.user_name
@@ -126,7 +136,7 @@ class WebGui < Sinatra::Base
     rescue UserAccount::NotFoundInstanceError
       raise WebError.new(status: 400, message: "該当するユーザが存在しません。")
     end
-    haml :user_edit
+    goPage :user_edit
   end
 
   # ユーザ情報編集ページ(POST)
@@ -166,7 +176,7 @@ class WebGui < Sinatra::Base
   # ログアウトページ
   get '/logout' do
     # 最終ログイン情報登録
-    haml :logout
+    goPage :logout
   end
 
   # エラーページ
index d9c45fd..0b7a80c 100644 (file)
@@ -69,7 +69,17 @@ class UserAccount
     return user.isAddmin()
   end
 
-  private_class_method :checkAdmin
+  # SALT と Password Hash を生成する
+  # @param [String] passwd パスワード
+  # @return [String, String] SALT, パスワードハッシュ
+  def self.makeHash(passwd) 
+    passwd_salt = BCrypt::Engine.generate_salt
+    passwd_hash = BCrypt::Engine.hash_secret(passwd, passwd_salt)
+
+    return passwd_salt, passwd_hash
+  end
+  
+  private_class_method :checkAdmin, :makeHash
     
   # ユーザアカウントを作成
   # @param [String] name ユーザ名
@@ -87,8 +97,7 @@ class UserAccount
     end
 
     # パスワードのハッシュ化
-    passwd_salt = BCrypt::Engine.generate_salt
-    passwd_hash = BCrypt::Engine.hash_secret(passwd, passwd_salt)
+    passwd_salt, passwd_hash = makeHash(passwd)
 
     # ユーザデータの登録
     user = User.new
@@ -172,7 +181,7 @@ class UserAccount
       end
       if (key == :passwd)
         # パスワード更新
-        user.passwd_hash = BCrypt::Engine.hash_secret(value, user.passwd_salt)
+        user.passwd_salt, user.passwd_hash = makeHash(value)
         change_f = true
       else
         if (value != user.send(key))
index 907acc0..74299e8 100644 (file)
@@ -6,11 +6,8 @@
     エラーが発生しました。
   %p= error_message
     
-  .buttoms
-    .buttoms__push
-      - if refs == nil
-        %a{ :href => '/'}
-          メインにもどる
-      - else
-        %a{ :href => refs}
-          もどる
+  .buttons
+    - if refs == nil
+      %input{ :type => 'button', :class=>'push_button', :onclick => "location.href='/'", :value => 'メインにもどる'}
+    - else
+      %input{ :type => 'button', :class=>'push_button', :onclick => "location.href='#{refs}'", :value => 'もどる'}
index 2a4c72f..05b92cb 100644 (file)
@@ -18,9 +18,9 @@
           %span
             パスワード:
         %input{ :name => 'passwd', :type => 'password', :id => 'passwd', :pattern => '.{6,}',  :required => true}
-  %hr
   
   .buttons
-    %input{ :type => 'submit', :value => '送信'}
-    %input{ :type => 'button', :onclick =>"location.href='/'", :value => 'もどる' }
+    %hr
+    %input{ :type => 'submit', :class=>"push_button", :value => '送信'}
+    %input{ :type => 'button', :class=>"push_button", :onclick =>"location.href='/'", :value => 'もどる' }
   
index d99db8f..64a16e7 100644 (file)
@@ -2,8 +2,7 @@
 %h2
   おつかれさまでした。
 
-.buttoms
-  .buttoms__push
-    %a{ :href => '/'}
-      メインにもどる
+.buttons
+  %input{ :type => 'button', :class=>"push_button", :onclick =>"location.href='/'", :value => 'メインにもどる' }
+      
 
index 9a3e0dc..172656d 100644 (file)
@@ -1,13 +1,11 @@
 - # encoding: utf-8
 
 %h1
-  蔵書管理 Web v0.01
+  □■□■ 蔵書管理 Web v0.01 ■□■□
 
-.buttoms
-  .buttoms__push
-    %a{ :href => '/signup' }
-      サインアップ
+%h3
+  重ね買いを防ぐために…
   
-  .buttoms__push
-    %a{ :href => '/login' }
-      ログイン
+.buttons
+  %input{ :type => 'button', :class=>"push_button", :onclick =>"location.href='/signup'", :value => 'サインアップ' }
+  %input{ :type => 'button', :class=>"push_button", :onclick =>"location.href='/login'", :value => 'ログイン' }
index aaa3eca..54c9e4f 100644 (file)
@@ -1,23 +1,49 @@
+@charset "utf-8";
+
 body {
     color:#444;
-    margin:auto;
-    max-width:45em;
+    align-items: center;
+    text-align: center;
+    margin: 10px auto;
+    max-width:50em;
+}
+
+h1 {
+    font-size: 3em;
 }
 
 ul {
     text-align: left;
 }
 
+input.push_button{
+    font-size: 1em;
+    padding: 5px,20px;
+    width: 200px;
+    height: 25px;
+    background-color: #f08300;
+    color: #3e62ad;
+    border: 1px solid #000000;
+    margin-left: 20px;
+    &:hover {
+        background-color:#f6ad49;
+        color: #3e62ad;
+    }
+}
+
 #main1 {
+    position: relative;
     background: #f8e58c;
     align-items: center;
     text-align: center;
+    height: 20em;
+    padding: 20px 5px;
 }
 
 #head {
-    height: 50px;
     background: #a8c97f;
     text-align: center;
+    padding: 5px 5px;
 }
 
 #center {
@@ -35,33 +61,21 @@ ul {
 }
 
 #main2 {
+    position: relative;
     float: right;
     width: 80%;
     background: #f8e58c;
+    align-items: center;
     text-align: center;
-    padding-bottom: 3267px;
-    margin-bottom: -3267px;
+    height: 32em;
+    padding: 5px 0px;
 }
 
 #foot {
-    height: 50px;
     background: #a8c97f;
+    padding: 5px 5px;
 }
 
-.buttoms {
-    display: flex;
-    flex-direction: row;
-    justify-content: center;
-    &__push {
-        margin: 20px;
-        height: 20px;
-        width: 200px;
-        background: #f08300;
-        foreground: #3e62ad;
-        border: 1px solid #000000;
-        text-align: center;
-    }
-}
 
 .message {
     margin-left: 10px;
@@ -69,6 +83,17 @@ ul {
     text-align: left;
 }
 
+.buttons {
+    margin: 20px 0px;
+    position: absolute;
+    bottom: 0;
+    left: 0;
+    right: 0;
+    margin: 0px auto;
+    padding-bottom: 20px;
+
+}
+
 .formstyle {
     margin: 0, auto;
     .params {
@@ -85,11 +110,22 @@ ul {
             }
         }
     }
-    .buttoms {
-        display: block;
-    }
 }
 
+.side_item {
+    padding: 5px 5px;
+    margin: 2px 0px;
+}
+
+
 .error {
-    background: #cd5e3c
+    background: #cd5e3c;
+    position: absolute;
+    top: 30px;
+    bottom: 30px;
+    left: 30px;
+    right: 30px;
+    margin: auto;
 }
+
+
index e7ceb8c..af72432 100644 (file)
@@ -1,5 +1,4 @@
 - # encoding: utf-8
-- salt = @salt
 
 %h3
   ユーザ登録
@@ -41,9 +40,9 @@
             Eメールアドレス:
         %input{ :name => 'email', :type => 'email', :id => 'email', :size => 30, :maxlength => 127, :required => true}
       
-    %hr
     .buttons
-      %input{ :type => 'submit', :value => '送信'}
-      %input{ :type => 'button', :onclick =>"location.href='/'", :value => 'もどる' }
+      %hr
+      %input{ :type => 'submit', :class=>'push_button', :value => '送信'}
+      %input{ :type => 'button', :class=>'push_button', :onclick =>"location.href='/'", :value => 'もどる' }
   
   
index 21ce8cc..bf8283d 100644 (file)
@@ -1,4 +1,5 @@
 - # encoding: utf-8
+- admin_f = @admin_f
 - id = @id
 - account = @account
 - username = @username
 %form{ :action => "/user_edit", :method => "post"}
   .formstyle
     .params
+      - if (admin_f)
+        .item
+          %label{ :for => 'user_id' }
+            %span
+              ユーザID:
+          %input{ :name => 'usr_id', :id => 'user_id', :value => account, :readonly => true}
+        
       .item
         %label{ :for => 'name' }
           %span
@@ -52,9 +60,9 @@
             Eメールアドレス:
         %input{ :name => 'email', :type => 'email', :id => 'email', :size => 30, :maxlength => 127, :value => email }
       
-    %hr
     .buttons
-      %input{ :type => 'submit', :value => '送信'}
-      %input{ :type => 'button', :onclick =>"location.href='/user_home'", :value => 'もどる' }
+      %hr
+      %input{ :type => 'submit', :class=>'push_button', :value => '送信'}
+      %input{ :type => 'button', :class=>'push_button', :onclick =>"location.href='/user_home'", :value => 'もどる' }
   
   
index fbed01a..f49ebbf 100644 (file)
@@ -8,7 +8,7 @@
 .message
   あなたの最近登録した本は以下になります。
 
-  %ul
-    - newest_list.each do |i|
-      %li=  i
+%ul
+  - newest_list.each do |i|
+    %li=  i
     
diff --git a/sinatra/create_admin.rb b/sinatra/create_admin.rb
new file mode 100644 (file)
index 0000000..722f5ef
--- /dev/null
@@ -0,0 +1,18 @@
+require_relative './app/models/users_db'
+require 'bcrypt'
+
+require 'bcrypt'
+
+passwd_salt = BCrypt::Engine.generate_salt
+passwd_hash = BCrypt::Engine.hash_secret("admin000", passwd_salt)
+
+admin_user = User.new
+admin_user.user_name = "admin"
+admin_user.full_name = "Admin User"
+admin_user.passwd_salt = passwd_salt
+admin_user.passwd_hash = passwd_hash
+admin_user.user_role = User::ROLE_ADMIN
+admin_user.create_at = DateTime.now
+admin_user.update_at = DateTime.now
+admin_user.save
+