ユーザ情報修正をHushで行うように対応 sidebarのファイル分割
authorOHASHI, Norikazu <katz@neko-mori.sakura.ne.jp>
Wed, 24 Apr 2019 13:13:32 +0000 (22:13 +0900)
committerOHASHI, Norikazu <katz@neko-mori.sakura.ne.jp>
Wed, 24 Apr 2019 13:13:32 +0000 (22:13 +0900)
readme.md
sinatra/app/controllers/web_gui.rb
sinatra/app/models/users_db.rb
sinatra/app/views/layout.haml
sinatra/app/views/main.haml
sinatra/app/views/sidebar.haml [new file with mode: 0644]
sinatra/public/favicon.ico [new file with mode: 0644]

index 6b16fb5..bdc5b0b 100644 (file)
--- a/readme.md
+++ b/readme.md
@@ -85,7 +85,7 @@
 |  1 | key_hash | VARCHAR(60) | NOT NULL, PRIMARY KEY | SHA125 HASH (アクセスキー) |
 |  2 | isbn | VARCHAR(14) | NOT NULL, UNIQUE | 対象ISBN |
 |  3 | mime_type | VARCHAR(255) | NOT NULL | 画像のMIME TYPE |
-|  4 | shadow | LARGETEXT | NOT NULL | 画像のデータ(BASE64) |
+|  4 | shadow | LONGBLOB | NOT NULL | 画像のデータ |
 |  5 | creat_at | DATETIME | NOT NULL | 登録日時 |
 |  6 | update_at | DATETIME | NOT NULL | 更新日時 |
 
index 8819a4b..f064e82 100644 (file)
@@ -135,6 +135,7 @@ class WebGui < Sinatra::Base
   # @post_param new_pass [String] 新パスワード
   # @post_param full_name [String] フルネーム
   # @post_param email [String] Eメール
+  # @raise [WebError] セッションの期限切れ
   # @raise [WebError] ユーザ情報編集失敗
   post '/user_edit' do
     id = session[:userId]
@@ -154,10 +155,9 @@ class WebGui < Sinatra::Base
           raise StandardError, "アカウント名とIDが不正"
         end
       end
-      UserAccount.changeUser(id, new_pass, full_name, email)
+      UserAccount.changeUser(id, passwd: new_pass, full_name: full_name, email: email)
       redirect "/user_home"
-    rescue StandardError,
-           UserAccount::NotFoundInstanceError,
+    rescue UserAccount::NotFoundInstanceError,
            UserAccount::AuthenticationError
       raise WebError.new(statu: 400, message: "ユーザ情報の編集に失敗しました。", refs: "/user_edit")
     end
index 5d17800..74749c7 100644 (file)
@@ -40,7 +40,6 @@ end
 
 # ユーザ管理
 class UserAccount
-
   
   # ユーザ認証エラー
   class AuthenticationError < SecurityError
@@ -157,32 +156,32 @@ class UserAccount
 
   # ユーザ情報の変更
   # @param [Integer] id 変更対象のユーザID
-  # @param [String] passwd 変更するパスワード (未修正の場合は空文字列)
-  # @param [String] full_name 変更するフルネーム (未修正の場合は空文字列)
-  # @param [String] email 変更するEメールアドレス (未修正の場合は空文字列)
-  def self.changeUser(id, passwd, full_name, email)
+  # @param [Hash] columns 変更するカラムと値のハッシュ
+
+  def self.changeUser(id, columns)
     user = User.find_by(user_id: id)
     change_f = false
     if (user == nil) 
       raise NotFoundInstanceError
     end
 
-    # パスワード更新
-    if (passwd != "") 
-      user.passwd_hash = BCrypt::Engine.hash_secret(passwd, user.passwd_salt)
-      change_f = true
-    end
-
-    # フルネーム更新
-    if ((full_name != "") && (full_name != user.full_name) )
-      user.full_name = full_name
-      change_f = true
-    end
-
-    # Eメール更新
-    if ((email != "") && (email != user.email))
-      user.email = email
-      change_f = true
+    columns.each do |key, value|
+      if ((value == nil) || (value == ""))
+        # 値がない、値が空文字の場合は対象としない。
+        next
+      end
+      if (key == :passwd)
+        # パスワード更新
+        user.passwd_hash = BCrypt::Engine.hash_secret(value, user.passwd_salt)
+        change_f = true
+      else
+        if (value != user.send(key))
+          # その他のステータス、値が異なれば更新
+          method = key.to_s + "="
+          user.send(method, value)
+          change_f = true
+        end
+      end
     end
 
     # 更新内容の適用
@@ -192,4 +191,15 @@ class UserAccount
     end
   end
 
+  # ユーザ情報の削除
+  def deleteUser(id)
+    user = User.find_by(id: id)
+    if (user == nil)
+      raise NotFoundInstanceError
+    end
+    if (not user.destroy)
+      raise DbAccessError
+    end
+  end
+
 end
index c92384d..3908d7f 100644 (file)
@@ -1,11 +1,9 @@
 - # encoding: utf-8
 - if @username != nil
-  - title_name = @username+"書籍"
-  - id = @id
+  - title_name = @username+" 蔵書管理 "
   - user_name = @username
-  - is_admin = @is_admin
 - else
-  - title_name = "書籍一覧管理"
+  - title_name = "蔵書管理 Web"
 !!!
 %html
   %head{ :lang => 'ja' }
       #main1= yield
     - else
       #head
-        #{user_name} 書籍一覧
+        #{user_name} 蔵書管理 Home
       #center
         #sidebar
-          %a{ :href => "/user_home" }
-            ホーム
-          %br
-          %a{ :href => "/book_list" }
-            書籍一覧
-          %br
-          - if is_admin
-            %a{ :href => "/user_list" }
-              ユーザ情報変更
-          - else
-            %a{ :href => "/user_edit" }
-              ユーザ情報変更
-          %br
-          %a{ :href => "/logout" }
-            ログアウト
+          = haml :sidebar
         #main2= yield
-      #foot
-        %p
-          連絡先:
-          %a{ :href => 'mailto:support@book_server.neko-mori.org' }
-            support@book_server.neko-mori.org
+    #foot
+      %p
+        連絡先:
+        %a{ :href => 'mailto:support@book_server.neko-mori.org' }
+          support@book_server.neko-mori.org
index 1089886..9a3e0dc 100644 (file)
@@ -1,7 +1,7 @@
 - # encoding: utf-8
 
 %h1
-  蔵書管理サーバ
+  蔵書管理 Web v0.01
 
 .buttoms
   .buttoms__push
diff --git a/sinatra/app/views/sidebar.haml b/sinatra/app/views/sidebar.haml
new file mode 100644 (file)
index 0000000..0a3dab5
--- /dev/null
@@ -0,0 +1,23 @@
+- # encoding: utf-8
+- is_admin = @is_admin
+
+.side_item
+  %a{ :href => "/user_home" }
+    ホーム
+.side_item
+  %a{ :href => "/book_list" }
+    書籍一覧
+.side_item
+  %a{ :href => "/book_regist" }
+    書籍登録
+.side_item
+  - if is_admin
+    %a{ :href => "/user_list" }
+      ユーザ情報変更
+  - else
+    %a{ :href => "/user_edit" }
+      ユーザ情報変更
+      
+.side_item
+  %a{ :href => "/logout" }
+    ログアウト
diff --git a/sinatra/public/favicon.ico b/sinatra/public/favicon.ico
new file mode 100644 (file)
index 0000000..abe7eaa
Binary files /dev/null and b/sinatra/public/favicon.ico differ