From: OHASHI, Norikazu Date: Fri, 22 Mar 2019 16:23:42 +0000 (+0900) Subject: エラー用のViewに対応 X-Git-Url: http://www.wald-der-katze.sakura.ne.jp/git/gitweb.cgi?a=commitdiff_plain;h=fbefb1d3a2915ccbf451298d662bd94e6d4c922f;p=book_server.git エラー用のViewに対応 --- diff --git a/sinatra/app/controllers/web_gui.rb b/sinatra/app/controllers/web_gui.rb index 32a38df..9e09cc9 100644 --- a/sinatra/app/controllers/web_gui.rb +++ b/sinatra/app/controllers/web_gui.rb @@ -7,10 +7,19 @@ require 'haml' require_relative '../models/users_db' class WebGui < Sinatra::Base + + class WebError < StandardError + attr_reader :status + def initialize(status) + @status = status + end + end + set :root, File.join(File.dirname(__FILE__), '..') set :views, Proc.new {File.join(root, "views")} set :haml, :format => :html5 - + set :environment, :production + use Rack::Session::Cookie, :expire_after => 300, :secret => 'change' @@ -42,8 +51,8 @@ class WebGui < Sinatra::Base session[:userId] = id; redirect "/user_home" rescue UserAccount::AlreadyInstanceError - status 406 - "すでに登録済みのアカウント名が指定されています。" + raise WebError.new(406), + "すでに登録済みのアカウント名が指定されています。" end end @@ -61,13 +70,17 @@ class WebGui < Sinatra::Base redirect "/user_home" rescue UserAccount::NotfondInstanceError, UserAccount::AuthenticationError - status 401 - "認証に失敗しました アカウント、 パスワードを確認してください。" + raise WebError.new(401), + "認証に失敗しました アカウント、 パスワードを確認してください。" end end get '/user_home' do id = session[:userId] + if (id == nil) + raize WebError.new(408), + "セッション期限切れです。再ログインをしてください。" + end user = UserAccount.getUser(id) @id = id @username = user.full_name @@ -80,5 +93,11 @@ class WebGui < Sinatra::Base haml :logout end + error WebError do + e = env['sinatra.error'] + status e.status + @error_message = e.message + haml :error + end end diff --git a/sinatra/app/views/error.haml b/sinatra/app/views/error.haml new file mode 100644 index 0000000..06a5929 --- /dev/null +++ b/sinatra/app/views/error.haml @@ -0,0 +1,12 @@ +- # encoding: utf-8 +- error_message = @error_message + +.error + %h3 + エラーが発生しました。 + %p= error_message + + .buttoms + .buttoms__push + %a{ :href => '/'} + メインにもどる diff --git a/sinatra/app/views/layout.haml b/sinatra/app/views/layout.haml index 9156f3c..a05a277 100644 --- a/sinatra/app/views/layout.haml +++ b/sinatra/app/views/layout.haml @@ -31,6 +31,7 @@ ユーザ情報 %br %a{ :href => "/logout" } + ログアウト #main= yield #foot %p diff --git a/sinatra/app/views/logout.haml b/sinatra/app/views/logout.haml index 086faa3..d99db8f 100644 --- a/sinatra/app/views/logout.haml +++ b/sinatra/app/views/logout.haml @@ -1,5 +1,9 @@ - # encoding: utf-8 - %h2 おつかれさまでした。 +.buttoms + .buttoms__push + %a{ :href => '/'} + メインにもどる + diff --git a/sinatra/app/views/scss/style.scss b/sinatra/app/views/scss/style.scss index e8be823..8c6ba2d 100644 --- a/sinatra/app/views/scss/style.scss +++ b/sinatra/app/views/scss/style.scss @@ -27,7 +27,7 @@ ul { #sidebar { float: left; - width: 30%; + width: 20%; background: #fddea5; text-align: left; padding-bottom: 3267px; @@ -36,7 +36,7 @@ ul { #main { float: right; - width: 70%; + width: 80%; background: #f8e58c; text-align: center; padding-bottom: 3267px; @@ -55,7 +55,7 @@ ul { &__push { margin: 20px; height: 20px; - width: 100px; + width: 200px; background: #f08300; foreground: #3e62ad; border: 1px solid #000000; @@ -67,3 +67,6 @@ ul { text-align: left; } +.error { + background: #cd5e3c +}