multi_auth 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/README +36 -0
  2. data/app/controllers/application_controller.rb +11 -0
  3. data/app/controllers/auth/email_controller.rb +34 -0
  4. data/app/controllers/auth/open_id_controller.rb +43 -0
  5. data/app/controllers/auth_controller.rb +24 -0
  6. data/app/controllers/credentials/email_controller.rb +156 -0
  7. data/app/controllers/credentials/open_id_controller.rb +85 -0
  8. data/app/controllers/credentials_controller.rb +14 -0
  9. data/app/controllers/signup/email_controller.rb +132 -0
  10. data/app/controllers/signup/open_id_controller.rb +62 -0
  11. data/app/controllers/signup_controller.rb +8 -0
  12. data/app/helpers/application_helper.rb +5 -0
  13. data/app/models/activation_mailer.rb +114 -0
  14. data/app/models/email_credential.rb +89 -0
  15. data/app/models/email_credential_edit_form.rb +52 -0
  16. data/app/models/email_login_form.rb +24 -0
  17. data/app/models/email_password_edit_form.rb +36 -0
  18. data/app/models/open_id_credential.rb +33 -0
  19. data/app/models/open_id_login_form.rb +17 -0
  20. data/app/models/session.rb +19 -0
  21. data/app/models/user.rb +37 -0
  22. data/app/views/activation_mailer/complete_for_credential.erb +4 -0
  23. data/app/views/activation_mailer/complete_for_notice.erb +4 -0
  24. data/app/views/activation_mailer/complete_for_signup.erb +4 -0
  25. data/app/views/activation_mailer/request_for_credential.erb +11 -0
  26. data/app/views/activation_mailer/request_for_notice.erb +11 -0
  27. data/app/views/activation_mailer/request_for_signup.erb +11 -0
  28. data/app/views/auth/email/index.html.erb +90 -0
  29. data/app/views/auth/logged_in.html.erb +21 -0
  30. data/app/views/auth/logged_out.html.erb +21 -0
  31. data/app/views/auth/open_id/index.html.erb +16 -0
  32. data/app/views/credentials/email/activated.html.erb +4 -0
  33. data/app/views/credentials/email/activation.html.erb +15 -0
  34. data/app/views/credentials/email/created.html.erb +15 -0
  35. data/app/views/credentials/email/delete.html.erb +20 -0
  36. data/app/views/credentials/email/edit_password.html.erb +31 -0
  37. data/app/views/credentials/email/new.html.erb +36 -0
  38. data/app/views/credentials/index.html.erb +88 -0
  39. data/app/views/credentials/open_id/delete.html.erb +20 -0
  40. data/app/views/credentials/open_id/new.html.erb +26 -0
  41. data/app/views/signup/email/_progress.html.erb +14 -0
  42. data/app/views/signup/email/activated.html.erb +9 -0
  43. data/app/views/signup/email/activation.html.erb +27 -0
  44. data/app/views/signup/email/created.html.erb +14 -0
  45. data/app/views/signup/email/index.html.erb +34 -0
  46. data/app/views/signup/email/validated.html.erb +21 -0
  47. data/app/views/signup/index.html.erb +51 -0
  48. data/app/views/signup/open_id/authenticated.html.erb +15 -0
  49. data/app/views/signup/open_id/created.html.erb +6 -0
  50. data/app/views/signup/open_id/index.html.erb +16 -0
  51. data/config/boot.rb +110 -0
  52. data/config/database.yml +22 -0
  53. data/config/database.yml.sqlite3 +22 -0
  54. data/config/environment.rb +62 -0
  55. data/config/routes.rb +51 -0
  56. data/config/smtp.yml.example +8 -0
  57. data/db/development.sqlite3 +0 -0
  58. data/db/schema.rb +88 -0
  59. data/db/test.sqlite3 +0 -0
  60. data/lib/action_mailer_util.rb +15 -0
  61. data/lib/multi_auth.rb +64 -0
  62. data/lib/multi_auth_helper.rb +98 -0
  63. data/lib/notice_formatter.rb +106 -0
  64. data/lib/open_id_authentication/result.rb +12 -0
  65. data/lib/token_util.rb +18 -0
  66. data/public/404.html +92 -0
  67. data/public/422.html +91 -0
  68. data/public/500.html +92 -0
  69. data/public/503.html +92 -0
  70. data/public/favicon.ico +0 -0
  71. data/public/images/battery/cell.png +0 -0
  72. data/public/images/battery/level-green.png +0 -0
  73. data/public/images/battery/level-orange.png +0 -0
  74. data/public/images/battery/level-red.png +0 -0
  75. data/public/images/battery/level-yellow.png +0 -0
  76. data/public/images/battery/style.html +82 -0
  77. data/public/images/favicons/livedoor.png +0 -0
  78. data/public/images/favicons/mixi.png +0 -0
  79. data/public/images/favicons/yahoo.png +0 -0
  80. data/public/images/h1-back.png +0 -0
  81. data/public/images/icons/fam/add.png +0 -0
  82. data/public/images/icons/fam/bin.png +0 -0
  83. data/public/images/icons/fam/bomb.png +0 -0
  84. data/public/images/icons/fam/cog.png +0 -0
  85. data/public/images/icons/fam/delete.png +0 -0
  86. data/public/images/icons/fam/email-with-desc.png +0 -0
  87. data/public/images/icons/fam/email.png +0 -0
  88. data/public/images/icons/fam/feed.png +0 -0
  89. data/public/images/icons/fam/help.png +0 -0
  90. data/public/images/icons/fam/key-with-desc.png +0 -0
  91. data/public/images/icons/fam/key.png +0 -0
  92. data/public/images/icons/fam/lightning.png +0 -0
  93. data/public/images/icons/fam/plugin.png +0 -0
  94. data/public/images/icons/fam/stop.png +0 -0
  95. data/public/images/icons/fam/table_save.png +0 -0
  96. data/public/images/icons/fam/tick.png +0 -0
  97. data/public/images/icons/fam/user.png +0 -0
  98. data/public/images/icons/fam/vcard.png +0 -0
  99. data/public/images/icons/openid-with-desc.png +0 -0
  100. data/public/images/icons/openid.png +0 -0
  101. data/public/images/logo-back.png +0 -0
  102. data/public/images/logo.png +0 -0
  103. data/public/images/side-column-back.png +0 -0
  104. data/public/javascripts/application.js +2 -0
  105. data/public/javascripts/controls.js +963 -0
  106. data/public/javascripts/dragdrop.js +973 -0
  107. data/public/javascripts/effects.js +1128 -0
  108. data/public/javascripts/prototype.js +4320 -0
  109. data/public/robots.txt +5 -0
  110. data/public/stylesheets/application.css +365 -0
  111. data/public/stylesheets/auth.css +22 -0
  112. data/public/stylesheets/home.css +114 -0
  113. data/rails/init.rb +24 -0
  114. data/test/functional/auth/email_controller_test.rb +102 -0
  115. data/test/functional/auth/open_id_controller_test.rb +76 -0
  116. data/test/functional/auth_controller_test.rb +74 -0
  117. data/test/functional/credentials/email_controller_test.rb +488 -0
  118. data/test/functional/credentials/open_id_controller_test.rb +308 -0
  119. data/test/functional/credentials_controller_test.rb +49 -0
  120. data/test/functional/signup/email_controller_test.rb +369 -0
  121. data/test/functional/signup/open_id_controller_test.rb +44 -0
  122. data/test/functional/signup_controller_test.rb +17 -0
  123. data/test/performance/browsing_test.rb +9 -0
  124. data/test/test_helper.rb +82 -0
  125. data/test/unit/action_mailer_util_test.rb +63 -0
  126. data/test/unit/activation_mailer_test.rb +181 -0
  127. data/test/unit/email_credential_edit_form_test.rb +173 -0
  128. data/test/unit/email_credential_test.rb +324 -0
  129. data/test/unit/email_login_form_test.rb +76 -0
  130. data/test/unit/email_password_edit_form_test.rb +117 -0
  131. data/test/unit/helpers/auth_helper_test.rb +4 -0
  132. data/test/unit/helpers/credentials/email_helper_test.rb +4 -0
  133. data/test/unit/helpers/credentials/open_id_helper_test.rb +4 -0
  134. data/test/unit/helpers/credentials_helper_test.rb +4 -0
  135. data/test/unit/helpers/email_auth_helper_test.rb +4 -0
  136. data/test/unit/helpers/email_signup_helper_test.rb +4 -0
  137. data/test/unit/helpers/open_id_auth_helper_test.rb +4 -0
  138. data/test/unit/helpers/open_id_signup_helper_test.rb +4 -0
  139. data/test/unit/helpers/password_auth_helper_test.rb +4 -0
  140. data/test/unit/helpers/password_signup_helper_test.rb +4 -0
  141. data/test/unit/helpers/signup_helper_test.rb +4 -0
  142. data/test/unit/notice_formatter_test.rb +153 -0
  143. data/test/unit/open_id_credential_test.rb +108 -0
  144. data/test/unit/open_id_login_form_test.rb +57 -0
  145. data/test/unit/session_test.rb +53 -0
  146. data/test/unit/token_util_test.rb +51 -0
  147. data/test/unit/user_test.rb +177 -0
  148. metadata +220 -0
data/config/routes.rb ADDED
@@ -0,0 +1,51 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ActionController::Routing::Routes.draw do |map|
4
+ IdPattern = /[0-9]+/
5
+ TokenPattern = /[0-9a-f]+/
6
+
7
+ if Rails.root.to_s == File.expand_path(File.join(File.dirname(__FILE__), '..'))
8
+ map.root :controller => "home", :action => "index"
9
+ end
10
+
11
+ map.connect "signup", :controller => "signup", :action => "index"
12
+
13
+ map.with_options :controller => "signup/email" do |email|
14
+ email.connect "signup/email/:action", :action => /(index|validate|validated|create|created|activate|activated)/
15
+ email.connect "signup/email/activation/:activation_token", :action => "activation", :activation_token => TokenPattern
16
+ end
17
+
18
+ map.with_options :controller => "signup/open_id" do |open_id|
19
+ open_id.connect "signup/open_id/:action", :action => /(index|authenticate|authenticated|create|created)/
20
+ end
21
+
22
+ map.connect "auth/:action", :controller => "auth", :action => /(logged_in|logout|logged_out)/
23
+ map.connect "auth/email/:action", :controller => "auth/email", :action => /(index|login)/
24
+ map.connect "auth/open_id/:action", :controller => "auth/open_id", :action => /(index|login)/
25
+
26
+ map.connect "credentials/:action", :controller => "credentials", :action => /(index)/
27
+
28
+ map.with_options :controller => "credentials/email" do |email|
29
+ email.connect "credentials/email/:action", :action => /(new|create)/
30
+ email.connect "credential/email/:email_credential_id/:action", :action => /(created|edit_password|update_password|delete|destroy)/, :email_credential_id => IdPattern
31
+ email.connect "credential/email/token/:activation_token/:action", :action => /(activation|activate|activated)/, :activation_token => TokenPattern
32
+ end
33
+
34
+ map.with_options :controller => "credentials/open_id" do |open_id|
35
+ open_id.connect "credentials/open_id/:action", :action => /(new|create)/
36
+ open_id.connect "credential/open_id/:open_id_credential_id/:action", :action => /(delete|destroy)/, :open_id_credential_id => IdPattern
37
+ end
38
+
39
+ map.with_options :controller => "emails" do |emails|
40
+ emails.connect "emails/:action", :action => /(new|create)/
41
+ emails.connect "email/:email_address_id/:action", :action => /(created|delete|destroy)/, :email_address_id => IdPattern
42
+ emails.connect "email/token/:activation_token/:action", :action => /(activation|activate|activated)/, :activation_token => TokenPattern
43
+ end
44
+
45
+ # MEMO: 下記2行のデフォルトルールをコメントアウトしてrake test:functionalsを
46
+ # 実行することにより、リンクチェックを行うことができる
47
+ # NOTE: この二行を有効にするとアプリケーション側の config/routes.rb で定義した
48
+ # ルートが有効にならない
49
+ map.connect ":controller/:action/:id"
50
+ map.connect ":controller/:action/:id.:format"
51
+ end
@@ -0,0 +1,8 @@
1
+
2
+ :enable_starttls_auto: true
3
+ :address: "smtp.gmail.com"
4
+ :port: 587
5
+ :domain: "localhost.localdomain"
6
+ :authentication: :plain
7
+ :user_name: "username"
8
+ :password: "password"
Binary file
data/db/schema.rb ADDED
@@ -0,0 +1,88 @@
1
+ # This file is auto-generated from the current state of the database. Instead of editing this file,
2
+ # please use the migrations feature of Active Record to incrementally modify your database, and
3
+ # then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6
+ # to create the application database on another system, you should be using db:schema:load, not running
7
+ # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
9
+ #
10
+ # It's strongly recommended to check this file into your version control system.
11
+
12
+ ActiveRecord::Schema.define(:version => 20090420020617) do
13
+
14
+ create_table "email_addresses", :force => true do |t|
15
+ t.datetime "created_at", :null => false
16
+ t.string "activation_token", :limit => 40, :null => false
17
+ t.integer "user_id", :null => false
18
+ t.string "email", :limit => 200, :null => false
19
+ t.datetime "activated_at"
20
+ end
21
+
22
+ add_index "email_addresses", ["activated_at"], :name => "index_email_addresses_on_activated_at"
23
+ add_index "email_addresses", ["activation_token"], :name => "index_email_addresses_on_activation_token", :unique => true
24
+ add_index "email_addresses", ["created_at"], :name => "index_email_addresses_on_created_at"
25
+ add_index "email_addresses", ["email", "user_id"], :name => "index_email_addresses_on_email_and_user_id", :unique => true
26
+ add_index "email_addresses", ["user_id"], :name => "index_email_addresses_on_user_id"
27
+
28
+ create_table "email_credentials", :force => true do |t|
29
+ t.datetime "created_at", :null => false
30
+ t.string "activation_token", :limit => 40, :null => false
31
+ t.integer "user_id", :null => false
32
+ t.string "email", :limit => 200, :null => false
33
+ t.string "hashed_password", :limit => 73, :null => false
34
+ t.datetime "activated_at"
35
+ t.datetime "loggedin_at"
36
+ end
37
+
38
+ add_index "email_credentials", ["activated_at"], :name => "index_email_credentials_on_activated_at"
39
+ add_index "email_credentials", ["activation_token"], :name => "index_email_credentials_on_activation_token", :unique => true
40
+ add_index "email_credentials", ["created_at"], :name => "index_email_credentials_on_created_at"
41
+ add_index "email_credentials", ["email"], :name => "index_email_credentials_on_email", :unique => true
42
+ add_index "email_credentials", ["user_id"], :name => "index_email_credentials_on_user_id"
43
+
44
+ create_table "open_id_authentication_associations", :force => true do |t|
45
+ t.integer "issued"
46
+ t.integer "lifetime"
47
+ t.string "handle"
48
+ t.string "assoc_type"
49
+ t.binary "server_url"
50
+ t.binary "secret"
51
+ end
52
+
53
+ create_table "open_id_authentication_nonces", :force => true do |t|
54
+ t.integer "timestamp", :null => false
55
+ t.string "server_url"
56
+ t.string "salt", :null => false
57
+ end
58
+
59
+ create_table "open_id_credentials", :force => true do |t|
60
+ t.datetime "created_at", :null => false
61
+ t.integer "user_id", :null => false
62
+ t.string "identity_url", :limit => 200, :null => false
63
+ t.datetime "loggedin_at"
64
+ end
65
+
66
+ add_index "open_id_credentials", ["identity_url"], :name => "index_open_id_credentials_on_identity_url", :unique => true
67
+ add_index "open_id_credentials", ["user_id"], :name => "index_open_id_credentials_on_user_id"
68
+
69
+ create_table "sessions", :force => true do |t|
70
+ t.datetime "created_at", :null => false
71
+ t.datetime "updated_at", :null => false
72
+ t.string "session_id", :limit => 64, :null => false
73
+ t.text "data"
74
+ end
75
+
76
+ add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id", :unique => true
77
+ add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
78
+
79
+ create_table "users", :force => true do |t|
80
+ t.datetime "created_at", :null => false
81
+ t.datetime "updated_at", :null => false
82
+ t.string "user_token", :limit => 40, :null => false
83
+ t.string "nickname", :limit => 40
84
+ end
85
+
86
+ add_index "users", ["user_token"], :name => "index_users_on_user_token", :unique => true
87
+
88
+ end
data/db/test.sqlite3 ADDED
Binary file
@@ -0,0 +1,15 @@
1
+
2
+ # アクションメーラユーティリティ
3
+ module ActionMailerUtil
4
+ private
5
+
6
+ def build_message(options)
7
+ sent_on(Time.now)
8
+ subject(options[:subject] || raise(ArgumentError))
9
+ from(options[:from] || raise(ArgumentError))
10
+ recipients(options[:recipients] || raise(ArgumentError))
11
+ body(options[:body] || raise(ArgumentError))
12
+
13
+ return nil
14
+ end
15
+ end
data/lib/multi_auth.rb ADDED
@@ -0,0 +1,64 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class MultiAuth
4
+
5
+ class << self
6
+ attr_accessor_with_default :application_name, 'app'
7
+ attr_accessor_with_default :from_address, 'noreply@example.com'
8
+ attr_accessor_with_default :user_model, 'User'
9
+ def setup
10
+ yield self
11
+ end
12
+
13
+ def self.user_model_class
14
+ @user_model.constantize
15
+ end
16
+ end
17
+
18
+ module ClassMethods
19
+ def verify_method_post(options = {})
20
+ verify({
21
+ :method => :post,
22
+ :render => {:text => "Method Not Allowed", :status => 405},
23
+ }.merge(options))
24
+ end
25
+ end
26
+
27
+ module InstanceMethods
28
+
29
+ private
30
+
31
+ def authentication(user_id = session[:user_id])
32
+ @login_user = User.find_by_id(user_id)
33
+ return true
34
+ end
35
+
36
+ def authentication_required
37
+ if @login_user
38
+ return true
39
+ else
40
+ set_error("ログインが必要です。")
41
+ redirect_to(root_path)
42
+ return false
43
+ end
44
+ end
45
+
46
+ def set_notice(message)
47
+ flash[:notice] = @flash_notice = message
48
+ flash[:error] = @flash_error = nil
49
+ end
50
+
51
+ def set_error(message)
52
+ flash[:notice] = @flash_notice = nil
53
+ flash[:error] = @flash_error = message
54
+ end
55
+
56
+ def set_error_now(message)
57
+ flash.now[:notice] = @flash_notice = nil
58
+ flash.now[:error] = @flash_error = message
59
+ end
60
+ end
61
+ end
62
+
63
+ ActionController::Base.__send__(:extend, MultiAuth::ClassMethods)
64
+ ActionController::Base.__send__(:include, MultiAuth::InstanceMethods)
@@ -0,0 +1,98 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # TODO: 不要なメソッドを削除する
4
+ module MultiAuthHelper
5
+
6
+ def production?
7
+ return (RAILS_ENV == "production")
8
+ end
9
+
10
+ def logged_in?
11
+ !!@login_user
12
+ end
13
+
14
+ def rss_auto_discovery(options = {})
15
+ options = options.dup
16
+ title = options.delete(:title) || raise(ArgumentError)
17
+ href = options.delete(:href) || raise(ArgumentError)
18
+ raise(ArgumentError) unless options.empty?
19
+
20
+ return %|<link rel="alternate" type="application/rss+xml" title="#{h(title)}" href="#{h(href)}" />|
21
+ end
22
+
23
+ def additional_head(&block)
24
+ @additional_head_html ||= ""
25
+ @additional_head_html += capture(&block)
26
+ end
27
+
28
+ def side_column(&block)
29
+ @side_column_html ||= ""
30
+ @side_column_html += capture(&block)
31
+ end
32
+
33
+ def even_or_odd(index)
34
+ return %w[even odd][index % 2]
35
+ end
36
+
37
+ def icon16(path, alt = nil)
38
+ return image_tag(
39
+ path,
40
+ :width => 16,
41
+ :height => 16,
42
+ :alt => alt,
43
+ :title => alt)
44
+ end
45
+
46
+ def enable_icon
47
+ return icon16("icons/fam/tick.png", "有効")
48
+ end
49
+
50
+ def disable_icon
51
+ return icon16("icons/fam/stop.png", "無効")
52
+ end
53
+
54
+ def enable_or_disable_icon(enable)
55
+ return (enable ? enable_icon : disable_icon)
56
+ end
57
+
58
+ def add_icon
59
+ return icon16("icons/fam/add.png", "追加")
60
+ end
61
+
62
+ def edit_icon
63
+ return icon16("icons/fam/cog.png", "編集")
64
+ end
65
+
66
+ def delete_icon
67
+ return icon16("icons/fam/bin.png", "削除")
68
+ end
69
+
70
+ def help_icon(alt = "ヘルプ")
71
+ return icon16("icons/fam/help.png", alt)
72
+ end
73
+
74
+ def feed_icon
75
+ return icon16("icons/fam/feed.png", "フィード")
76
+ end
77
+
78
+ def csv_icon
79
+ return icon16("icons/fam/table_save.png", "CSV")
80
+ end
81
+
82
+ def yyyymmdd(time, null = "-")
83
+ return time.try(:strftime, "%Y年%m月%d日") || null
84
+ end
85
+
86
+ def yyyymmdd_hhmm(time, null = "-")
87
+ return time.try(:strftime, "%Y年%m月%d日 %H時%M分") || null
88
+ end
89
+
90
+ def mmdd_hhmm(time, null = "-")
91
+ return time.try(:strftime, "%m月%d日 %H時%M分") || null
92
+ end
93
+
94
+ def user_nickname(user, nickname_column = :nickname)
95
+ nickname = user.__send__(nickname_column)
96
+ return (nickname.blank? ? h("名無しさん") : h(nickname))
97
+ end
98
+ end
@@ -0,0 +1,106 @@
1
+
2
+ module NoticeFormatter
3
+ def self.replace_keywords(str, keywords)
4
+ return keywords.inject(str.dup) { |memo, (key, value)|
5
+ memo.gsub!(/\{#{Regexp.escape(key)}\}/, value)
6
+ memo
7
+ }
8
+ end
9
+
10
+ def self.add_namespace(name, keywords)
11
+ return keywords.inject({}) { |memo, (key, value)|
12
+ memo[name + ":" + key] = value
13
+ memo
14
+ }
15
+ end
16
+
17
+ def self.format_integer_value(value)
18
+ return (value.nil? ? "-" : value.to_s)
19
+ end
20
+
21
+ def self.format_integer_json_value(value)
22
+ return value.to_json
23
+ end
24
+
25
+ def self.format_string_value(value)
26
+ return (value.blank? ? "-" : value.to_s)
27
+ end
28
+
29
+ def self.format_string_json_value(value)
30
+ return (value.blank? ? nil.to_json : value.to_json)
31
+ end
32
+
33
+ def self.format_part_of_date(date)
34
+ return {
35
+ "date" => date.try(:strftime, "%Y-%m-%d") || "-",
36
+ "date:json" => date.try(:strftime, '"%Y-%m-%d"') || "null",
37
+ "date:ja" => date.try(:strftime, "%Y年%m月%d日") || "-",
38
+ "yyyy" => date.try(:strftime, "%Y") || "-",
39
+ "mm" => date.try(:strftime, "%m") || "-",
40
+ "dd" => date.try(:strftime, "%d") || "-",
41
+ }
42
+ end
43
+
44
+ def self.format_part_of_time(time)
45
+ return {
46
+ "time" => time.try(:strftime, "%H:%M:%S") || "-",
47
+ "time:json" => time.try(:strftime, '"%H:%M:%S"') || "null",
48
+ "time:ja" => time.try(:strftime, "%H時%M分%S秒") || "-",
49
+ "hh" => time.try(:strftime, "%H") || "-",
50
+ "nn" => time.try(:strftime, "%M") || "-",
51
+ "ss" => time.try(:strftime, "%S") || "-",
52
+ }
53
+ end
54
+
55
+ def self.format_part_of_datetime(datetime)
56
+ result = {
57
+ "datetime" => datetime.try(:strftime, "%Y-%m-%d %H:%M:%S") || "-",
58
+ "datetime:json" => datetime.try(:strftime, '"%Y-%m-%d %H:%M:%S"') || "null",
59
+ "datetime:ja" => datetime.try(:strftime, "%Y年%m月%d日 %H時%M分%S秒") || "-",
60
+ }
61
+ result.merge!(self.format_part_of_date(datetime))
62
+ result.merge!(self.format_part_of_time(datetime))
63
+ return result
64
+ end
65
+
66
+ def self.format_part_of_user(user)
67
+ return {
68
+ "user:token" => self.format_string_value(user.try(:user_token)),
69
+ "user:token:json" => self.format_string_json_value(user.try(:user_token)),
70
+ "user:nickname" => self.format_string_value(user.try(:nickname)),
71
+ "user:nickname:json" => self.format_string_json_value(user.try(:nickname)),
72
+ }
73
+ end
74
+
75
+ def self.format_part_of_device(device)
76
+ return {
77
+ "device:token" => self.format_string_value(device.try(:device_token)),
78
+ "device:token:json" => self.format_string_json_value(device.try(:device_token)),
79
+ "device:name" => self.format_string_value(device.try(:name)),
80
+ "device:name:json" => self.format_string_json_value(device.try(:name)),
81
+ }
82
+ end
83
+
84
+ def self.format_part_of_event(event)
85
+ result = {
86
+ "event:trigger-operator" => self.format_string_value(event.try(:trigger_operator_symbol)),
87
+ "event:trigger-operator:json" => self.format_string_json_value(event.try(:trigger_operator_symbol)),
88
+ "event:trigger-level" => self.format_integer_value(event.try(:trigger_level)),
89
+ "event:trigger-level:json" => self.format_integer_json_value(event.try(:trigger_level)),
90
+ "event:observed-level" => self.format_integer_value(event.try(:observed_level)),
91
+ "event:observed-level:json" => self.format_integer_json_value(event.try(:observed_level)),
92
+ }
93
+ result.merge!(self.add_namespace("event:created-at", self.format_part_of_datetime(event.try(:created_at))))
94
+ result.merge!(self.add_namespace("event:observed-at", self.format_part_of_datetime(event.try(:observed_at))))
95
+ return result
96
+ end
97
+
98
+ def self.format_event(event, time = Time.now)
99
+ result = {}
100
+ result.merge!(self.add_namespace("now", self.format_part_of_datetime(time)))
101
+ result.merge!(self.format_part_of_event(event))
102
+ result.merge!(self.format_part_of_device(event.try(:device)))
103
+ result.merge!(self.format_part_of_user(event.try(:device).try(:user)))
104
+ return result
105
+ end
106
+ end
@@ -0,0 +1,12 @@
1
+ # -*- coding: utf-8 -*-
2
+ module OpenIdAuthentication
3
+ class Result
4
+ ERROR_MESSAGES.update({
5
+ :missing => "OpenID サーバが見つかりませんでした。",
6
+ :invalid => "OpenID が不正です。",
7
+ :canceled => "OpenID の検証がキャンセルされました。",
8
+ :failed => "OpenID の検証が失敗しました。",
9
+ :setup_needed => "OpenID の検証には準備が必要です。",
10
+ })
11
+ end
12
+ end
data/lib/token_util.rb ADDED
@@ -0,0 +1,18 @@
1
+
2
+ module TokenUtil
3
+ def self.create_token(size)
4
+ return size.times.map { rand(16).to_s(16) }.join
5
+ end
6
+
7
+ def self.create_unique_token(klass, column, size)
8
+ begin
9
+ token = self.create_token(size)
10
+ end while klass.exists?(column => token)
11
+
12
+ return token
13
+ end
14
+
15
+ def self.create_token_regexp(size)
16
+ return /\A[0-9a-f]{#{size}}\z/
17
+ end
18
+ end
data/public/404.html ADDED
@@ -0,0 +1,92 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <title>404: Not Found</title>
6
+ <style type="text/css">
7
+ *
8
+ {
9
+ margin: 0;
10
+ padding: 0;
11
+ }
12
+ #dialog
13
+ {
14
+ position: absolute;
15
+ top: 50%;
16
+ left: 50%;
17
+ width: 650px;
18
+ height: 200px;
19
+ margin: -100px 0px 0px -325px;
20
+ }
21
+ #code-outer
22
+ {
23
+ position: absolute;
24
+ top: 0px;
25
+ left: 0px;
26
+ width: 249px;
27
+ height: 200px;
28
+ border-style: solid;
29
+ border-color: #CCCCCC;
30
+ border-width: 0px 1px 0px 0px;
31
+ }
32
+ #code-inner
33
+ {
34
+ font-size: 150px;
35
+ line-height: 200px;
36
+ text-align: center;
37
+ color: #999999;
38
+ }
39
+ #message
40
+ {
41
+ position: absolute;
42
+ top: 0px;
43
+ left: 250px;
44
+ width: 400px;
45
+ height: 200px;
46
+ }
47
+ #status-outer
48
+ {
49
+ height: 75px;
50
+ }
51
+ #status-inner
52
+ {
53
+ padding: 40px 0px 0px 10px;
54
+ font-size: 24px;
55
+ font-weight: bold;
56
+ color: #999999;
57
+ }
58
+ #description-outer
59
+ {
60
+ height: 124px;
61
+ border-style: solid;
62
+ border-color: #CCCCCC;
63
+ border-width: 1px 0px 0px 0px;
64
+ }
65
+ #description-inner
66
+ {
67
+ padding: 10px;
68
+ font-size: 14px;
69
+ line-height: 24px;
70
+ color: #999999;
71
+ }
72
+ </style>
73
+ </head>
74
+ <body>
75
+ <div id="dialog">
76
+ <div id="code-outer">
77
+ <div id="code-inner">404</div>
78
+ </div>
79
+ <div id="message">
80
+ <div id="status-outer">
81
+ <div id="status-inner">Not Found</div>
82
+ </div>
83
+ <div id="description-outer">
84
+ <div id="description-inner">
85
+ <div>要求されたURLは見つかりませんでした。URLが間違っている可能性があります。</div>
86
+ <div>The requested URL was not found on this server.</div>
87
+ </div>
88
+ </div>
89
+ </div>
90
+ </div>
91
+ </body>
92
+ </html>
data/public/422.html ADDED
@@ -0,0 +1,91 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <title>422: Unprocessable Entity</title>
6
+ <style type="text/css">
7
+ *
8
+ {
9
+ margin: 0;
10
+ padding: 0;
11
+ }
12
+ #dialog
13
+ {
14
+ position: absolute;
15
+ top: 50%;
16
+ left: 50%;
17
+ width: 650px;
18
+ height: 200px;
19
+ margin: -100px 0px 0px -325px;
20
+ }
21
+ #code-outer
22
+ {
23
+ position: absolute;
24
+ top: 0px;
25
+ left: 0px;
26
+ width: 249px;
27
+ height: 200px;
28
+ border-style: solid;
29
+ border-color: #CCCCCC;
30
+ border-width: 0px 1px 0px 0px;
31
+ }
32
+ #code-inner
33
+ {
34
+ font-size: 150px;
35
+ line-height: 200px;
36
+ text-align: center;
37
+ color: #999999;
38
+ }
39
+ #message
40
+ {
41
+ position: absolute;
42
+ top: 0px;
43
+ left: 250px;
44
+ width: 400px;
45
+ height: 200px;
46
+ }
47
+ #status-outer
48
+ {
49
+ height: 75px;
50
+ }
51
+ #status-inner
52
+ {
53
+ padding: 40px 0px 0px 10px;
54
+ font-size: 24px;
55
+ font-weight: bold;
56
+ color: #999999;
57
+ }
58
+ #description-outer
59
+ {
60
+ height: 124px;
61
+ border-style: solid;
62
+ border-color: #CCCCCC;
63
+ border-width: 1px 0px 0px 0px;
64
+ }
65
+ #description-inner
66
+ {
67
+ padding: 10px;
68
+ font-size: 14px;
69
+ line-height: 24px;
70
+ color: #999999;
71
+ }
72
+ </style>
73
+ </head>
74
+ <body>
75
+ <div id="dialog">
76
+ <div id="code-outer">
77
+ <div id="code-inner">422</div>
78
+ </div>
79
+ <div id="message">
80
+ <div id="status-outer">
81
+ <div id="status-inner">Unprocessable Entity</div>
82
+ </div>
83
+ <div id="description-outer">
84
+ <div id="description-inner">
85
+ <div>要求されたURLは処理できませんでした。</div>
86
+ </div>
87
+ </div>
88
+ </div>
89
+ </div>
90
+ </body>
91
+ </html>