before do
set :haml, :format => :html5
end
+
+ #stylesheet
+ get '/sytle.css' do
+ scss :'sccs/style'
+ end
# main page
get '/' do
# 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
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
require 'active_record'
require 'mysql2'
+require 'bcrypt'
# DB設定ファイルの読み込み
ActiveRecord::Base.cofigurations = YAML.load_file('database.yml')
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)
end
return user
end
-
end
@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
--- /dev/null
+- # encoding: utf-8
+
+%h1
+ 書籍管理サーバ
+
+.push_buttom
+ %a{ :href => '/signup' }
+ サインアップ
+
+.push_buttom
+ %a{ :href => '/login' }
+ ログイン
--- /dev/null
+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;
+ }
+}
--- /dev/null
+- # 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 => 'リセット'}
+
+