From: OHASHI, Norikazu Date: Sat, 16 Mar 2019 12:13:01 +0000 (+0900) Subject: メイン画面、 ユーザ登録画面 など追加 X-Git-Url: http://www.wald-der-katze.sakura.ne.jp/git/gitweb.cgi?a=commitdiff_plain;h=08d7ade58c123f98a1c9d861f55ff5a1eafc1a4c;p=book_server.git メイン画面、 ユーザ登録画面 など追加 --- diff --git a/sinatra/app/controllers/web_gui.rb b/sinatra/app/controllers/web_gui.rb index c7dbdad..9383dad 100644 --- a/sinatra/app/controllers/web_gui.rb +++ b/sinatra/app/controllers/web_gui.rb @@ -16,6 +16,11 @@ class WebGui < Sinatra::Base before do set :haml, :format => :html5 end + + #stylesheet + get '/sytle.css' do + scss :'sccs/style' + end # main page get '/' do @@ -24,19 +29,17 @@ class WebGui < Sinatra::Base # signup page get '/signup' do - @salt = Digest::SHA1.hexdigest("#{DateTime.now.to_s}") haml :signup end - # signup + # signup posting post '/signup' do name = params[:name] full_name = params[:full_name] email = params[:email] - passwd_hash = params[:passwd_hash] - passwd_salt = params[:salt] + passwd = params[:passwd] - id = UserAccount.createAccount(name, full_name, email, passwd_hash, passwd_salt) + id = UserAccount.createAccount(name, full_name, email, passwd) redirect "/user_home/#{id}" end @@ -46,18 +49,11 @@ class WebGui < Sinatra::Base end post '/login' do - user_name = params[:name] - id, salt = UserAccount.gelSalt(user_name); + name = params[:name] + passwd = params[:passwd] + + id = UserAccount.checkPasswd(name, passwd); @id = id - @salt = salt - halm :check_passwd - end - - post '/check_passwd/:id' do - id = params[:id] - passwd_hash = params[:passwd_hash] - id = UserAccount.checkPasswd(id, passwd_hash); - redirect "/user_home/#{id}" end diff --git a/sinatra/app/models/users_db.rb b/sinatra/app/models/users_db.rb index 46b32f0..bef6e99 100644 --- a/sinatra/app/models/users_db.rb +++ b/sinatra/app/models/users_db.rb @@ -2,6 +2,7 @@ require 'active_record' require 'mysql2' +require 'bcrypt' # DB設定ファイルの読み込み ActiveRecord::Base.cofigurations = YAML.load_file('database.yml') @@ -29,49 +30,59 @@ class UserAccount class DbAccessError < StandardError end + # ユーザロールを設定 role[:admin] = 1 role[:normal] = 8 + # ユーザアカウントを作成 - def self.createAccount(name, full_name, email, passwd_hash, passwd_salt) - user = Users.new + def self.createAccount(name, full_name, email, passwd) + + # ユーザの有無をチェック if (User.find_by(:user_name, name) != nil) raise AlreadyInstanceError end + + # パスワードのハッシュ化 + passwd_salt = BCrypt::Engine.generate_salt + passwd_hash = BCrypt::Engine.hash_secret(passwd, passwd_salt) + + # ユーザデータの登録 + user = Users.new user.user_name = name user.full_name = full_name user.email = email - user.passwd_hash = passwd_hash user.passwd_salt = passwd_salt + user.passwd_hash = passwd_hash user.role = role[:normal] user.create_at = DateTime.now user.update_at = DateTime.now user.save + return user.id end - # パスワード用SALTを取得する - def self.getSalt(name) - user = Users.find_by(:user_name, name) - if (user == nil) - raise NotfondInstanceError - end - - return user.user_id, user.passwd_salt - end - #パスワードハッシュをチェックする - def self.checkPasswd(id, passwd_hash) - user = Users.find_by(:user_id, id) + # パスワードをチェックする + def self.checkPasswd(name, passwd) + user = Users.find_by(:user_name, id) + + # ユーザの有無をチェック if (user == nil) raise NotfondInstanceError end - + + # パスワードハッシュを取得 + passwd_hash = BCrypt::Engine.hash_secret(passwd, user.passwd_salt) + + # 登録されているパスワードハッシュと比較 if (user.passwd_hash != passwd_hash) raise AuthenticationError end return id end + + # ユーザ情報取得 def self.getUser(id) user = Users.find_by(:user_id, id) if (user == nil) @@ -79,5 +90,4 @@ class UserAccount end return user end - end diff --git a/sinatra/app/views/layout.haml b/sinatra/app/views/layout.haml index 60ee733..a6c179f 100644 --- a/sinatra/app/views/layout.haml +++ b/sinatra/app/views/layout.haml @@ -20,20 +20,15 @@ @username 書籍一覧 #center #sidebar - %a{ :href => '/user_home/#{id}' } + %a{ :href => "/user_home/#{id}" } ホーム - %a{ :href => '/book_list/#{id}'} + %a{ :href => "/book_list/#{id}"} 書籍一覧 - %a{ :href => '/user_info/#{id}'} + %a{ :href => "/user_info/#{id}"} ユーザ情報 #main= yield #foot - - - - - - - - - + %p + 連絡先: + %a{ :href => 'mailto:support@book_server.neko-mori.org' } + support@book_server.neko-mori.org diff --git a/sinatra/app/views/main.haml b/sinatra/app/views/main.haml new file mode 100644 index 0000000..845f68d --- /dev/null +++ b/sinatra/app/views/main.haml @@ -0,0 +1,12 @@ +- # encoding: utf-8 + +%h1 + 書籍管理サーバ + +.push_buttom + %a{ :href => '/signup' } + サインアップ + +.push_buttom + %a{ :href => '/login' } + ログイン diff --git a/sinatra/app/views/scss/style.scss b/sinatra/app/views/scss/style.scss new file mode 100644 index 0000000..58daf89 --- /dev/null +++ b/sinatra/app/views/scss/style.scss @@ -0,0 +1,30 @@ +div { + &:title { + background: #f8e58c; + } + &:head { + height: 50px; + background: #a8c97f + } + &:sidebar { + float: left; + width: 30%; + background: #fddea5 + } + &:main { + float: right; + width: 70%; + background: #f8e58c; + } + &:foot { + height: 50px; + background: #a8c97f + } + &.pushbuttom { + height: 50px; + width: 300px; + background: #f08300; + foreground: #3e62ad; + border: 1px solid #000000; + } +} diff --git a/sinatra/app/views/signup.haml b/sinatra/app/views/signup.haml new file mode 100644 index 0000000..439c30e --- /dev/null +++ b/sinatra/app/views/signup.haml @@ -0,0 +1,33 @@ +- # encoding: utf-8 +- salt = @salt + +%h3 + ユーザ登録 +%p + ユーザのアカウントを登録します。 以下を入力してください。 + +%hr + +%form{ :action => "/signup", :method => "post"} + アカウント: + %input{ :name => 'name', :size => 10, :maxlength => 10} + %br + + フルネーム: + %input{ :name => 'full_name', :size => 30, :maxlength => 127} + %br + + パスワード: + %input{ :name => 'passwd', :type => 'password', :pattern => '.{6,}' } + %br + + Eメールアドレス + %input{ :name => 'email', :type => 'email', :size => 30, :maxlength => 127} + %br + + %hr + + %input{ :type => 'submit', :value => '送信'} + %input{ :type => 'reset', :value => 'リセット'} + +