tiny_passport 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/ables/tiny_passport/account_validate_able.rb +24 -0
- data/app/ables/tiny_passport/aggrement_term_able.rb +28 -0
- data/app/ables/tiny_passport/formable.rb +17 -0
- data/app/ables/tiny_passport/query_able.rb +25 -0
- data/app/controllers/tiny_passport/application_controller.rb +1 -0
- data/app/displays/tiny_passport/account_display.rb +25 -0
- data/app/displays/tiny_passport/oauth_login_display.rb +21 -0
- data/app/displays/tiny_passport/oauth_token_display.rb +25 -0
- data/app/errors/tiny_passport/alert_authorized_error.rb +6 -0
- data/app/errors/tiny_passport/unauthorized_error.rb +6 -0
- data/app/forms/tiny_passport/account_active_form.rb +83 -0
- data/app/forms/tiny_passport/account_form.rb +6 -0
- data/app/forms/tiny_passport/confirmation_token_form.rb +58 -0
- data/app/forms/tiny_passport/oauth/bind_connect_form.rb +65 -0
- data/app/forms/tiny_passport/oauth/bind_disconnect_form.rb +42 -0
- data/app/forms/tiny_passport/oauth/callback_form.rb +165 -0
- data/app/forms/tiny_passport/oauth/login_connect_form.rb +63 -0
- data/app/forms/tiny_passport/registration_form.rb +172 -0
- data/app/forms/tiny_passport/remember_token_auth_form.rb +32 -0
- data/app/forms/tiny_passport/reset_password_form.rb +95 -0
- data/app/forms/tiny_passport/reset_password_token_form.rb +55 -0
- data/app/forms/tiny_passport/session_form.rb +116 -0
- data/app/forms/tiny_passport/update_password_form.rb +50 -0
- data/app/forms/tiny_passport/welcome_email_form.rb +47 -0
- data/app/helpers/tiny_passport/application_helper.rb +1 -0
- data/app/mailers/tiny_passport/registration_mailer.rb +23 -0
- data/app/mailers/tiny_passport/reset_password_mailer.rb +16 -0
- data/app/models/concerns/tiny_passport/account_authenticatable.rb +24 -0
- data/app/models/tiny_passport/account.rb +41 -0
- data/app/models/tiny_passport/avatar.rb +6 -0
- data/app/models/tiny_passport/login_email.rb +89 -0
- data/app/models/tiny_passport/login_record.rb +69 -0
- data/app/models/tiny_passport/oauth_bind.rb +9 -0
- data/app/models/tiny_passport/oauth_info.rb +8 -0
- data/app/models/tiny_passport/oauth_login.rb +28 -0
- data/app/models/tiny_passport/oauth_token.rb +57 -0
- data/app/queries/tiny_passport/account_query.rb +45 -0
- data/app/services/tiny_passport/account_service.rb +43 -0
- data/app/services/tiny_passport/email_send_service.rb +32 -0
- data/app/services/tiny_passport/oauth_service.rb +11 -0
- data/app/views/layouts/tiny_passport/mailer.html.erb +7 -0
- data/app/views/tiny_passport/registration_mailer/send_confirmation_token.html.erb +5 -0
- data/app/views/tiny_passport/registration_mailer/welcome.html.erb +5 -0
- data/app/views/tiny_passport/reset_password_mailer/send_token.html.erb +5 -0
- data/config/locales/en/forms.en.yml +81 -0
- data/config/locales/zh-CN/forms.zh-CN.yml +123 -0
- data/config/routes.rb +1 -0
- data/db/migrate/20131105103853_create_tiny_passport_accounts.rb +23 -0
- data/db/migrate/20131105104415_create_tiny_passport_login_records.rb +20 -0
- data/db/migrate/20131105104559_create_tiny_passport_oauth_tokens.rb +27 -0
- data/db/migrate/20131105104632_create_tiny_passport_oauth_logins.rb +15 -0
- data/db/migrate/20131105104702_create_tiny_passport_oauth_binds.rb +16 -0
- data/db/migrate/20131105104738_create_tiny_passport_oauth_infos.rb +13 -0
- data/db/migrate/20131105104847_create_tiny_passport_avatars.rb +20 -0
- data/db/migrate/20131107031935_create_tiny_passport_login_emails.rb +25 -0
- data/lib/omniauth/strategies/qq_connect.rb +114 -0
- data/lib/tiny_passport/config.rb +72 -0
- data/lib/tiny_passport/engine.rb +16 -0
- data/lib/tiny_passport/http_authable.rb +50 -0
- data/lib/tiny_passport/http_authcenter.rb +138 -0
- data/lib/tiny_passport/mailerable.rb +20 -0
- data/lib/tiny_passport/omniauth/strategable.rb +21 -0
- data/lib/tiny_passport/version.rb +2 -1
- data/lib/tiny_passport.rb +13 -0
- data/test/dummy/app/controllers/application_controller.rb +1 -0
- data/test/dummy/app/helpers/application_helper.rb +1 -0
- data/test/dummy/config/application.rb +1 -0
- data/test/dummy/config/boot.rb +1 -0
- data/test/dummy/config/environment.rb +1 -0
- data/test/dummy/config/environments/development.rb +1 -0
- data/test/dummy/config/environments/production.rb +1 -0
- data/test/dummy/config/environments/test.rb +1 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +1 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +1 -0
- data/test/dummy/config/initializers/inflections.rb +1 -0
- data/test/dummy/config/initializers/mime_types.rb +1 -0
- data/test/dummy/config/initializers/secret_token.rb +1 -0
- data/test/dummy/config/initializers/session_store.rb +1 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +1 -0
- data/test/dummy/config/routes.rb +1 -0
- data/test/dummy/db/schema.rb +138 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +15986 -0
- 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 +1 -0
- data/test/fixtures/tiny_passport/avatars.yml +23 -0
- data/test/fixtures/tiny_passport/login_emails.yml +23 -0
- data/test/fixtures/tiny_passport/login_records.yml +17 -0
- data/test/fixtures/tiny_passport/oauth_binds.yml +13 -0
- data/test/fixtures/tiny_passport/oauth_infos.yml +9 -0
- data/test/fixtures/tiny_passport/oauth_logins.yml +11 -0
- data/test/fixtures/tiny_passport/oauth_tokens.yml +21 -0
- data/test/fixtures/tiny_passport/users.yml +13 -0
- data/test/forms/tiny_passport/oauth/callback_form_test.rb +23 -0
- data/test/forms/tiny_passport/registration_form_test.rb +112 -0
- data/test/forms/tiny_passport/session_form_test.rb +139 -0
- data/test/forms/tiny_passport/update_password_form_test.rb +20 -0
- data/test/integration/navigation_test.rb +1 -0
- data/test/mailers/tiny_passport/registration_mailer_test.rb +10 -0
- data/test/mailers/tiny_passport/reset_password_mailer_test.rb +10 -0
- data/test/models/concerns/tiny_passport/configable_test.rb +46 -0
- data/test/models/tiny_passport/account_test.rb +8 -0
- data/test/models/tiny_passport/avatar_test.rb +10 -0
- data/test/models/tiny_passport/login_email_test.rb +10 -0
- data/test/models/tiny_passport/login_record_test.rb +10 -0
- data/test/models/tiny_passport/oauth_bind_test.rb +10 -0
- data/test/models/tiny_passport/oauth_info_test.rb +10 -0
- data/test/models/tiny_passport/oauth_login_test.rb +10 -0
- data/test/models/tiny_passport/oauth_token_test.rb +10 -0
- data/test/support/helpers.rb +66 -0
- data/test/test_helper.rb +24 -0
- data/test/tiny_passport_test.rb +1 -0
- metadata +257 -69
@@ -0,0 +1,89 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module TinyPassport
|
3
|
+
class LoginEmail < ActiveRecord::Base
|
4
|
+
include ::TinySupport::Configable
|
5
|
+
|
6
|
+
self.acts_as_tiny_cached :version => 1
|
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
|
+
]
|
17
|
+
|
18
|
+
belongs_to :account, :class_name => "TinyPassport::Account"
|
19
|
+
|
20
|
+
attr_accessor :confirmation_token, :reset_password_token
|
21
|
+
|
22
|
+
attr_accessible :account
|
23
|
+
|
24
|
+
# confirmation_token ----------------------------------------------
|
25
|
+
def generate_encrypted_confirmation_token
|
26
|
+
self.confirmation_token = ::SecureRandom.base64
|
27
|
+
self.encrypted_confirmation_token = self.class.generate_encrypted_confirmation_token(self.confirmation_token)
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid_confirmation_token?(token)
|
31
|
+
self.encrypted_confirmation_token == self.class.generate_encrypted_confirmation_token(token)
|
32
|
+
end
|
33
|
+
|
34
|
+
# 验证是否过期?
|
35
|
+
def confirmation_token_expires?
|
36
|
+
!!self.confirmation_send_at &&
|
37
|
+
self.confirmation_send_at + ::TinyPassport.config.login_email_confirmation_token_expires_in < Time.now
|
38
|
+
end
|
39
|
+
|
40
|
+
# return login_email or nil
|
41
|
+
def self.authenticate_from_confirmation_token token=''
|
42
|
+
encode_token = self.generate_encrypted_confirmation_token(token)
|
43
|
+
|
44
|
+
self.find_by_encrypted_confirmation_token(encode_token)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.generate_encrypted_confirmation_token(token)
|
48
|
+
Digest::SHA1.hexdigest("#{token}")
|
49
|
+
end
|
50
|
+
|
51
|
+
# 邮箱状态激活
|
52
|
+
def status_active_verify!
|
53
|
+
self.confirmation_token = nil
|
54
|
+
self.confirmed_at = Time.now
|
55
|
+
self.confirmation_send_at = nil
|
56
|
+
self.status_key = 'active'
|
57
|
+
self.encrypted_confirmation_token = ''
|
58
|
+
self.save!
|
59
|
+
end
|
60
|
+
|
61
|
+
# reset_password_token ----------------------------------------------
|
62
|
+
def generate_encrypted_reset_password_token
|
63
|
+
self.reset_password_token = ::SecureRandom.base64
|
64
|
+
self.encrypted_reset_password_token = self.class.generate_encrypted_reset_password_token(self.reset_password_token)
|
65
|
+
end
|
66
|
+
|
67
|
+
def valid_reset_password_token?(token)
|
68
|
+
self.encrypted_reset_password_token == self.class.generate_encrypted_reset_password_token(token)
|
69
|
+
end
|
70
|
+
|
71
|
+
# 验证是否过期?
|
72
|
+
def reset_password_token_expires?
|
73
|
+
!!self.reset_password_token_send_at &&
|
74
|
+
self.reset_password_token_send_at + ::TinyPassport.config.login_email_reset_password_token_expires_in < Time.now
|
75
|
+
end
|
76
|
+
|
77
|
+
# return login_email or nil
|
78
|
+
def self.authenticate_from_reset_password_token token=''
|
79
|
+
encode_token = self.generate_encrypted_reset_password_token(token)
|
80
|
+
|
81
|
+
self.find_by_encrypted_reset_password_token(encode_token)
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.generate_encrypted_reset_password_token(token)
|
85
|
+
Digest::SHA1.hexdigest("#{token}")
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module TinyPassport
|
3
|
+
class LoginRecord < ActiveRecord::Base
|
4
|
+
include ::TinySupport::Configable
|
5
|
+
|
6
|
+
# status_value
|
7
|
+
self.tiny_support_config :way, [
|
8
|
+
{:key => 'default', :value => 0},
|
9
|
+
{:key => 'login_name', :value => 201},
|
10
|
+
{:key => 'login_email', :value => 301},
|
11
|
+
{:key => 'after_login_email_actived', :value => 302}, # 在邮箱激活之后自动登录
|
12
|
+
|
13
|
+
# oauth
|
14
|
+
{:key => 'oauth_qq_connect', :value => 401},
|
15
|
+
{:key => 'oauth_weibo', :value => 402},
|
16
|
+
{:key => 'oauth_github', :value => 403},
|
17
|
+
{:key => 'oauth_google', :value => 404}
|
18
|
+
]
|
19
|
+
|
20
|
+
attr_accessor :remember_token
|
21
|
+
|
22
|
+
belongs_to :account, :class_name => "TinyPassport::Account", :counter_cache => :login_records_count
|
23
|
+
|
24
|
+
# 创建之前需要确认是否生成记住密码的token
|
25
|
+
before_create do |r|
|
26
|
+
if r.remembered?
|
27
|
+
r.remember_token = ::SecureRandom.hex(64)
|
28
|
+
r.encrypted_remember_token = r.class.generate_encrypted_remember_token(r.remember_token)
|
29
|
+
r.remember_expires_at = 3.months.from_now
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
after_create do |r|
|
34
|
+
if r.account
|
35
|
+
r.account.update_columns(
|
36
|
+
:last_login_at => r.created_at,
|
37
|
+
:last_login_record_id => r.id
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def remembered?
|
43
|
+
!!remembered
|
44
|
+
end
|
45
|
+
|
46
|
+
def available?
|
47
|
+
self.remember_sign_out_at.nil? &&
|
48
|
+
self.remember_expires_at.is_a?(::Time) &&
|
49
|
+
self.remember_expires_at > Time.now
|
50
|
+
end
|
51
|
+
|
52
|
+
# 校验是否符合
|
53
|
+
def valid_remember_token?(token)
|
54
|
+
self.encrypted_remember_token == self.class.generate_encrypted_remember_token(token)
|
55
|
+
end
|
56
|
+
|
57
|
+
# return login_record or nil
|
58
|
+
def self.authenticate_from_remember_token token=''
|
59
|
+
encode_token = self.generate_encrypted_remember_token(token)
|
60
|
+
|
61
|
+
self.find_by_encrypted_remember_token(encode_token)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.generate_encrypted_remember_token(token)
|
65
|
+
Digest::SHA1.hexdigest("#{token}")
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module TinyPassport
|
3
|
+
class OauthBind < ActiveRecord::Base
|
4
|
+
belongs_to :account, :class_name => "TinyPassport::Account"
|
5
|
+
belongs_to :oauth_token, :class_name => "TinyPassport::OauthToken"
|
6
|
+
|
7
|
+
attr_accessible :account, :oauth_token
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module TinyPassport
|
3
|
+
class OauthLogin < ActiveRecord::Base
|
4
|
+
include ::TinySupport::Configable
|
5
|
+
|
6
|
+
self.acts_as_tiny_cached :version => 1
|
7
|
+
self.tiny_support_display
|
8
|
+
|
9
|
+
belongs_to :account, :class_name => "TinyPassport::Account"
|
10
|
+
belongs_to :oauth_token, :class_name => "TinyPassport::OauthToken"
|
11
|
+
|
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
|
+
attr_accessible :account, :oauth_token
|
23
|
+
|
24
|
+
def oauth_token?
|
25
|
+
!!oauth_token
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module TinyPassport
|
3
|
+
class OauthToken < ActiveRecord::Base
|
4
|
+
include ::TinySupport::Configable
|
5
|
+
# 用于登录的
|
6
|
+
has_one :oauth_login, :class_name => "TinyPassport::OauthLogin"
|
7
|
+
|
8
|
+
self.acts_as_tiny_cached :version => 1
|
9
|
+
self.tiny_support_display
|
10
|
+
|
11
|
+
# 长字段信息
|
12
|
+
has_one :oauth_info, :class_name => "TinyPassport::OauthInfo"
|
13
|
+
# 被绑定的
|
14
|
+
has_many :oauth_binds, :class_name => "TinyPassport::OauthBind"
|
15
|
+
# 被绑定的账户信息
|
16
|
+
has_many :bind_accounts, :class_name => "TinyPassport::Account", :through => :oauth_binds, :source => :account
|
17
|
+
|
18
|
+
self.tiny_support_config :strategy_type, [
|
19
|
+
{:key => 'qq_connect', :value => 1}
|
20
|
+
]
|
21
|
+
|
22
|
+
attr_accessible :strategy_type_value,
|
23
|
+
:strategy_id,
|
24
|
+
:access_token,
|
25
|
+
:access_secret,
|
26
|
+
:expires_at,
|
27
|
+
:origin_avatar_url,
|
28
|
+
:name,
|
29
|
+
:nick_name
|
30
|
+
|
31
|
+
def strategy_name
|
32
|
+
I18n.t("tiny_passport.oauth.providers.#{self.strategy_type_key}.name")
|
33
|
+
end
|
34
|
+
|
35
|
+
# 已经绑定登录帐号了
|
36
|
+
def login_account?
|
37
|
+
!!(self.login_account)
|
38
|
+
end
|
39
|
+
|
40
|
+
def oauth_login?
|
41
|
+
!!(self.oauth_login)
|
42
|
+
end
|
43
|
+
|
44
|
+
def login_account
|
45
|
+
self.oauth_login? ? self.oauth_login.account : nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def bind_accounts?
|
49
|
+
self.bind_accounts.to_a.any?
|
50
|
+
end
|
51
|
+
|
52
|
+
def not_login_connect_to? key
|
53
|
+
key == self.strategy_type_key && !(self.login_account?)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module TinyPassport
|
2
|
+
class AccountQuery
|
3
|
+
include ::TinyPassport::QueryAble
|
4
|
+
|
5
|
+
attr_reader :account
|
6
|
+
|
7
|
+
def initialize account
|
8
|
+
@account = account
|
9
|
+
end
|
10
|
+
|
11
|
+
# {
|
12
|
+
# :oauth_logins => [
|
13
|
+
# {
|
14
|
+
# :strategy => {:type => :taobao, :id => 'ABCDEFGHIJK'},
|
15
|
+
# :nick_name => 'ABCE',
|
16
|
+
# :name => 'ABCE',
|
17
|
+
# :avatar => {
|
18
|
+
# :normal => '',
|
19
|
+
# :big => '',
|
20
|
+
# :origin => '',
|
21
|
+
# },
|
22
|
+
# :crated_at => '2013-12-30 23:22:34',
|
23
|
+
# :updated_at => '2013-12-30 23:22:34',
|
24
|
+
# :expires_at => '2013-12-30 23:22:34',
|
25
|
+
# :access_token => '',
|
26
|
+
# :access_secret => '',
|
27
|
+
# :status => {:value => 1, :key => :default}
|
28
|
+
# }
|
29
|
+
# ]
|
30
|
+
# }
|
31
|
+
def oauth_logins_data options={}
|
32
|
+
options = query_normalize_options options
|
33
|
+
|
34
|
+
oauth_logins = self.account.oauth_logins.joins(:oauth_token).page(options[:page] || 1).per(options[:per_page] || 20)
|
35
|
+
|
36
|
+
result = {}
|
37
|
+
|
38
|
+
result[:oauth_logins] = oauth_logins.map do |login|
|
39
|
+
login.display.basic
|
40
|
+
end
|
41
|
+
|
42
|
+
result
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module TinyPassport
|
3
|
+
class AccountService # 用户服务
|
4
|
+
include ::TinySupport::Serviceable
|
5
|
+
|
6
|
+
# TODO: 修改密码
|
7
|
+
def update_password_with_params params={}
|
8
|
+
form = ::TinyPassport::UpdatePasswordForm.new
|
9
|
+
form.submit params
|
10
|
+
form
|
11
|
+
end
|
12
|
+
|
13
|
+
# TODO: 重置密码
|
14
|
+
def reset_password_with_params params={}
|
15
|
+
form = ::TinyPassport::ResetPasswordForm.new
|
16
|
+
form.submit params
|
17
|
+
form
|
18
|
+
end
|
19
|
+
|
20
|
+
# TODO: 请求激活
|
21
|
+
def request_confirmation_token_with_params params={}
|
22
|
+
form = ::TinyPassport::ConfirmationTokenForm.new
|
23
|
+
form.submit params
|
24
|
+
form
|
25
|
+
end
|
26
|
+
|
27
|
+
# 生成一个重置密码的请求
|
28
|
+
# TODO:
|
29
|
+
def request_reset_password_with_params params={}
|
30
|
+
form = ::TinyPassport::ResetPasswordTokenForm.new
|
31
|
+
form.submit params
|
32
|
+
form
|
33
|
+
end
|
34
|
+
|
35
|
+
# 使用参数激活
|
36
|
+
def active_with_params params={}
|
37
|
+
form = ::TinyPassport::AccountActiveForm.new
|
38
|
+
form.submit params
|
39
|
+
form
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module TinyPassport
|
3
|
+
# 邮箱发送服务
|
4
|
+
class EmailSendService
|
5
|
+
include ::TinySupport::Serviceable
|
6
|
+
|
7
|
+
# 用户激活后发送欢迎语
|
8
|
+
# TODO:
|
9
|
+
def send_welcome_for_active params={}
|
10
|
+
form = ::TinyPassport::WelcomeEmailForm.new
|
11
|
+
form.submit params
|
12
|
+
form
|
13
|
+
end
|
14
|
+
|
15
|
+
# 为login_email, 发送验证码
|
16
|
+
def send_confirmation_token_for_active params={}
|
17
|
+
form = ::TinyPassport::ConfirmationTokenForm.new
|
18
|
+
form.submit params
|
19
|
+
form
|
20
|
+
end
|
21
|
+
|
22
|
+
# 为了找回密码,来发送验证码
|
23
|
+
def send_confirmation_token_for_reset_password params={}
|
24
|
+
form = ::TinyPassport::RequestResetPasswordForm.new
|
25
|
+
form.submit params
|
26
|
+
form
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
en:
|
2
|
+
tiny_passport:
|
3
|
+
oauth:
|
4
|
+
providers:
|
5
|
+
qq_connect:
|
6
|
+
name: 'QQ'
|
7
|
+
|
8
|
+
activemodel:
|
9
|
+
models:
|
10
|
+
tiny_passport/registration_form: 'Registration Infomation'
|
11
|
+
tiny_passport/session_form: 'Session'
|
12
|
+
tiny_passport/confirmation_token_form: 'Confirmation Token'
|
13
|
+
tiny_passport/reset_password_token_form: 'Reset Password Token'
|
14
|
+
attributes:
|
15
|
+
tiny_passport/reset_password_token_form:
|
16
|
+
login_email_value: Login Email
|
17
|
+
|
18
|
+
tiny_passport/confirmation_token_form:
|
19
|
+
login_email_value: Login Email
|
20
|
+
|
21
|
+
tiny_passport/session_form:
|
22
|
+
input_value: Login Name or Email
|
23
|
+
|
24
|
+
tiny_passport/registration_form:
|
25
|
+
login_email_value: Email
|
26
|
+
login_name: Login Name
|
27
|
+
password: Password
|
28
|
+
password_confirmation: Password Confirmation
|
29
|
+
agreement_terms: Agree with our agreement
|
30
|
+
|
31
|
+
errors:
|
32
|
+
models:
|
33
|
+
tiny_passport/registration_form:
|
34
|
+
attributes:
|
35
|
+
agreement_terms:
|
36
|
+
not_agree: Please Agree with our agreement
|
37
|
+
|
38
|
+
tiny_passport/confirmation_token_form:
|
39
|
+
attributes:
|
40
|
+
login_email_value:
|
41
|
+
already_active: 'already active'
|
42
|
+
not_found: 'not found'
|
43
|
+
|
44
|
+
tiny_passport/session_form:
|
45
|
+
attributes:
|
46
|
+
input_value:
|
47
|
+
login_email_not_exists: "email not exists"
|
48
|
+
login_name_not_exists: "login name not exists"
|
49
|
+
login_email_wrong: "login email wrong"
|
50
|
+
login_email_not_active: "email not active"
|
51
|
+
password:
|
52
|
+
wrong: "wrong"
|
53
|
+
|
54
|
+
tiny_passport/update_password_form:
|
55
|
+
attributes:
|
56
|
+
current_password:
|
57
|
+
not_matached: 'not match'
|
58
|
+
password:
|
59
|
+
not_changed: 'not change'
|
60
|
+
|
61
|
+
tiny_passport/reset_password_token_form:
|
62
|
+
attributes:
|
63
|
+
login_email_value:
|
64
|
+
not_found: 'not found'
|
65
|
+
not_active: 'not active'
|
66
|
+
|
67
|
+
tiny_passport/reset_password_form:
|
68
|
+
attributes:
|
69
|
+
base:
|
70
|
+
invalid: 'invalid'
|
71
|
+
reset_password_token:
|
72
|
+
not_found: 'not found'
|
73
|
+
|
74
|
+
tiny_passport/account_active_form:
|
75
|
+
attributes:
|
76
|
+
base:
|
77
|
+
invalid: 'invalid'
|
78
|
+
confirmation_token:
|
79
|
+
already_active: 'alreay active'
|
80
|
+
expired: 'expired'
|
81
|
+
not_matched: 'mismatch'
|
@@ -0,0 +1,123 @@
|
|
1
|
+
zh-CN:
|
2
|
+
tiny_passport:
|
3
|
+
oauth:
|
4
|
+
providers:
|
5
|
+
qq_connect:
|
6
|
+
name: 'QQ登录'
|
7
|
+
weibo:
|
8
|
+
name: '新浪微博'
|
9
|
+
github:
|
10
|
+
name: 'Github'
|
11
|
+
google:
|
12
|
+
name: 'Google'
|
13
|
+
|
14
|
+
activemodel:
|
15
|
+
models:
|
16
|
+
tiny_passport/registration_form: '注册信息'
|
17
|
+
tiny_passport/session_form: '登录信息'
|
18
|
+
tiny_passport/confirmation_token_form: '激活码'
|
19
|
+
tiny_passport/reset_password_token_form: '验证码'
|
20
|
+
tiny_passport/reset_password_form: '重置密码'
|
21
|
+
attributes:
|
22
|
+
tiny_passport/reset_password_token_form:
|
23
|
+
login_email_value: '登录邮箱'
|
24
|
+
|
25
|
+
tiny_passport/confirmation_token_form:
|
26
|
+
login_email_value: '登录邮箱'
|
27
|
+
|
28
|
+
tiny_passport/update_password_form:
|
29
|
+
password: '密码'
|
30
|
+
current_password: '当前密码'
|
31
|
+
password_confirmation: '密码确认'
|
32
|
+
|
33
|
+
tiny_passport/session_form:
|
34
|
+
input_value: '用户名或登录邮箱'
|
35
|
+
password: '密码'
|
36
|
+
remembered: '记住登录状态'
|
37
|
+
|
38
|
+
tiny_passport/registration_form:
|
39
|
+
login_email_value: '电子邮箱'
|
40
|
+
login_name: '用户名'
|
41
|
+
password: '密码'
|
42
|
+
password_confirmation: '密码确认'
|
43
|
+
agreement_terms: '同意我们的协议'
|
44
|
+
tiny_captcha: '验证码'
|
45
|
+
|
46
|
+
tiny_passport/reset_password_form:
|
47
|
+
password: '密码'
|
48
|
+
password_confirmation: '密码确认'
|
49
|
+
|
50
|
+
|
51
|
+
errors:
|
52
|
+
models:
|
53
|
+
tiny_passport/registration_form:
|
54
|
+
attributes:
|
55
|
+
agreement_terms:
|
56
|
+
not_agree: '请同意我们的协议'
|
57
|
+
login_name:
|
58
|
+
invalid: "无效"
|
59
|
+
login_email_value:
|
60
|
+
invalid: "无效"
|
61
|
+
password:
|
62
|
+
too_short: "长度不够"
|
63
|
+
blank: "不能为空"
|
64
|
+
password_confirmation:
|
65
|
+
confirmation: "两次输入不一致"
|
66
|
+
|
67
|
+
tiny_passport/confirmation_token_form:
|
68
|
+
attributes:
|
69
|
+
login_email_value:
|
70
|
+
already_active: '已经激活'
|
71
|
+
not_found: '没有找到'
|
72
|
+
invalid: '无效'
|
73
|
+
|
74
|
+
tiny_passport/session_form:
|
75
|
+
attributes:
|
76
|
+
input_value:
|
77
|
+
blank: "不能为空"
|
78
|
+
login_email_not_exists: "邮箱不存在"
|
79
|
+
login_name_not_exists: "用户名不存在"
|
80
|
+
login_email_wrong: "登录邮箱错误"
|
81
|
+
login_email_not_active: "登录邮箱没有激活"
|
82
|
+
password:
|
83
|
+
wrong: "错误"
|
84
|
+
blank: "不能为空"
|
85
|
+
|
86
|
+
tiny_passport/update_password_form:
|
87
|
+
attributes:
|
88
|
+
current_password:
|
89
|
+
not_matached: '不匹配'
|
90
|
+
password:
|
91
|
+
not_changed: '没有修改'
|
92
|
+
|
93
|
+
tiny_passport/reset_password_token_form:
|
94
|
+
attributes:
|
95
|
+
login_email_value:
|
96
|
+
not_found: '没有找到'
|
97
|
+
not_active: '没有激活'
|
98
|
+
invalid: "无效"
|
99
|
+
blank: "不能为空"
|
100
|
+
|
101
|
+
tiny_passport/reset_password_form:
|
102
|
+
attributes:
|
103
|
+
base:
|
104
|
+
invalid: '无效的'
|
105
|
+
reset_password_token:
|
106
|
+
not_found: '没有找到'
|
107
|
+
blank: '不能为空'
|
108
|
+
password:
|
109
|
+
invalid: '无效'
|
110
|
+
blank: '不能为空'
|
111
|
+
too_short: '长度不足'
|
112
|
+
password_confirmation:
|
113
|
+
confirmation: "两次输入不一致"
|
114
|
+
|
115
|
+
tiny_passport/account_active_form:
|
116
|
+
attributes:
|
117
|
+
base:
|
118
|
+
invalid: '无效的'
|
119
|
+
confirmation_token:
|
120
|
+
already_active: '已经激活'
|
121
|
+
expired: '过期了'
|
122
|
+
not_matched: '不匹配'
|
123
|
+
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class CreateTinyPassportAccounts < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :tiny_passport_accounts do |t|
|
5
|
+
t.string :login_name
|
6
|
+
t.integer :avatar_id
|
7
|
+
t.string :created_ip, :default => '', :null => false # IP
|
8
|
+
t.string :encrypted_password, :default => '', :null => false
|
9
|
+
t.string :password_salt, :default => '', :null => false
|
10
|
+
t.integer :register_way_value, :default => 0, :null => false
|
11
|
+
t.datetime :deleted_at
|
12
|
+
t.datetime :last_login_at # 上一次登录时间
|
13
|
+
t.integer :login_records_count, :default => 0, :null => false
|
14
|
+
t.integer :current_login_failed_count, :default => 0, :null => false
|
15
|
+
t.integer :login_failed_count, :default => 0, :null => false
|
16
|
+
t.integer :last_login_record_id #上一次登录的记录
|
17
|
+
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
|
21
|
+
add_index :tiny_passport_accounts, [:login_name], :unique => true
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class CreateTinyPassportLoginRecords < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :tiny_passport_login_records do |t|
|
5
|
+
t.integer :account_id
|
6
|
+
t.string :ip, :default => '', :null => false
|
7
|
+
t.string :last_remembered_ip, :default => '', :null => false
|
8
|
+
t.integer :way_value, :default => 0, :null => false
|
9
|
+
t.boolean :remembered, :default => false, :null => false
|
10
|
+
t.string :encrypted_remember_token, :default => '', :null => false
|
11
|
+
t.datetime :remember_expires_at
|
12
|
+
t.integer :remembered_count, :default => 0, :null => false
|
13
|
+
t.datetime :remember_sign_out_at # 主动退出时间
|
14
|
+
|
15
|
+
t.timestamps
|
16
|
+
end
|
17
|
+
|
18
|
+
add_index :tiny_passport_login_records, [:account_id]
|
19
|
+
end
|
20
|
+
end
|