multi_auth 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +36 -0
- data/app/controllers/application_controller.rb +11 -0
- data/app/controllers/auth/email_controller.rb +34 -0
- data/app/controllers/auth/open_id_controller.rb +43 -0
- data/app/controllers/auth_controller.rb +24 -0
- data/app/controllers/credentials/email_controller.rb +156 -0
- data/app/controllers/credentials/open_id_controller.rb +85 -0
- data/app/controllers/credentials_controller.rb +14 -0
- data/app/controllers/signup/email_controller.rb +132 -0
- data/app/controllers/signup/open_id_controller.rb +62 -0
- data/app/controllers/signup_controller.rb +8 -0
- data/app/helpers/application_helper.rb +5 -0
- data/app/models/activation_mailer.rb +114 -0
- data/app/models/email_credential.rb +89 -0
- data/app/models/email_credential_edit_form.rb +52 -0
- data/app/models/email_login_form.rb +24 -0
- data/app/models/email_password_edit_form.rb +36 -0
- data/app/models/open_id_credential.rb +33 -0
- data/app/models/open_id_login_form.rb +17 -0
- data/app/models/session.rb +19 -0
- data/app/models/user.rb +37 -0
- data/app/views/activation_mailer/complete_for_credential.erb +4 -0
- data/app/views/activation_mailer/complete_for_notice.erb +4 -0
- data/app/views/activation_mailer/complete_for_signup.erb +4 -0
- data/app/views/activation_mailer/request_for_credential.erb +11 -0
- data/app/views/activation_mailer/request_for_notice.erb +11 -0
- data/app/views/activation_mailer/request_for_signup.erb +11 -0
- data/app/views/auth/email/index.html.erb +90 -0
- data/app/views/auth/logged_in.html.erb +21 -0
- data/app/views/auth/logged_out.html.erb +21 -0
- data/app/views/auth/open_id/index.html.erb +16 -0
- data/app/views/credentials/email/activated.html.erb +4 -0
- data/app/views/credentials/email/activation.html.erb +15 -0
- data/app/views/credentials/email/created.html.erb +15 -0
- data/app/views/credentials/email/delete.html.erb +20 -0
- data/app/views/credentials/email/edit_password.html.erb +31 -0
- data/app/views/credentials/email/new.html.erb +36 -0
- data/app/views/credentials/index.html.erb +88 -0
- data/app/views/credentials/open_id/delete.html.erb +20 -0
- data/app/views/credentials/open_id/new.html.erb +26 -0
- data/app/views/signup/email/_progress.html.erb +14 -0
- data/app/views/signup/email/activated.html.erb +9 -0
- data/app/views/signup/email/activation.html.erb +27 -0
- data/app/views/signup/email/created.html.erb +14 -0
- data/app/views/signup/email/index.html.erb +34 -0
- data/app/views/signup/email/validated.html.erb +21 -0
- data/app/views/signup/index.html.erb +51 -0
- data/app/views/signup/open_id/authenticated.html.erb +15 -0
- data/app/views/signup/open_id/created.html.erb +6 -0
- data/app/views/signup/open_id/index.html.erb +16 -0
- data/config/boot.rb +110 -0
- data/config/database.yml +22 -0
- data/config/database.yml.sqlite3 +22 -0
- data/config/environment.rb +62 -0
- data/config/routes.rb +51 -0
- data/config/smtp.yml.example +8 -0
- data/db/development.sqlite3 +0 -0
- data/db/schema.rb +88 -0
- data/db/test.sqlite3 +0 -0
- data/lib/action_mailer_util.rb +15 -0
- data/lib/multi_auth.rb +64 -0
- data/lib/multi_auth_helper.rb +98 -0
- data/lib/notice_formatter.rb +106 -0
- data/lib/open_id_authentication/result.rb +12 -0
- data/lib/token_util.rb +18 -0
- data/public/404.html +92 -0
- data/public/422.html +91 -0
- data/public/500.html +92 -0
- data/public/503.html +92 -0
- data/public/favicon.ico +0 -0
- data/public/images/battery/cell.png +0 -0
- data/public/images/battery/level-green.png +0 -0
- data/public/images/battery/level-orange.png +0 -0
- data/public/images/battery/level-red.png +0 -0
- data/public/images/battery/level-yellow.png +0 -0
- data/public/images/battery/style.html +82 -0
- data/public/images/favicons/livedoor.png +0 -0
- data/public/images/favicons/mixi.png +0 -0
- data/public/images/favicons/yahoo.png +0 -0
- data/public/images/h1-back.png +0 -0
- data/public/images/icons/fam/add.png +0 -0
- data/public/images/icons/fam/bin.png +0 -0
- data/public/images/icons/fam/bomb.png +0 -0
- data/public/images/icons/fam/cog.png +0 -0
- data/public/images/icons/fam/delete.png +0 -0
- data/public/images/icons/fam/email-with-desc.png +0 -0
- data/public/images/icons/fam/email.png +0 -0
- data/public/images/icons/fam/feed.png +0 -0
- data/public/images/icons/fam/help.png +0 -0
- data/public/images/icons/fam/key-with-desc.png +0 -0
- data/public/images/icons/fam/key.png +0 -0
- data/public/images/icons/fam/lightning.png +0 -0
- data/public/images/icons/fam/plugin.png +0 -0
- data/public/images/icons/fam/stop.png +0 -0
- data/public/images/icons/fam/table_save.png +0 -0
- data/public/images/icons/fam/tick.png +0 -0
- data/public/images/icons/fam/user.png +0 -0
- data/public/images/icons/fam/vcard.png +0 -0
- data/public/images/icons/openid-with-desc.png +0 -0
- data/public/images/icons/openid.png +0 -0
- data/public/images/logo-back.png +0 -0
- data/public/images/logo.png +0 -0
- data/public/images/side-column-back.png +0 -0
- data/public/javascripts/application.js +2 -0
- data/public/javascripts/controls.js +963 -0
- data/public/javascripts/dragdrop.js +973 -0
- data/public/javascripts/effects.js +1128 -0
- data/public/javascripts/prototype.js +4320 -0
- data/public/robots.txt +5 -0
- data/public/stylesheets/application.css +365 -0
- data/public/stylesheets/auth.css +22 -0
- data/public/stylesheets/home.css +114 -0
- data/rails/init.rb +24 -0
- data/test/functional/auth/email_controller_test.rb +102 -0
- data/test/functional/auth/open_id_controller_test.rb +76 -0
- data/test/functional/auth_controller_test.rb +74 -0
- data/test/functional/credentials/email_controller_test.rb +488 -0
- data/test/functional/credentials/open_id_controller_test.rb +308 -0
- data/test/functional/credentials_controller_test.rb +49 -0
- data/test/functional/signup/email_controller_test.rb +369 -0
- data/test/functional/signup/open_id_controller_test.rb +44 -0
- data/test/functional/signup_controller_test.rb +17 -0
- data/test/performance/browsing_test.rb +9 -0
- data/test/test_helper.rb +82 -0
- data/test/unit/action_mailer_util_test.rb +63 -0
- data/test/unit/activation_mailer_test.rb +181 -0
- data/test/unit/email_credential_edit_form_test.rb +173 -0
- data/test/unit/email_credential_test.rb +324 -0
- data/test/unit/email_login_form_test.rb +76 -0
- data/test/unit/email_password_edit_form_test.rb +117 -0
- data/test/unit/helpers/auth_helper_test.rb +4 -0
- data/test/unit/helpers/credentials/email_helper_test.rb +4 -0
- data/test/unit/helpers/credentials/open_id_helper_test.rb +4 -0
- data/test/unit/helpers/credentials_helper_test.rb +4 -0
- data/test/unit/helpers/email_auth_helper_test.rb +4 -0
- data/test/unit/helpers/email_signup_helper_test.rb +4 -0
- data/test/unit/helpers/open_id_auth_helper_test.rb +4 -0
- data/test/unit/helpers/open_id_signup_helper_test.rb +4 -0
- data/test/unit/helpers/password_auth_helper_test.rb +4 -0
- data/test/unit/helpers/password_signup_helper_test.rb +4 -0
- data/test/unit/helpers/signup_helper_test.rb +4 -0
- data/test/unit/notice_formatter_test.rb +153 -0
- data/test/unit/open_id_credential_test.rb +108 -0
- data/test/unit/open_id_login_form_test.rb +57 -0
- data/test/unit/session_test.rb +53 -0
- data/test/unit/token_util_test.rb +51 -0
- data/test/unit/user_test.rb +177 -0
- metadata +220 -0
data/README
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
MultiAuth
|
|
2
|
+
=========
|
|
3
|
+
|
|
4
|
+
This engine provides basic login functionality for your Rails applications.
|
|
5
|
+
|
|
6
|
+
Install
|
|
7
|
+
=======
|
|
8
|
+
|
|
9
|
+
$ sudo gem install okkez-multi_auth
|
|
10
|
+
|
|
11
|
+
Setup
|
|
12
|
+
=====
|
|
13
|
+
|
|
14
|
+
$ ruby script/generate open_id_authentication_tables create_open_id_authentication_tables
|
|
15
|
+
|
|
16
|
+
Create migrations for open_id_authentication.
|
|
17
|
+
|
|
18
|
+
$ rake multi_auth:copy:all
|
|
19
|
+
|
|
20
|
+
Copy migrations, stylesheets and images from multi_auth plugin.
|
|
21
|
+
|
|
22
|
+
$ rake db:migrate
|
|
23
|
+
|
|
24
|
+
You must have a model 'User'. User model has any columns which you want to add.
|
|
25
|
+
|
|
26
|
+
Customize
|
|
27
|
+
=========
|
|
28
|
+
|
|
29
|
+
If you want to custom views, you create RAILS_ROOT/app/view/{activation_mailer,auth,credentials,signup}/*.
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
TODO
|
|
33
|
+
====
|
|
34
|
+
|
|
35
|
+
see TODO.ja
|
|
36
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
class ApplicationController < ActionController::Base
|
|
4
|
+
helper :all # include all helpers, all the time
|
|
5
|
+
protect_from_forgery # See ActionController::RequestForgeryProtection for details
|
|
6
|
+
before_filter { |c| c.instance_eval { @topic_path = [] }; true }
|
|
7
|
+
|
|
8
|
+
GetText.locale = "ja"
|
|
9
|
+
init_gettext "multi_auth"
|
|
10
|
+
|
|
11
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# メール認証
|
|
4
|
+
class Auth::EmailController < ApplicationController
|
|
5
|
+
filter_parameter_logging :password
|
|
6
|
+
verify_method_post :only => [:login]
|
|
7
|
+
|
|
8
|
+
# GET /auth/email
|
|
9
|
+
def index
|
|
10
|
+
session[:user_id] = nil
|
|
11
|
+
@login_form = EmailLoginForm.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# POST /auth/email/login
|
|
15
|
+
def login
|
|
16
|
+
session[:user_id] = nil
|
|
17
|
+
@login_form = EmailLoginForm.new(params[:login_form])
|
|
18
|
+
|
|
19
|
+
if @login_form.valid?
|
|
20
|
+
@email_credential = @login_form.authenticate
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
if @email_credential
|
|
24
|
+
@email_credential.login!
|
|
25
|
+
@login_user = @email_credential.user
|
|
26
|
+
session[:user_id] = @login_user.id
|
|
27
|
+
redirect_to(:controller => "/auth", :action => "logged_in")
|
|
28
|
+
else
|
|
29
|
+
@login_form.password = nil
|
|
30
|
+
set_error_now("メールアドレス、またはパスワードが違います。")
|
|
31
|
+
render(:action => "index")
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# OpenID認証
|
|
4
|
+
# FIXME: 全体的に実装を整理
|
|
5
|
+
class Auth::OpenIdController < ApplicationController
|
|
6
|
+
verify_method_post :only => [:login]
|
|
7
|
+
|
|
8
|
+
# GET /auth/open_id
|
|
9
|
+
def index
|
|
10
|
+
session[:user_id] = nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# POST /auth/open_id/login
|
|
14
|
+
# GET /auth/open_id/login
|
|
15
|
+
def login
|
|
16
|
+
openid_url = params[:openid_url]
|
|
17
|
+
|
|
18
|
+
authenticate_with_open_id(openid_url) { |result, identity_url, sreg|
|
|
19
|
+
if result.successful?
|
|
20
|
+
@open_id_credential = OpenIdCredential.find_by_identity_url(identity_url)
|
|
21
|
+
if @open_id_credential
|
|
22
|
+
@open_id_credential.login!
|
|
23
|
+
session[:user_id] = @open_id_credential.user.id
|
|
24
|
+
flash[:notice] = "ログインしました。"
|
|
25
|
+
redirect_to(root_path)
|
|
26
|
+
else
|
|
27
|
+
flash[:notice] = "OpenID がまだ登録されていません。"
|
|
28
|
+
redirect_to(:controller => "signup/open_id", :action => "index")
|
|
29
|
+
end
|
|
30
|
+
else
|
|
31
|
+
failed_login(result.message)
|
|
32
|
+
end
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def failed_login(message)
|
|
39
|
+
flash[:error] = message
|
|
40
|
+
redirect_to(root_path)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# 認証
|
|
4
|
+
class AuthController < ApplicationController
|
|
5
|
+
verify_method_post :only => [:logout]
|
|
6
|
+
|
|
7
|
+
# GET /auth/logged_in
|
|
8
|
+
def logged_in
|
|
9
|
+
@return_path = params[:return_path]
|
|
10
|
+
@return_path = root_path if @return_path.blank?
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# POST /auth/logout
|
|
14
|
+
def logout
|
|
15
|
+
reset_session
|
|
16
|
+
redirect_to(:action => "logged_out")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# GET /auth/logged_out
|
|
20
|
+
def logged_out
|
|
21
|
+
@return_path = params[:return_path]
|
|
22
|
+
@return_path = root_path if @return_path.blank?
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
|
|
2
|
+
# メール認証情報コントローラ
|
|
3
|
+
class Credentials::EmailController < ApplicationController
|
|
4
|
+
EditFormClass = EmailCredentialEditForm
|
|
5
|
+
|
|
6
|
+
verify_method_post :only => [:create, :update_password, :destroy, :activate]
|
|
7
|
+
before_filter :authentication
|
|
8
|
+
before_filter :authentication_required, :except => [:activation, :activate, :activated]
|
|
9
|
+
before_filter :required_param_email_credential_id, :only => [:created, :edit_password, :update_password, :delete, :destroy]
|
|
10
|
+
before_filter :specified_email_credential_belongs_to_login_user, :only => [:created, :edit_password, :update_password, :delete, :destroy]
|
|
11
|
+
before_filter :required_param_activation_token, :only => [:activation, :activate, :activated]
|
|
12
|
+
before_filter :only_inactive_email_credential, :only => [:activation, :activate]
|
|
13
|
+
|
|
14
|
+
# GET /credentials/email/new
|
|
15
|
+
def new
|
|
16
|
+
@edit_form = EditFormClass.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# GET /credentials/email/create
|
|
20
|
+
def create
|
|
21
|
+
@edit_form = EditFormClass.new(params[:edit_form])
|
|
22
|
+
|
|
23
|
+
@email_credential = @login_user.email_credentials.build
|
|
24
|
+
@email_credential.attributes = @edit_form.to_email_credential_hash
|
|
25
|
+
|
|
26
|
+
if @edit_form.valid? && @email_credential.save
|
|
27
|
+
# TODO: テスト
|
|
28
|
+
@activation_url = url_for(
|
|
29
|
+
:only_path => false,
|
|
30
|
+
:controller => "credentials/email",
|
|
31
|
+
:action => "activation",
|
|
32
|
+
:activation_token => @email_credential.activation_token)
|
|
33
|
+
|
|
34
|
+
# TODO: テスト
|
|
35
|
+
# MEMO: 即時性を優先し、非同期化しない
|
|
36
|
+
ActivationMailer.deliver_request_for_credential(
|
|
37
|
+
:recipients => @email_credential.email,
|
|
38
|
+
:activation_url => @activation_url)
|
|
39
|
+
|
|
40
|
+
set_notice("メール認証情報を追加しました。")
|
|
41
|
+
redirect_to(:action => "created", :email_credential_id => @email_credential.id)
|
|
42
|
+
else
|
|
43
|
+
@edit_form.password = nil
|
|
44
|
+
@edit_form.password_confirmation = nil
|
|
45
|
+
set_error_now("入力内容を確認してください。")
|
|
46
|
+
render(:action => "new")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# GET /credential/email/:email_credential_id/created
|
|
51
|
+
def created
|
|
52
|
+
# nop
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# GET /credential/email/:email_credential_id/edit_password
|
|
56
|
+
def edit_password
|
|
57
|
+
@edit_form = EmailPasswordEditForm.new
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# POST /credential/email/:email_credential_id/update_password
|
|
61
|
+
def update_password
|
|
62
|
+
@edit_form = EmailPasswordEditForm.new(params[:edit_form])
|
|
63
|
+
|
|
64
|
+
@email_credential.attributes = @edit_form.to_email_credential_hash
|
|
65
|
+
|
|
66
|
+
if @edit_form.valid? && @email_credential.save
|
|
67
|
+
set_notice("パスワードを変更しました。")
|
|
68
|
+
redirect_to(:controller => "/credentials")
|
|
69
|
+
else
|
|
70
|
+
@edit_form.password = nil
|
|
71
|
+
@edit_form.password_confirmation = nil
|
|
72
|
+
set_error_now("入力内容を確認してください。")
|
|
73
|
+
render(:action => "edit_password")
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# GET /credential/email/:email_credential_id/delete
|
|
78
|
+
def delete
|
|
79
|
+
# nop
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# POST /credential/email/:email_credential_id/destroy
|
|
83
|
+
def destroy
|
|
84
|
+
@email_credential.destroy
|
|
85
|
+
|
|
86
|
+
set_notice("メール認証情報を削除しました。")
|
|
87
|
+
redirect_to(:controller => "/credentials")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# GET /credential/email/token/:activation_token/activation
|
|
91
|
+
def activation
|
|
92
|
+
# nop
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# POST /credential/email/token/:activation_token/activate
|
|
96
|
+
def activate
|
|
97
|
+
@email_credential.activate!
|
|
98
|
+
|
|
99
|
+
# TODO: テスト
|
|
100
|
+
# MEMO: 即時性を優先し、非同期化しない
|
|
101
|
+
ActivationMailer.deliver_complete_for_credential(
|
|
102
|
+
:recipients => @email_credential.email)
|
|
103
|
+
|
|
104
|
+
redirect_to(:action => "activated")
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# GET /credential/email/token/:activation_token/activated
|
|
108
|
+
def activated
|
|
109
|
+
# nop
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
# FIXME: login_userに属することを同時に確認
|
|
115
|
+
def required_param_email_credential_id(email_credential_id = params[:email_credential_id])
|
|
116
|
+
@email_credential = EmailCredential.find_by_id(email_credential_id)
|
|
117
|
+
if @email_credential
|
|
118
|
+
return true
|
|
119
|
+
else
|
|
120
|
+
set_error("メール認証情報IDが正しくありません。")
|
|
121
|
+
redirect_to(root_path)
|
|
122
|
+
return false
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def specified_email_credential_belongs_to_login_user
|
|
127
|
+
if @email_credential.user_id == @login_user.id
|
|
128
|
+
return true
|
|
129
|
+
else
|
|
130
|
+
set_error("メール認証情報IDが正しくありません。")
|
|
131
|
+
redirect_to(root_path)
|
|
132
|
+
return false
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def required_param_activation_token(activation_token = params[:activation_token])
|
|
137
|
+
@email_credential = EmailCredential.find_by_activation_token(activation_token)
|
|
138
|
+
if @email_credential
|
|
139
|
+
return true
|
|
140
|
+
else
|
|
141
|
+
set_error("アクティベーショントークンが正しくありません。")
|
|
142
|
+
redirect_to(root_path)
|
|
143
|
+
return false
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def only_inactive_email_credential
|
|
148
|
+
if @email_credential.activated?
|
|
149
|
+
set_error("既にアクティベーションされています。")
|
|
150
|
+
redirect_to(root_path)
|
|
151
|
+
return false
|
|
152
|
+
else
|
|
153
|
+
return true
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
|
|
2
|
+
# OpenID認証情報コントローラ
|
|
3
|
+
class Credentials::OpenIdController < ApplicationController
|
|
4
|
+
verify_method_post :only => [:destroy]
|
|
5
|
+
before_filter :authentication
|
|
6
|
+
before_filter :authentication_required
|
|
7
|
+
before_filter :required_param_open_id_credential_id, :only => [:delete, :destroy]
|
|
8
|
+
before_filter :specified_open_id_credential_belongs_to_login_user, :only => [:delete, :destroy]
|
|
9
|
+
|
|
10
|
+
# GET /credentials/open_id/new
|
|
11
|
+
def new
|
|
12
|
+
@login_form = OpenIdLoginForm.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# POST /credentials/open_id/create
|
|
16
|
+
# GET /credentials/open_id/create
|
|
17
|
+
def create
|
|
18
|
+
@login_form = OpenIdLoginForm.new(params[:login_form])
|
|
19
|
+
|
|
20
|
+
if params[:open_id_complete].nil? && !@login_form.valid?
|
|
21
|
+
set_error_now("入力内容を確認してください。")
|
|
22
|
+
render(:action => "new")
|
|
23
|
+
return
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
authenticate_with_open_id(@login_form.openid_url) { |result, identity_url|
|
|
27
|
+
@login_form.openid_url = identity_url
|
|
28
|
+
@status = result.status
|
|
29
|
+
|
|
30
|
+
if result.successful?
|
|
31
|
+
@open_id_credential = @login_user.open_id_credentials.find_or_initialize_by_identity_url(identity_url)
|
|
32
|
+
|
|
33
|
+
if @open_id_credential.new_record?
|
|
34
|
+
@open_id_credential.save!
|
|
35
|
+
|
|
36
|
+
set_notice("OpenID認証情報を追加しました。")
|
|
37
|
+
redirect_to(:controller => "/credentials", :action => "index")
|
|
38
|
+
else
|
|
39
|
+
set_error_now("既に使用されているOpenIDです。")
|
|
40
|
+
render(:action => "new")
|
|
41
|
+
end
|
|
42
|
+
else
|
|
43
|
+
set_error_now(result.message)
|
|
44
|
+
render(:action => "new")
|
|
45
|
+
end
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# GET /credential/open_id/:open_id_credential_id/delete
|
|
50
|
+
def delete
|
|
51
|
+
# nop
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# POST /credential/open_id/:open_id_credential_id/destroy
|
|
55
|
+
def destroy
|
|
56
|
+
@open_id_credential.destroy
|
|
57
|
+
|
|
58
|
+
set_notice("OpenID認証情報を削除しました。")
|
|
59
|
+
redirect_to(:controller => "/credentials")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
# FIXME: login_userに属することを同時に確認
|
|
65
|
+
def required_param_open_id_credential_id(open_id_credential_id = params[:open_id_credential_id])
|
|
66
|
+
@open_id_credential = OpenIdCredential.find_by_id(open_id_credential_id)
|
|
67
|
+
if @open_id_credential
|
|
68
|
+
return true
|
|
69
|
+
else
|
|
70
|
+
set_error("OpenID認証情報IDが正しくありません。")
|
|
71
|
+
redirect_to(root_path)
|
|
72
|
+
return false
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def specified_open_id_credential_belongs_to_login_user
|
|
77
|
+
if @open_id_credential.user_id == @login_user.id
|
|
78
|
+
return true
|
|
79
|
+
else
|
|
80
|
+
set_error("OpenID認証情報IDが正しくありません。")
|
|
81
|
+
redirect_to(root_path)
|
|
82
|
+
return false
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
# 認証情報コントローラ
|
|
3
|
+
class CredentialsController < ApplicationController
|
|
4
|
+
before_filter :authentication
|
|
5
|
+
before_filter :authentication_required
|
|
6
|
+
|
|
7
|
+
# GET /credentials
|
|
8
|
+
def index
|
|
9
|
+
@open_id_credentials = @login_user.open_id_credentials.all(
|
|
10
|
+
:order => "open_id_credentials.identity_url ASC")
|
|
11
|
+
@email_credentials = @login_user.email_credentials.all(
|
|
12
|
+
:order => "email_credentials.email ASC")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# メール認証情報サインアップ
|
|
4
|
+
class Signup::EmailController < ApplicationController
|
|
5
|
+
EditFormClass = EmailCredentialEditForm
|
|
6
|
+
|
|
7
|
+
filter_parameter_logging :password
|
|
8
|
+
verify_method_post :only => [:validate, :create, :activate]
|
|
9
|
+
before_filter :clear_session_user_id, :only => [:index, :validate, :validated, :create, :created, :activation, :activate, :activated]
|
|
10
|
+
before_filter :clear_session_signup_form, :only => [:index, :validate, :activation, :activate, :activated]
|
|
11
|
+
|
|
12
|
+
# GET /signup/email
|
|
13
|
+
def index
|
|
14
|
+
@signup_form = EditFormClass.new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# POST /signup/email/validate
|
|
18
|
+
def validate
|
|
19
|
+
@signup_form = EditFormClass.new(params[:signup_form])
|
|
20
|
+
|
|
21
|
+
if @signup_form.valid?
|
|
22
|
+
session[:signup_form] = @signup_form.attributes
|
|
23
|
+
redirect_to(:action => "validated")
|
|
24
|
+
else
|
|
25
|
+
@signup_form.password = nil
|
|
26
|
+
@signup_form.password_confirmation = nil
|
|
27
|
+
set_error_now("入力内容を確認してください。")
|
|
28
|
+
render(:action => "index")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# GET /signup/email/validated
|
|
33
|
+
def validated
|
|
34
|
+
@signup_form = EditFormClass.new(session[:signup_form])
|
|
35
|
+
|
|
36
|
+
if @signup_form.valid?
|
|
37
|
+
render
|
|
38
|
+
else
|
|
39
|
+
set_error_now("入力内容を確認してください。")
|
|
40
|
+
render(:action => "index")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# POST /signup/email/create
|
|
45
|
+
def create
|
|
46
|
+
@signup_form = EditFormClass.new(session[:signup_form])
|
|
47
|
+
|
|
48
|
+
@user = User.new
|
|
49
|
+
@credential = @user.email_credentials.build
|
|
50
|
+
@credential.attributes = @signup_form.to_email_credential_hash
|
|
51
|
+
|
|
52
|
+
if @signup_form.valid? && @user.save
|
|
53
|
+
@activation_url = url_for(
|
|
54
|
+
:only_path => false,
|
|
55
|
+
:controller => "signup/email",
|
|
56
|
+
:action => "activation",
|
|
57
|
+
:activation_token => @credential.activation_token)
|
|
58
|
+
|
|
59
|
+
# TODO: テスト
|
|
60
|
+
# MEMO: 即時性を優先し、非同期化しない
|
|
61
|
+
ActivationMailer.deliver_request_for_signup(
|
|
62
|
+
:recipients => @credential.email,
|
|
63
|
+
:activation_url => @activation_url)
|
|
64
|
+
|
|
65
|
+
redirect_to(:action => "created")
|
|
66
|
+
else
|
|
67
|
+
set_error_now("入力内容を確認してください。")
|
|
68
|
+
render(:action => "index")
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# GET /signup/email/created
|
|
73
|
+
def created
|
|
74
|
+
@signup_form = EditFormClass.new(session[:signup_form])
|
|
75
|
+
@credential = EmailCredential.find_by_email(@signup_form.email)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# GET /signup/email/activation/:activation_token
|
|
79
|
+
# FIXME: URLの見直し
|
|
80
|
+
# FIXME: 無効なアクティベーションキー、アクティベーション済みのキーはフィルタで弾く
|
|
81
|
+
def activation
|
|
82
|
+
@credential = EmailCredential.find_by_activation_token(params[:activation_token])
|
|
83
|
+
@activated = @credential.try(:activated?)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# POST /signup/email/activate
|
|
87
|
+
# FIXME: URLの見直し
|
|
88
|
+
# FIXME: 無効なアクティベーションキー、アクティベーション済みのキーはフィルタで弾く
|
|
89
|
+
def activate
|
|
90
|
+
@credential = EmailCredential.find_by_activation_token(params[:activation_token])
|
|
91
|
+
|
|
92
|
+
unless @credential
|
|
93
|
+
set_error("無効なアクティベーションキーです。")
|
|
94
|
+
redirect_to(root_path)
|
|
95
|
+
return
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
if @credential.activated?
|
|
99
|
+
set_error("既に本登録されています。")
|
|
100
|
+
redirect_to(root_path)
|
|
101
|
+
return
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
@credential.activate!
|
|
105
|
+
|
|
106
|
+
# TODO: テスト
|
|
107
|
+
# MEMO: 即時性を優先し、非同期化しない
|
|
108
|
+
ActivationMailer.deliver_complete_for_signup(
|
|
109
|
+
:recipients => @credential.email)
|
|
110
|
+
|
|
111
|
+
redirect_to(:action => "activated")
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# GET /signup/email/activated
|
|
115
|
+
# FIXME: URLの見直し
|
|
116
|
+
# FIXME: 無効なアクティベーションキー、アクティベーション済みのキーはフィルタで弾く
|
|
117
|
+
def activated
|
|
118
|
+
# nop
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
private
|
|
122
|
+
|
|
123
|
+
def clear_session_user_id
|
|
124
|
+
session[:user_id] = nil
|
|
125
|
+
return true
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def clear_session_signup_form
|
|
129
|
+
session[:signup_form] = nil
|
|
130
|
+
return true
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# OpenID認証情報サインアップ
|
|
4
|
+
# FIXME: 全体的に実装を整理
|
|
5
|
+
class Signup::OpenIdController < ApplicationController
|
|
6
|
+
# GET /signup/open_id
|
|
7
|
+
def index
|
|
8
|
+
session[:identity_url] = nil
|
|
9
|
+
@openid_url = nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# POST /signup/open_id/authenticate
|
|
13
|
+
# GET /signup/open_id/authenticate
|
|
14
|
+
def authenticate
|
|
15
|
+
@openid_url = params[:openid_url]
|
|
16
|
+
|
|
17
|
+
failed = proc { |message|
|
|
18
|
+
flash[:error] = message
|
|
19
|
+
redirect_to(:action => "index")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
authenticate_with_open_id(@openid_url) { |result, identity_url, sreg|
|
|
23
|
+
if result.successful?
|
|
24
|
+
if OpenIdCredential.exists?(:identity_url => identity_url)
|
|
25
|
+
failed["指定されたOpenIDは既に登録されているため、利用できません。"]
|
|
26
|
+
else
|
|
27
|
+
session[:identity_url] = identity_url
|
|
28
|
+
redirect_to(:action => "authenticated")
|
|
29
|
+
end
|
|
30
|
+
else
|
|
31
|
+
failed[result.message]
|
|
32
|
+
end
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# GET /signup/open_id/authenticated
|
|
37
|
+
def authenticated
|
|
38
|
+
@identity_url = session[:identity_url]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# POST /signup/open_id/create
|
|
42
|
+
def create
|
|
43
|
+
@identity_url = session[:identity_url]
|
|
44
|
+
|
|
45
|
+
@user = User.new
|
|
46
|
+
@credential = @user.open_id_credentials.build
|
|
47
|
+
@credential.identity_url = @identity_url
|
|
48
|
+
|
|
49
|
+
@user.save!
|
|
50
|
+
|
|
51
|
+
# FIXME: ログイン状態にしないように変更
|
|
52
|
+
session[:identity_url] = nil
|
|
53
|
+
session[:user_id] = @user.id
|
|
54
|
+
|
|
55
|
+
redirect_to(:action => "created")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# GET /signup/open_id/created
|
|
59
|
+
def created
|
|
60
|
+
# nop
|
|
61
|
+
end
|
|
62
|
+
end
|