tiny_passport 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/ables/tiny_passport/account_validate_able.rb +1 -0
- data/app/ables/tiny_passport/aggrement_term_able.rb +1 -0
- data/app/assets/images/tiny_passport/loading-mini.gif +0 -0
- data/app/assets/images/tiny_passport/oauth-icons.gif +0 -0
- data/app/assets/images/tiny_passport/oauth-icons.png +0 -0
- data/app/assets/stylesheets/tiny_passport/application.css.scss +20 -0
- data/app/displays/tiny_passport/account_display.rb +4 -6
- data/app/displays/tiny_passport/login_email_display.rb +19 -0
- data/app/displays/tiny_passport/oauth_login_display.rb +2 -0
- data/app/displays/tiny_passport/oauth_token_display.rb +2 -0
- data/app/forms/tiny_passport/account_active_form.rb +14 -7
- data/app/forms/tiny_passport/confirmation_token_form.rb +17 -8
- data/app/forms/tiny_passport/oauth/bind_connect_form.rb +4 -8
- data/app/forms/tiny_passport/oauth/bind_disconnect_form.rb +11 -3
- data/app/forms/tiny_passport/oauth/callback_form.rb +11 -8
- data/app/forms/tiny_passport/oauth/login_connect_form.rb +5 -12
- data/app/forms/tiny_passport/oauth/login_disconnect_form.rb +50 -0
- data/app/forms/tiny_passport/registration_form.rb +46 -35
- data/app/forms/tiny_passport/remember_token_auth_form.rb +2 -2
- data/app/forms/tiny_passport/reset_password_form.rb +4 -4
- data/app/forms/tiny_passport/session_form.rb +12 -11
- data/app/forms/tiny_passport/update_login_email_form.rb +68 -0
- data/app/forms/tiny_passport/update_password_form.rb +1 -1
- data/app/mailers/tiny_passport/registration_mailer.rb +1 -1
- data/app/models/concerns/tiny_passport/basic_status_able.rb +28 -0
- data/app/models/tiny_passport/account.rb +0 -1
- data/app/models/tiny_passport/login_email.rb +26 -16
- data/app/models/tiny_passport/oauth_login.rb +1 -12
- data/app/models/tiny_passport/oauth_token.rb +8 -2
- data/app/queries/tiny_passport/account_query.rb +4 -1
- data/config/locales/en/forms.en.yml +13 -0
- data/config/locales/zh-CN/forms.zh-CN.yml +44 -5
- data/db/migrate/20131105104415_create_tiny_passport_login_records.rb +1 -0
- data/lib/omniauth/strategies/github.rb +58 -0
- data/lib/omniauth/strategies/qq_connect.rb +1 -1
- data/lib/omniauth/strategies/weibo.rb +93 -0
- data/lib/tiny_passport/engine.rb +3 -3
- data/lib/tiny_passport/http_authcenter.rb +7 -2
- data/lib/tiny_passport/omniauth/strategable.rb +1 -0
- data/lib/tiny_passport/version.rb +1 -1
- data/test/dummy/db/schema.rb +2 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +8973 -0
- data/test/forms/tiny_passport/oauth/callback_form_test.rb +2 -2
- data/test/forms/tiny_passport/session_form_test.rb +0 -2
- metadata +13 -12
- data/app/assets/stylesheets/tiny_passport/application.css +0 -13
- data/app/forms/tiny_passport/welcome_email_form.rb +0 -47
- data/app/services/tiny_passport/account_service.rb +0 -43
- data/app/services/tiny_passport/email_send_service.rb +0 -32
- data/app/services/tiny_passport/oauth_service.rb +0 -11
- data/test/dummy/tmp/cache/271/2A1/tiny_cache%2Fmodels%2FTinyPassport%3A%3AAccount%2F1%2F1 +0 -0
- data/test/dummy/tmp/cache/EDF/4C1/tiny_cache%2Fmodel_uniq_keys%2FTinyPassport%3A%3ALoginEmail%2F%5B%5B%22account_id%22%2C+1%5D%5D +0 -1
@@ -6,9 +6,11 @@ module TinyPassport
|
|
6
6
|
include ::TinyPassport::AccountValidateAble
|
7
7
|
include ::TinyPassport::AggrementTermAble
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
attr_reader :password, :password_confirmation, :login_email_value,
|
10
|
+
:auto_login, :user_agent_value,
|
11
|
+
:login_record,
|
12
|
+
:login_name,
|
13
|
+
:created_ip
|
12
14
|
|
13
15
|
# 取出用户名与邮箱的前后的空格
|
14
16
|
self.support_strip_values!(:login_name, :login_email_value)
|
@@ -38,17 +40,8 @@ module TinyPassport
|
|
38
40
|
@account ||= ::TinyPassport::Account.new
|
39
41
|
end
|
40
42
|
|
41
|
-
def
|
42
|
-
|
43
|
-
return @login_record if defined?(@login_record)
|
44
|
-
|
45
|
-
::ActiveRecord::Base.transaction do
|
46
|
-
@login_record ||= ::TinyPassport::LoginRecord.new
|
47
|
-
@login_record.account = self.account
|
48
|
-
@login_record.save!
|
49
|
-
@login_record
|
50
|
-
end
|
51
|
-
end
|
43
|
+
def auto_login?
|
44
|
+
[1, '1', true, 'true'].include?(self.auto_login)
|
52
45
|
end
|
53
46
|
|
54
47
|
def login_email
|
@@ -67,6 +60,7 @@ module TinyPassport
|
|
67
60
|
# :created_ip 当前的IP
|
68
61
|
# :captcha_key 验证码的KEY
|
69
62
|
# :captcha 验证码的值
|
63
|
+
# :auto_login 自动登录 true/false 默认false
|
70
64
|
#
|
71
65
|
# Usage:
|
72
66
|
# form = ::TinyPassport::RegistrationForm.new
|
@@ -78,11 +72,14 @@ module TinyPassport
|
|
78
72
|
self.submit_valid?(params) do
|
79
73
|
if save_objects
|
80
74
|
if self.login_email_required?
|
75
|
+
confirmation_token_form = ::TinyPassport::ConfirmationTokenForm.new
|
76
|
+
|
81
77
|
# 为login_email发送验证码
|
82
|
-
|
78
|
+
confirmation_token_form.submit(
|
83
79
|
:login_email_value => self.login_email.value,
|
84
|
-
:active_way
|
80
|
+
:active_way => 'login_email'
|
85
81
|
)
|
82
|
+
|
86
83
|
end
|
87
84
|
|
88
85
|
@result = {
|
@@ -98,12 +95,14 @@ module TinyPassport
|
|
98
95
|
end
|
99
96
|
|
100
97
|
def submit_valid?(params={}, &block)
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
98
|
+
@agreement_terms = params[:agreement_terms]
|
99
|
+
@login_name = params[:login_name]
|
100
|
+
@login_email_value = params[:login_email_value]
|
101
|
+
@password = params[:password]
|
102
|
+
@password_confirmation = params[:password_confirmation]
|
103
|
+
@created_ip = params[:created_ip]
|
104
|
+
@user_agent_value = params[:user_agent_value]
|
105
|
+
@auto_login = params[:auto_login]
|
107
106
|
|
108
107
|
# 验证码
|
109
108
|
self.captcha_key = params[:captcha_key]
|
@@ -144,24 +143,36 @@ module TinyPassport
|
|
144
143
|
end
|
145
144
|
end
|
146
145
|
|
147
|
-
def email_send_service
|
148
|
-
@email_send_service ||= ::TinyPassport::EmailSendService.new
|
149
|
-
end
|
150
|
-
|
151
146
|
private
|
152
147
|
|
153
148
|
# 保存对象
|
154
149
|
def save_objects
|
155
150
|
::ActiveRecord::Base.transaction do
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
151
|
+
self.account.register_way_key = 'basic'
|
152
|
+
self.account.login_name = self.login_name
|
153
|
+
self.account.created_ip = self.created_ip
|
154
|
+
|
155
|
+
if self.login_email_required?
|
156
|
+
self.login_email.account = self.account
|
157
|
+
self.login_email.save!
|
158
|
+
end
|
159
|
+
|
160
|
+
self.account.login_email = self.login_email
|
161
|
+
self.account.save!
|
162
|
+
|
163
|
+
if self.auto_login?
|
164
|
+
@login_record ||= ::TinyPassport::LoginRecord.new
|
165
|
+
@login_record.ip = self.created_ip
|
166
|
+
@login_record.last_remembered_ip = self.created_ip
|
167
|
+
@login_record.remembered = true
|
168
|
+
@login_record.user_agent_value = self.user_agent_value
|
169
|
+
@login_record.way_key = 'after_login_email_actived'
|
170
|
+
@login_record.account = self.account
|
171
|
+
|
172
|
+
@login_record.save!
|
173
|
+
end
|
174
|
+
|
175
|
+
true
|
165
176
|
end
|
166
177
|
rescue
|
167
178
|
self.errors.add :base, :service_error
|
@@ -4,7 +4,7 @@ module TinyPassport
|
|
4
4
|
include ::TinyPassport::Formable
|
5
5
|
|
6
6
|
attr_reader :login_record
|
7
|
-
|
7
|
+
attr_reader :remember_token
|
8
8
|
|
9
9
|
validates_presence_of :remember_token
|
10
10
|
|
@@ -12,7 +12,7 @@ module TinyPassport
|
|
12
12
|
@remember_token = params[:remember_token]
|
13
13
|
|
14
14
|
if self.valid? && self.success?
|
15
|
-
@login_record = ::TinyPassport::LoginRecord.authenticate_from_remember_token(remember_token)
|
15
|
+
@login_record = ::TinyPassport::LoginRecord.authenticate_from_remember_token(self.remember_token)
|
16
16
|
|
17
17
|
if self.login_record && self.login_record.available? && self.login_record.account
|
18
18
|
self.login_record.last_remembered_ip = params[:last_remembered_ip].to_s
|
@@ -73,10 +73,10 @@ module TinyPassport
|
|
73
73
|
# - reset_password_token
|
74
74
|
#
|
75
75
|
def submit_valid? params={}, &block
|
76
|
-
@password
|
77
|
-
@password_confirmation
|
78
|
-
@reset_password_token
|
79
|
-
@reset_way
|
76
|
+
@password = params[:password]
|
77
|
+
@password_confirmation = params[:password_confirmation]
|
78
|
+
@reset_password_token = params[:reset_password_token]
|
79
|
+
@reset_way = params[:reset_way]
|
80
80
|
|
81
81
|
# 基本验证
|
82
82
|
if self.valid? && self.success?
|
@@ -3,7 +3,7 @@ module TinyPassport
|
|
3
3
|
class SessionForm
|
4
4
|
include ::TinyPassport::Formable
|
5
5
|
|
6
|
-
|
6
|
+
attr_reader :input_value, :password, :remembered, :ip, :user_agent_value, :login_record
|
7
7
|
|
8
8
|
validates_presence_of :input_value
|
9
9
|
validates_presence_of :password
|
@@ -14,10 +14,6 @@ module TinyPassport
|
|
14
14
|
@remembered = true
|
15
15
|
end
|
16
16
|
|
17
|
-
def login_record
|
18
|
-
@login_record ||= ::TinyPassport::LoginRecord.new
|
19
|
-
end
|
20
|
-
|
21
17
|
def remembered?
|
22
18
|
[true, 'true', '1'].include?(self.remembered)
|
23
19
|
end
|
@@ -30,15 +26,20 @@ module TinyPassport
|
|
30
26
|
# :remembered
|
31
27
|
#
|
32
28
|
def submit params={}
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
@input_value = params[:input_value]
|
30
|
+
@password = params[:password]
|
31
|
+
@ip = params[:ip].to_s
|
32
|
+
@remembered = params[:remembered]
|
33
|
+
@user_agent_value = params[:user_agent_value].to_s
|
34
|
+
|
35
|
+
|
36
|
+
@login_record = ::TinyPassport::LoginRecord.new
|
37
37
|
|
38
38
|
#######
|
39
|
-
self.login_record.ip
|
39
|
+
self.login_record.ip = self.ip
|
40
40
|
self.login_record.last_remembered_ip = self.ip
|
41
|
-
self.login_record.
|
41
|
+
self.login_record.user_agent_value = self.user_agent_value
|
42
|
+
self.login_record.remembered = self.remembered?
|
42
43
|
|
43
44
|
if self.valid?
|
44
45
|
if self.success?
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module TinyPassport
|
3
|
+
# 登录邮箱表单
|
4
|
+
class UpdateLoginEmailForm
|
5
|
+
include ::TinyPassport::Formable
|
6
|
+
|
7
|
+
attr_reader :current_password, :account, :login_email_value
|
8
|
+
|
9
|
+
validates_presence_of :current_password
|
10
|
+
|
11
|
+
self.support_strip_values!(:login_email_value)
|
12
|
+
|
13
|
+
self.email_validates_of :login_email_value
|
14
|
+
|
15
|
+
validate :verify_uniques
|
16
|
+
|
17
|
+
# 如果两者都为不为空,则判断, 是否一致
|
18
|
+
def password_confirmation_required?
|
19
|
+
self.password.present? || self.password_confirmation.present?
|
20
|
+
end
|
21
|
+
|
22
|
+
def login_email
|
23
|
+
@login_email = self.account.login_email || ::TinyPassport::LoginEmail.new(:account => self.account)
|
24
|
+
end
|
25
|
+
|
26
|
+
def submit params={}
|
27
|
+
@current_password = params[:current_password]
|
28
|
+
@account = params[:account]
|
29
|
+
@login_email_value = params[:login_email_value]
|
30
|
+
|
31
|
+
if self.valid? && self.success?
|
32
|
+
if self.account
|
33
|
+
if self.account.valid_password?(self.current_password)
|
34
|
+
save_objects and return true
|
35
|
+
else
|
36
|
+
self.errors.add :current_password, :wrong # 密码错误
|
37
|
+
end
|
38
|
+
else
|
39
|
+
self.errors.add :account, :required # 密码错误
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
false
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def verify_uniques
|
49
|
+
if self.login_email_value.present?
|
50
|
+
if self.login_email_value == self.login_email.value
|
51
|
+
self.errors.add :login_email_value, :not_changed
|
52
|
+
end
|
53
|
+
|
54
|
+
if ::TinyPassport::LoginEmail.exists?(:value => self.login_email_value)
|
55
|
+
self.errors.add :login_email_value, :taken
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def save_objects
|
61
|
+
::ActiveRecord::Base.transaction do
|
62
|
+
self.login_email.value = self.login_email_value
|
63
|
+
self.login_email.account = self.account
|
64
|
+
self.login_email.save_with_send_confirmation_token!(true)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -3,7 +3,7 @@ module TinyPassport
|
|
3
3
|
class UpdatePasswordForm
|
4
4
|
include ::TinyPassport::Formable
|
5
5
|
|
6
|
-
|
6
|
+
attr_reader :password, :password_confirmation, :current_password, :account
|
7
7
|
|
8
8
|
validates_presence_of :password
|
9
9
|
validates_presence_of :current_password
|
@@ -13,7 +13,7 @@ module TinyPassport
|
|
13
13
|
|
14
14
|
def send_confirmation_token(login_email)
|
15
15
|
@login_email = login_email
|
16
|
-
@account
|
16
|
+
@account = login_email.account
|
17
17
|
|
18
18
|
mail(:to => @account.login_email_value_to, :subject => "Welcome Confirm To TinyPassport") do |format|
|
19
19
|
format.html
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Concerns
|
3
|
+
module TinyPassport
|
4
|
+
module BasicStatusAble
|
5
|
+
extend ::ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
include ::TinySupport::Configable
|
9
|
+
|
10
|
+
# 邮箱的激活情况
|
11
|
+
self.tiny_support_config :status, [
|
12
|
+
{:key => 'default', :value => 0}, # 初始状态
|
13
|
+
{:key => 'pending', :value => 1}, # 需激活状态
|
14
|
+
{:key => 'active', :value => 2}, # 激活状态
|
15
|
+
{:key => 'lock', :value => 3}, # 已经锁定,需要邮箱激活
|
16
|
+
{:key => 'block', :value => 4}, # 已经被屏蔽
|
17
|
+
{:key => 'deleted', :value => -1} # 已经删除
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
def status_desc
|
22
|
+
I18n.t("tiny_passport.basic_status.#{self.status_key}")
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -1,19 +1,9 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module TinyPassport
|
3
3
|
class LoginEmail < ActiveRecord::Base
|
4
|
-
|
4
|
+
self.tiny_support_display
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
# 邮箱的激活情况
|
9
|
-
self.tiny_support_config :status, [
|
10
|
-
{:key => 'default', :value => 0}, # 初始状态
|
11
|
-
{:key => 'pending', :value => 1}, # 需要验证
|
12
|
-
{:key => 'active', :value => 2}, # 激活状态
|
13
|
-
{:key => 'lock', :value => 3}, # 已经锁定,需要邮箱激活
|
14
|
-
{:key => 'block', :value => 4}, # 已经被屏蔽
|
15
|
-
{:key => 'deleted', :value => -1} # 已经删除
|
16
|
-
]
|
6
|
+
include ::Concerns::TinyPassport::BasicStatusAble
|
17
7
|
|
18
8
|
belongs_to :account, :class_name => "TinyPassport::Account"
|
19
9
|
|
@@ -50,14 +40,34 @@ module TinyPassport
|
|
50
40
|
|
51
41
|
# 邮箱状态激活
|
52
42
|
def status_active_verify!
|
53
|
-
self.confirmation_token
|
54
|
-
self.confirmed_at
|
55
|
-
self.confirmation_send_at
|
56
|
-
self.status_key
|
43
|
+
self.confirmation_token = nil
|
44
|
+
self.confirmed_at = Time.now
|
45
|
+
self.confirmation_send_at = nil
|
46
|
+
self.status_key = 'active'
|
57
47
|
self.encrypted_confirmation_token = ''
|
58
48
|
self.save!
|
59
49
|
end
|
60
50
|
|
51
|
+
# 发送邮件
|
52
|
+
def save_with_send_confirmation_token!(token_refresh=false)
|
53
|
+
# 如果验证码已经过期了
|
54
|
+
if self.confirmation_token_expires? || token_refresh
|
55
|
+
self.generate_encrypted_confirmation_token
|
56
|
+
end
|
57
|
+
|
58
|
+
self.confirmation_send_at = ::Time.now
|
59
|
+
self.status_key = 'default'
|
60
|
+
|
61
|
+
if self.save!
|
62
|
+
# TODO
|
63
|
+
::TinyPassport::RegistrationMailer.send_confirmation_token(self).deliver
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def await_confirm?
|
68
|
+
['default', 'pending'].include?(self.status_key)
|
69
|
+
end
|
70
|
+
|
61
71
|
# reset_password_token ----------------------------------------------
|
62
72
|
def generate_encrypted_reset_password_token
|
63
73
|
self.reset_password_token = ::SecureRandom.base64
|
@@ -1,24 +1,13 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module TinyPassport
|
3
3
|
class OauthLogin < ActiveRecord::Base
|
4
|
-
include ::
|
4
|
+
include ::Concerns::TinyPassport::BasicStatusAble
|
5
5
|
|
6
|
-
self.acts_as_tiny_cached :version => 1
|
7
6
|
self.tiny_support_display
|
8
7
|
|
9
8
|
belongs_to :account, :class_name => "TinyPassport::Account"
|
10
9
|
belongs_to :oauth_token, :class_name => "TinyPassport::OauthToken"
|
11
10
|
|
12
|
-
# 邮箱的激活情况
|
13
|
-
self.tiny_support_config :status, [
|
14
|
-
{:key => 'default', :value => 0 }, # 初始状态
|
15
|
-
{:key => 'pending', :value => 1 }, # 需要验证
|
16
|
-
{:key => 'active', :value => 2 }, # 激活状态
|
17
|
-
{:key => 'lock', :value => 3 }, # 已经锁定,需要邮箱激活
|
18
|
-
{:key => 'block', :value => 4 }, # 已经被屏蔽
|
19
|
-
{:key => 'deleted', :value => -1 } # 已经删除
|
20
|
-
]
|
21
|
-
|
22
11
|
attr_accessible :account, :oauth_token
|
23
12
|
|
24
13
|
def oauth_token?
|
@@ -5,7 +5,6 @@ module TinyPassport
|
|
5
5
|
# 用于登录的
|
6
6
|
has_one :oauth_login, :class_name => "TinyPassport::OauthLogin"
|
7
7
|
|
8
|
-
self.acts_as_tiny_cached :version => 1
|
9
8
|
self.tiny_support_display
|
10
9
|
|
11
10
|
# 长字段信息
|
@@ -16,7 +15,10 @@ module TinyPassport
|
|
16
15
|
has_many :bind_accounts, :class_name => "TinyPassport::Account", :through => :oauth_binds, :source => :account
|
17
16
|
|
18
17
|
self.tiny_support_config :strategy_type, [
|
19
|
-
{:key => 'qq_connect', :value => 1}
|
18
|
+
{:key => 'qq_connect', :value => 1},
|
19
|
+
{:key => 'github', :value => 2},
|
20
|
+
{:key => 'google', :value => 3},
|
21
|
+
{:key => 'weibo', :value => 4}
|
20
22
|
]
|
21
23
|
|
22
24
|
attr_accessible :strategy_type_value,
|
@@ -32,6 +34,10 @@ module TinyPassport
|
|
32
34
|
I18n.t("tiny_passport.oauth.providers.#{self.strategy_type_key}.name")
|
33
35
|
end
|
34
36
|
|
37
|
+
def expires_at?
|
38
|
+
self.expires_at.present?
|
39
|
+
end
|
40
|
+
|
35
41
|
# 已经绑定登录帐号了
|
36
42
|
def login_account?
|
37
43
|
!!(self.login_account)
|