-# coding: utf-8
+ # coding: utf-8
# Web GUI用コントローラ
# @author OHASHI, Norikazu
haml pageId
end
- #
+ # アップロード用にファイルからデータを読む
# @params [Hash] Upload用パラメータ
# @return [Hash] Uploadデータ情報
def getUploadData(upload_param)
user = UserAccount.getUser(id)
@id = id
@username = user.full_name
- @is_addmin = user.isAddmin
+ @is_admin = UserAccount.checkAdmin(id)
@newest_list = BookManager.newestListOfBooks(id, 5)
goPage :user_home
end
end
begin
user = UserAccount.getUser(id)
- @admin_f = false
+ @is_admin = UserAccount.checkAdmin(id);
+ @admin_type = false
@id = id
@username = user.full_name
+ @editname = user.full_name
@account = user.user_name
@email = user.email
rescue UserAccount::NotFoundInstanceError
goPage :user_edit
end
+ # ユーザ情報編集ページ(ユーザID指定)
+ # @path_param [Integer] editId 更新するユーザのId
+ # @raise [WebError] セッションの期限切れ
+ # @raise [WebError] ユーザID不正
+ get '/user_edit/:editId' do
+ id = session[:userId]
+ edit_id = params[:editId]
+ if (id == nil)
+ raise WebError.new(status: 408, message: "セッション期限切れです。再ログインをしてください。")
+ end
+ if (not UserAccount.checkAdmin(id))
+ raise WebError.new(status: 405, message: "管理者アカウントでないと操作できません。")
+ end
+ begin
+ user = UserAccount.getUser(id)
+ edit_user = UserAccount.getUser(edit_id)
+ @admin_type = true
+ @is_admin = UserAccount.checkAdmin(id);
+ @id = edit_id
+ @username = user.full_name
+ @editname = edit_user.full_name
+ @account = edit_user.user_name
+ @email = edit_user.email
+ rescue UserAccount::NotFoundInstanceError
+ raise WebError.new(status: 400, message: "該当するユーザが存在しません。")
+ end
+ goPage :user_edit
+ end
+
# ユーザ情報編集ページ(POST)
# @post_param name [String] ログインユーザ名,
# @post_param try_pass [String] 旧パスワード
end
end
- # 蔵書の登録
+ # ユーザ情報編集ページ(ユーザID指定)(POST)
+ # @post_param name [String] ログインユーザ名,
+ # @post_param try_pass [String] 旧パスワード
+ # @post_param new_pass [String] 新パスワード
+ # @post_param full_name [String] フルネーム
+ # @post_param email [String] Eメール
+ # @raise [WebError] セッションの期限切れ
+ # @raise [WebError] ユーザ情報編集失敗
+ post '/user_edit/:editId' do
+ id = session[:userId]
+ edit_id = params[:editId]
+ full_name = params[:full_name]
+ email = params[:email]
+ new_pass = params[:new_pass]
+
+ if (id == nil)
+ raise WebError.new(staut: 408, message: "セッション期限切れです。再ログインをしてください。")
+ end
+ if (not UserAccount.checkAdmin(id))
+ raise WebError.new(status: 405, message: "管理者アカウントでないと操作できません。")
+ end
+ begin
+ params = {passwd: new_pass,
+ full_name: full_name,
+ email: email}
+ UserAccount.updateUser(edit_id, params)
+ redirect to('/user_list')
+ rescue UserAccount::NotFoundInstanceError,
+ UserAccount::AuthenticationError
+ raise WebError.new(status: 400, message: "ユーザ情報の編集に失敗しました。", refs: "/user_edit")
+ end
+ end
+
+ # ユーザ一覧ページ
+ # @raise [WebError] セッションの期限切れ
+ # @raise [WebError] ユーザID不正
+ get '/user_list' do
+ cache_control :public, :must_revalidate, :max_age => 30
+ id = session[:userId]
+ book_update_f = false
+ session[:book_update_f] = book_update_f
+ if (id == nil)
+ raise WebError.new(status: 408, message: "セッション期限切れです。再ログインをしてください。")
+ end
+ if (not UserAccount.checkAdmin(id))
+ raise WebError.new(status: 405, message: "管理者アカウントでないと操作できません。")
+ end
+ begin
+ user = UserAccount.getUser(id)
+ @user_list = UserAccount.getUserList(id);
+ @username = user.full_name
+ @is_admin = UserAccount.checkAdmin(id);
+ rescue UserAccount::AuthenticationError
+ raise WebError.new(status: 405, message: "管理者でしか利用できません。")
+ end
+ goPage :user_list
+ end
+
+
+ # ユーザ情報の削除
+ # @path_param [integer] deletId 削除対象のユーザId
+ # @raise [WebError] セッションの期限切れ
+ get '/user_delete/:deleteId' do
+ cache_control :public, :must_revalidate, :max_age => 30
+ id = session[:userId]
+ delete_id = params[:deleteId]
+ if (id == nil)
+ raise WebError.new(status: 408, message: "セッション期限切れです。再ログインをしてください。")
+ end
+ if (not UserAccount.checkAdmin(id))
+ raise WebError.new(status: 405, message: "管理者アカウントでないと操作できません。")
+ end
+ begin
+ user = UserAccount.getUser(id)
+ @delete_user = UserAccount.getUser(delete_id)
+ @username = user.full_name
+ rescue UserAccount::NotFoundInstanceError
+ raise WebError.new(status: 404, message: "ユーザ情報が存在しません。")
+ end
+ goPage :user_delete
+ end
+
+ # ユーザ情報の削除 (削除実行)
+ # @path_param [Integer] deleteId 削除対象のユーザId
+ # @raise [WebError] セッションの期限切れ
+ get '/user_delete/result/:deleteId' do
+ cache_control :public, :must_revalidate, :max_age => 30
+ id = session[:userId]
+ delete_id = params[:deleteId]
+ if (not UserAccount.checkAdmin(id))
+ raise WebError.new(status: 405, message: "管理者アカウントでないと操作できません。")
+ end
+ begin
+ BookManager.deleteBookCollectOfUser(delete_id)
+ UserAccount.deleteUser(delete_id)
+ rescue UserAccount::NotFoundInstanceError
+ raise WebError.new(status: 404, message: "ユーザ情報が存在しません。")
+ rescue UserAccount::AuthenticationError
+ raise WebError.new(status: 405, message: "管理者でしか利用できません。")
+ end
+ redirect to('/user_list')
+ end
+
+ # 蔵書の登録ページ
+ # @raise [WebError] セッションの期限切れ
+ # @raise [WebError] ユーザID不正
get '/book_regist' do
cache_control :public, :must_revalidate, :max_age => 30
id = session[:userId]
@username = user.full_name
@book_info = Hash.new
@update_f = book_update_f
+ @is_admin = UserAccount.checkAdmin(id);
rescue UserAccount::NotFoundInstanceError
raise WebError.new(status: 404, message: "ユーザ情報が存在しません。")
end
goPage :book_regist
end
- # 蔵書の編集
+ # 蔵書の編集ページ
+ # @path_param [string] isbn 編集対象のISBN
+ # @raise [WebError] セッションの期限切れ
+ # @raise [WebError] ユーザID不正
get '/book_edit/:isbn' do
cache_control :public, :must_revalidate, :max_age => 30
id = session[:userId]
@username = user.full_name
@book_info = BookManager.getBookCollect(isbn, id)
@update_f = book_update_f
+ @is_admin = UserAccount.checkAdmin(id);
rescue UserAccount::NotFoundInstanceError
raise WebError.new(status: 404, message: "ユーザ情報が存在しません。")
end
@id = id
@username = user.full_name
@book_info = BookManager.searchISBN(isbn, id)
+ @is_admin = UserAccount.checkAdmin(id);
rescue UserAccount::NotFoundInstanceError
raise WebError.new(status: 404, message: "ユーザ情報が存在しません。")
rescue BookManager::AlreadyInstanceError
@id = id
@username = user.full_name
@book_info = params
+ @is_admin = UserAccount.checkAdmin(id);
cover_image = getUploadData(params[:cover_file])
if (cover_image != nil)
base64 = Base64.encode64(cover_image[:data])
goPage :book_regist
end
+
# 書影の表示
get '/book_image/:hash' do
cache_control :public, :must_revalidate, :max_age => 30
end
- # 蔵書情報の取得
+ # 蔵書情報の取得ページ
+ # @raise [WebError] セッションの期限切れ
+ # @raise [WebError] ユーザID不正
+ # @raise [WebError] 蔵書情報がない
get '/book_info/:isbn' do
cache_control :public, :must_revalidate, :max_age => 30
id = session[:userId]
@id = id
@username = user.full_name
@book_info = BookManager.getBookCollect(isbn, id)
+ @is_admin = UserAccount.checkAdmin(id);
rescue UserAccount::NotFoundInstanceError
raise WebError.new(status: 404, message: "ユーザ情報が存在しません。")
rescue BookManager::NotFoundInstanceError
goPage :book_info
end
- #蔵書一覧の取得(トリガページ)
+ # 蔵書一覧の取得(トリガページ)
+ # @raise [WebError] セッションの期限切れ
get '/book_list' do
id = session[:userId]
if (id == nil)
redirect to('/book_list/main')
end
- #蔵書一覧の取得(表示件数変更ページ)
+ # 蔵書一覧の取得(表示件数変更ページ)
+ # @raise [WebError] セッションの期限切れ
post '/book_list/change_step' do
id = session[:userId]
if (id == nil)
redirect to('/book_list/main')
end
- #蔵書一覧の取得(次ページ)
+ # 蔵書一覧の取得(次ページ)
+ # @raise [WebError] セッションの期限切れ
post '/book_list/next' do
id = session[:userId]
if (id == nil)
redirect to('/book_list/main')
end
- #蔵書一覧の取得(前ページ)
+ # 蔵書一覧の取得(前ページ)
+ # @raise [WebError] セッションの期限切れ
post '/book_list/before' do
id = session[:userId]
if (id == nil)
redirect to('/book_list/main')
end
- #蔵書一覧の取得(検索後)
+
+ # 蔵書一覧の取得(検索後)
+ # @raise [WebError] セッションの期限切れ
post '/book_list/find' do
id = session[:userId]
if (id == nil)
redirect to('/book_list/main')
end
- #蔵書一覧の取得 (蔵書情報取得から)
+ # 蔵書一覧の取得 (蔵書情報取得から)
+ # @raise [WebError] セッションの期限切れ
get '/book_list/fromInfo' do
id = session[:userId]
if (id == nil)
end
redirect to('/book_list/main')
end
- #蔵書一覧の取得(メインページ)
+
+ # 蔵書一覧の取得(メインページ)
+ # @raise [WebError] セッションの期限切れ
get '/book_list/main' do
id = session[:userId]
list_status = session[:list_status]
user = UserAccount.getUser(id)
@id = id
@username = user.full_name
+ @is_admin = UserAccount.checkAdmin(id);
rescue UserAccount::NotFoundInstanceError
raise WebError.new(status: 404, message: "ユーザ情報が存在しません。")
end
end
# 蔵書の削除
+ # @path_param [string] isbn 削除対象のISBN
+ # @raise [WebError] セッションの期限切れ
get '/book_delete/:isbn' do
cache_control :public, :must_revalidate, :max_age => 30
id = session[:userId]
@id = id
@username = user.full_name
@book_info = BookManager.getBookCollect(isbn, id)
+ @is_admin = UserAccount.checkAdmin(id);
rescue UserAccount::NotFoundInstanceError
raise WebError.new(status: 404, message: "ユーザ情報が存在しません。")
rescue BookManager::NotFoundInstanceError
goPage :book_delete
end
- # 蔵書の削除
+ # 蔵書の削除 (削除実行)
+ # @path_param [string] isbn 削除対象のISBN
+ # @raise [WebError] セッションの期限切れ
get '/book_delete/result/:isbn' do
cache_control :public, :must_revalidate, :max_age => 30
id = session[:userId]
- # encoding: utf-8
-- admin_f = @admin_f
+- is_admin = @admin_type
- id = @id
- account = @account
-- username = @username
+- editname = @editname
- email = @email
-
+- if (is_admin)
+ - post_url="/user_edit/#{id}"; return_url='/user_list'
+- else
+ - post_url='/user_edit'; return_url='/user_home'
+
%h3
- #{username} さんのユーザデータを変更できます。
+ #{editname} さんのユーザデータを変更できます。
.message
- パスワードを変更する際には、現在のパスワードと
- 新しいパスワードを入力してください。
+ -if (not is_admin)
+ パスワードを変更する際には、現在のパスワードと
+ 新しいパスワードを入力してください。
%hr
-%form{ :action => "/user_edit", :method => "post"}
+%form{ :action => post_url, :method => "post"}
.formstyle
.params
- - if (admin_f)
+ - if (is_admin)
.item
%label{ :for => 'user_id' }
%span
ユーザID:
- %input{ :name => 'usr_id', :type => 'text', :class => 'input_text', :id => 'user_id', :value => account, :readonly => true}
+ %input{ :name => 'usr_id', :type => 'text', :class => 'input_text', :id => 'user_id', :value => id, :readonly => true}
.item
%label{ :for => 'name' }
%label{ :for => 'full_name' }
%span
フルネーム:
- %input{ :name => 'full_name', :type => 'text', :class => 'input_text', :id => 'full_name', :size => 30, :value => username, :maxlength => 127}
-
- .item
- %label{ :for => 'old_passwd' }
- %span
- 現在のパスワード:
- %input{ :name => 'try_pass', :type => 'password', :class => 'input_text', :id => 'old_passwd'}
+ %input{ :name => 'full_name', :type => 'text', :class => 'input_text', :id => 'full_name', :size => 30, :value => editname, :maxlength => 127}
+
+ - if (not is_admin)
+ .item
+ %label{ :for => 'old_passwd' }
+ %span
+ 現在のパスワード:
+ %input{ :name => 'try_pass', :type => 'password', :class => 'input_text', :id => 'old_passwd'}
.item
%label{ :for => 'passwd' }
.buttons
%hr
%input{ :type => 'submit', :class => 'push_button', :value => '送信'}
- %input{ :type => 'button', :class => 'push_button', :onclick =>"location.href='/user_home'", :value => 'もどる' }
+ %input{ :type => 'button', :class => 'push_button', :onclick =>"location.href='#{return_url}'", :value => 'もどる' }