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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 414ccb9816b1c775f0c4b1bb9a20b9974c468d76
|
4
|
+
data.tar.gz: 172c23591eb89029e862cd5994c0a6ada1156e81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95b24ffef7b24fc5c31b2b2d7f66e87a51dfe0bf491985e21a0ed539633413bb110014a1e5bcfb4af0df0aaec3a6dfce7a6660ad8bdd0ee704e0252195ac54b9
|
7
|
+
data.tar.gz: 39ea06a61fd9352b7c1330fc18066a56e4cf244650b34c39a8c1543a1afbe08daca9b13eb132824d74f3c170efd57dd53d89bf45a61c26a0f9c0b043717b690f
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/*
|
2
|
+
*= require_self
|
3
|
+
*/
|
4
|
+
|
5
|
+
.oauth-icon {
|
6
|
+
width: 16px !important;
|
7
|
+
height: 16px !important;
|
8
|
+
display: inline-block;
|
9
|
+
background: url(oauth-icons.png) no-repeat;
|
10
|
+
_background-image: url(oauth-icons.gif);
|
11
|
+
}
|
12
|
+
|
13
|
+
.oauth-icon-qq_connect {
|
14
|
+
background-position: 0 -192px;
|
15
|
+
}
|
16
|
+
|
17
|
+
.oauth-icon-github {
|
18
|
+
background-position: 0 -144px;
|
19
|
+
}
|
20
|
+
|
@@ -1,21 +1,19 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
module TinyPassport
|
2
3
|
class AccountDisplay < ::TinySupport::ActiveRecord::DisplayBase
|
3
4
|
def basic
|
4
5
|
result = {}
|
5
6
|
|
6
|
-
result[:login_email?] = _origin_record.login_email?
|
7
7
|
result[:register_way] = _origin_record.register_way_display
|
8
8
|
result[:login_name] = _origin_record.login_name
|
9
9
|
result[:login_records_count] = _origin_record.login_records_count
|
10
10
|
result[:last_login_at] = _origin_record.last_login_at
|
11
11
|
result[:created_at] = _origin_record.created_at
|
12
12
|
|
13
|
+
result[:login_email?] = _origin_record.login_email?
|
14
|
+
|
13
15
|
if result[:login_email?]
|
14
|
-
login_email = _origin_record.login_email
|
15
|
-
result[:login_email] = {
|
16
|
-
:value => login_email.value,
|
17
|
-
:status => login_email.status_display
|
18
|
-
}
|
16
|
+
result[:login_email] = _origin_record.login_email.display.basic
|
19
17
|
end
|
20
18
|
|
21
19
|
result
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module TinyPassport
|
3
|
+
class LoginEmailDisplay < ::TinySupport::ActiveRecord::DisplayBase
|
4
|
+
def basic
|
5
|
+
{
|
6
|
+
:value => _origin_record.value,
|
7
|
+
:status => _origin_record.status_display,
|
8
|
+
:status_desc => _origin_record.status_desc,
|
9
|
+
:await_confirm? => _origin_record.await_confirm?
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def value_starred
|
14
|
+
return @value_starred if defined?(@value_starred)
|
15
|
+
value_parts = _origin_record.value.split('@')
|
16
|
+
@value_starred = "***#{value_parts[0].to_s[-3..-1]}@#{value_parts[1].to_s}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
module TinyPassport
|
2
3
|
class OauthLoginDisplay < ::TinySupport::ActiveRecord::DisplayBase
|
3
4
|
def basic
|
4
5
|
result = {}
|
5
6
|
|
6
7
|
result.merge!(
|
8
|
+
:id => _origin_record.id,
|
7
9
|
:crated_at => _origin_record.created_at,
|
8
10
|
:updated_at => _origin_record.updated_at,
|
9
11
|
:status => _origin_record.status_display,
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
module TinyPassport
|
2
3
|
class OauthTokenDisplay < ::TinySupport::ActiveRecord::DisplayBase
|
3
4
|
def basic
|
@@ -9,6 +10,7 @@ module TinyPassport
|
|
9
10
|
:access_token => _origin_record.access_token,
|
10
11
|
:access_secret => _origin_record.access_secret,
|
11
12
|
:expires_at => _origin_record.expires_at,
|
13
|
+
:expires_at? => _origin_record.expires_at?,
|
12
14
|
:strategy => {
|
13
15
|
:type => _origin_record.strategy_type_display,
|
14
16
|
:id => _origin_record.strategy_id,
|
@@ -6,9 +6,10 @@ module TinyPassport
|
|
6
6
|
attr_reader :active_way, # 激活方式
|
7
7
|
:confirmation_token, # 激活码
|
8
8
|
:value, # account的值
|
9
|
-
:ip
|
9
|
+
:ip, # 当前IP
|
10
|
+
:user_agent_value
|
10
11
|
|
11
|
-
attr_reader :account, :login_record
|
12
|
+
attr_reader :account, :login_record, :auto_login
|
12
13
|
|
13
14
|
validates_presence_of :confirmation_token
|
14
15
|
validates_presence_of :value
|
@@ -20,12 +21,17 @@ module TinyPassport
|
|
20
21
|
!!@login_record
|
21
22
|
end
|
22
23
|
|
24
|
+
def auto_login?
|
25
|
+
[1, '1', true, 'true'].include?(self.auto_login)
|
26
|
+
end
|
27
|
+
|
23
28
|
def submit params={}
|
24
29
|
@active_way = params[:active_way]
|
25
30
|
@confirmation_token = params[:confirmation_token]
|
26
31
|
@value = params[:value]
|
27
32
|
@ip = params[:ip]
|
28
33
|
@auto_login = params[:auto_login]
|
34
|
+
@user_agent_value = params[:user_agent_value].to_s
|
29
35
|
|
30
36
|
if self.valid? && self.success?
|
31
37
|
case self.active_way
|
@@ -50,13 +56,14 @@ module TinyPassport
|
|
50
56
|
if _login_email.status_active_verify!
|
51
57
|
@account = _login_email.account
|
52
58
|
|
53
|
-
if
|
59
|
+
if self.auto_login?
|
54
60
|
@login_record = ::TinyPassport::LoginRecord.new
|
55
|
-
@login_record.ip
|
61
|
+
@login_record.ip = self.ip
|
56
62
|
@login_record.last_remembered_ip = self.ip
|
57
|
-
@login_record.remembered
|
58
|
-
@login_record.account
|
59
|
-
@login_record.
|
63
|
+
@login_record.remembered = true
|
64
|
+
@login_record.account = @account
|
65
|
+
@login_record.user_agent_value = self.user_agent_value
|
66
|
+
@login_record.way_key = 'after_login_email_actived'
|
60
67
|
@login_record.save!
|
61
68
|
end
|
62
69
|
|
@@ -8,15 +8,22 @@ module TinyPassport
|
|
8
8
|
attr_accessor :active_way # 激活方式
|
9
9
|
|
10
10
|
validates_inclusion_of :active_way, :in => ['login_email']
|
11
|
+
|
11
12
|
self.email_validates_of :login_email_value, :if => :login_email_required?
|
12
13
|
|
14
|
+
# 验证频率!
|
15
|
+
validate :verify_frequency
|
16
|
+
|
17
|
+
# 取出用户名与邮箱的前后的空格
|
18
|
+
self.support_strip_values!(:login_email_value)
|
19
|
+
|
13
20
|
# 是否需要邮箱
|
14
21
|
def login_email_required?
|
15
22
|
self.active_way == 'login_email'
|
16
23
|
end
|
17
24
|
|
18
25
|
def login_email
|
19
|
-
@login_email ||= ::TinyPassport::LoginEmail.
|
26
|
+
@login_email ||= ::TinyPassport::LoginEmail.tiny_cache_find_by(:value => self.login_email_value)
|
20
27
|
end
|
21
28
|
|
22
29
|
def submit params={}
|
@@ -35,13 +42,7 @@ module TinyPassport
|
|
35
42
|
when 'deleted'
|
36
43
|
self.errors.add :login_email_value, :already_deleted # 已经被注销
|
37
44
|
else
|
38
|
-
self.login_email.
|
39
|
-
self.login_email.confirmation_send_at = ::Time.now
|
40
|
-
|
41
|
-
if self.login_email.save!
|
42
|
-
# 发送邮件
|
43
|
-
!!(::TinyPassport::RegistrationMailer.send_confirmation_token(self.login_email).deliver) and return true
|
44
|
-
end
|
45
|
+
self.login_email.save_with_send_confirmation_token! and return true
|
45
46
|
end
|
46
47
|
else
|
47
48
|
self.errors.add :login_email_value, :not_found # 没有找到
|
@@ -54,5 +55,13 @@ module TinyPassport
|
|
54
55
|
false
|
55
56
|
end
|
56
57
|
|
58
|
+
# 验证发送频率
|
59
|
+
def verify_frequency
|
60
|
+
if self.login_email && self.login_email.confirmation_send_at
|
61
|
+
if ::Time.now - self.login_email.confirmation_send_at < 2.minutes
|
62
|
+
self.errors.add :base, :too_often # 太频繁了!
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
57
66
|
end
|
58
67
|
end
|
@@ -5,7 +5,7 @@ module TinyPassport
|
|
5
5
|
class BindConnectForm
|
6
6
|
include ::TinyPassport::Formable
|
7
7
|
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :account, :oauth_token_id
|
9
9
|
attr_reader :oauth_login
|
10
10
|
|
11
11
|
validate :verify_params
|
@@ -14,7 +14,7 @@ module TinyPassport
|
|
14
14
|
|
15
15
|
# 提交
|
16
16
|
def submit params={}
|
17
|
-
@
|
17
|
+
@account = params[:account]
|
18
18
|
@oauth_token_id = params[:oauth_token_id]
|
19
19
|
|
20
20
|
if self.valid? && self.success?
|
@@ -26,15 +26,11 @@ module TinyPassport
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def account
|
30
|
-
@account ||= ::TinyPassport::Account.find_by_id(@account_id)
|
31
|
-
end
|
32
|
-
|
33
29
|
# 不唯一
|
34
30
|
def oauth_bind
|
35
31
|
@oauth_bind ||= ::TinyPassport::OauthBind.where(
|
36
32
|
:oauth_token_id => self.oauth_token_id,
|
37
|
-
:account_id => self.
|
33
|
+
:account_id => self.account.id
|
38
34
|
).first_or_initialize
|
39
35
|
end
|
40
36
|
|
@@ -46,7 +42,7 @@ module TinyPassport
|
|
46
42
|
def verify_params
|
47
43
|
if self.account
|
48
44
|
else
|
49
|
-
self.errors.add :
|
45
|
+
self.errors.add :account, :not_found
|
50
46
|
end
|
51
47
|
|
52
48
|
if self.oauth_token
|
@@ -1,11 +1,10 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module TinyPassport
|
3
3
|
module Oauth
|
4
|
-
# Oauth 分享的绑定的断开
|
5
4
|
class BindDisconnectForm
|
6
5
|
include ::TinyPassport::Formable
|
7
6
|
|
8
|
-
attr_reader :oauth_bind_id
|
7
|
+
attr_reader :oauth_bind_id, :account
|
9
8
|
|
10
9
|
validate :verify_params
|
11
10
|
|
@@ -14,6 +13,7 @@ module TinyPassport
|
|
14
13
|
# 提交
|
15
14
|
def submit params={}
|
16
15
|
@oauth_bind_id = params[:oauth_bind_id]
|
16
|
+
@account = params[:account]
|
17
17
|
|
18
18
|
if self.valid? && self.success?
|
19
19
|
::ActiveRecord::Base.transaction do
|
@@ -24,7 +24,6 @@ module TinyPassport
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
# 不唯一
|
28
27
|
def oauth_bind
|
29
28
|
@oauth_bind ||= ::TinyPassport::OauthBind.where(:id => self.oauth_bind_id).first
|
30
29
|
end
|
@@ -32,9 +31,18 @@ module TinyPassport
|
|
32
31
|
# 校验参数
|
33
32
|
def verify_params
|
34
33
|
if self.oauth_bind
|
34
|
+
if self.account
|
35
|
+
if self.account.id != self.oauth_bind.account_id
|
36
|
+
self.errors.add :oauth_bind_id, :wrong
|
37
|
+
end
|
38
|
+
end
|
35
39
|
else
|
36
40
|
self.errors.add :oauth_bind_id, :not_found
|
37
41
|
end
|
42
|
+
|
43
|
+
unless self.account
|
44
|
+
self.errors.add :account, :required
|
45
|
+
end
|
38
46
|
end
|
39
47
|
end
|
40
48
|
end
|
@@ -9,14 +9,17 @@ module TinyPassport
|
|
9
9
|
attr_reader :result_status
|
10
10
|
attr_reader :login_record
|
11
11
|
attr_reader :ip
|
12
|
+
attr_reader :user_agent_value
|
13
|
+
attr_reader :login_account
|
12
14
|
|
13
15
|
validates_inclusion_of :usage, :in => ['login', 'bind']
|
14
16
|
validate :verify_info_params
|
15
17
|
|
16
18
|
def submit usage, options={}, info_params={}
|
17
|
-
@usage
|
18
|
-
@info_params
|
19
|
+
@usage = usage
|
20
|
+
@info_params = (info_params || {})
|
19
21
|
@ip = options[:ip]
|
22
|
+
@user_agent_value = options[:user_agent_value]
|
20
23
|
|
21
24
|
if self.valid? && self.success?
|
22
25
|
case self.usage
|
@@ -28,7 +31,6 @@ module TinyPassport
|
|
28
31
|
|
29
32
|
true
|
30
33
|
else
|
31
|
-
|
32
34
|
false
|
33
35
|
end
|
34
36
|
end
|
@@ -40,12 +42,13 @@ module TinyPassport
|
|
40
42
|
@login_account = self.oauth_token.login_account
|
41
43
|
|
42
44
|
# 有绑定的账户
|
43
|
-
@login_record
|
44
|
-
@login_record.ip
|
45
|
+
@login_record = ::TinyPassport::LoginRecord.new
|
46
|
+
@login_record.ip = self.ip
|
45
47
|
@login_record.last_remembered_ip = self.ip
|
46
|
-
@login_record.remembered
|
47
|
-
@login_record.account
|
48
|
-
@login_record.
|
48
|
+
@login_record.remembered = true
|
49
|
+
@login_record.account = self.login_account
|
50
|
+
@login_record.user_agent_value = self.user_agent_value
|
51
|
+
@login_record.way_key = 'oauth_qq_connect'
|
49
52
|
@login_record.save!
|
50
53
|
|
51
54
|
@result_status = 'already'
|
@@ -5,15 +5,14 @@ module TinyPassport
|
|
5
5
|
class LoginConnectForm
|
6
6
|
include ::TinyPassport::Formable
|
7
7
|
|
8
|
-
attr_accessor :
|
9
|
-
attr_reader :oauth_login
|
8
|
+
attr_accessor :oauth_token_id
|
9
|
+
attr_reader :oauth_login, :account
|
10
10
|
|
11
|
-
validates_presence_of :account_id, :oauth_token_id
|
12
11
|
validate :verify_params
|
13
12
|
|
14
13
|
# 提交
|
15
14
|
def submit params={}
|
16
|
-
@
|
15
|
+
@account = params[:account]
|
17
16
|
@oauth_token_id = params[:oauth_token_id]
|
18
17
|
|
19
18
|
if self.valid? && self.success?
|
@@ -31,11 +30,6 @@ module TinyPassport
|
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
34
|
-
def account
|
35
|
-
return @account if defined?(@account)
|
36
|
-
@account ||= ::TinyPassport::Account.find_by_id(self.account_id)
|
37
|
-
end
|
38
|
-
|
39
33
|
def oauth_token
|
40
34
|
return @oauth_token if defined?(@oauth_token)
|
41
35
|
@oauth_token ||= ::TinyPassport::OauthToken.find_by_id(self.oauth_token_id)
|
@@ -43,9 +37,8 @@ module TinyPassport
|
|
43
37
|
|
44
38
|
# 校验参数
|
45
39
|
def verify_params
|
46
|
-
|
47
|
-
|
48
|
-
self.errors.add :account_id, :not_found
|
40
|
+
unless self.account
|
41
|
+
self.errors.add :account, :required
|
49
42
|
end
|
50
43
|
|
51
44
|
if self.oauth_token
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module TinyPassport
|
3
|
+
module Oauth
|
4
|
+
class LoginDisconnectForm
|
5
|
+
include ::TinyPassport::Formable
|
6
|
+
|
7
|
+
attr_reader :oauth_login_id, :account
|
8
|
+
|
9
|
+
validate :verify_params
|
10
|
+
|
11
|
+
validates_presence_of :oauth_login_id
|
12
|
+
|
13
|
+
# 提交
|
14
|
+
def submit params={}
|
15
|
+
@oauth_login_id = params[:oauth_login_id]
|
16
|
+
@account = params[:account]
|
17
|
+
|
18
|
+
if self.valid? && self.success?
|
19
|
+
::ActiveRecord::Base.transaction do
|
20
|
+
self.oauth_login.destroy!
|
21
|
+
end
|
22
|
+
else
|
23
|
+
false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def oauth_login
|
28
|
+
@oauth_login ||= ::TinyPassport::OauthLogin.where(:id => self.oauth_login_id).first
|
29
|
+
end
|
30
|
+
|
31
|
+
# 校验参数
|
32
|
+
def verify_params
|
33
|
+
if self.oauth_login
|
34
|
+
if self.account
|
35
|
+
if self.account.id != self.oauth_login.account_id
|
36
|
+
self.errors.add :oauth_login_id, :wrong
|
37
|
+
end
|
38
|
+
end
|
39
|
+
else
|
40
|
+
self.errors.add :oauth_login_id, :not_found
|
41
|
+
end
|
42
|
+
|
43
|
+
unless self.account
|
44
|
+
self.errors.add :account, :required
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|