tokak_engine 0.0.5 → 0.0.6

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/Rakefile CHANGED
@@ -49,3 +49,6 @@ rescue LoadError
49
49
  end
50
50
  task :rdoc => :yardoc
51
51
  task :doc => :yardoc
52
+
53
+ desc "Bump gem version, release and install"
54
+ task :push => %w(version:bump:patch release gemcutter:release install)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.6
@@ -11,6 +11,7 @@ class UserAvatar < ActiveRecord::Base
11
11
  if url = pavatar.avatar_url_for(openid_identifier, :pavatar_field => :openid_identifier)
12
12
  openid_identifier.user.avatars.create(:url => url)
13
13
  end
14
+ rescue
14
15
  end
15
16
 
16
17
  def self.discover_from_user(user)
@@ -1,10 +1,9 @@
1
1
  module TokakEngine
2
- module Application
3
- extend self
4
- mattr_accessor :config
2
+ class Application
3
+ @@config = nil
5
4
 
6
5
  # Default configuration options
7
- def default_config
6
+ def self.default_config
8
7
  @@default_config = {
9
8
  :canonical_host => 'tokak.ru',
10
9
  :domain => '.tokak.ru'
@@ -13,36 +12,37 @@ module TokakEngine
13
12
 
14
13
  # Autoload application config from application.yml
15
14
  # @return [Hash] application configuration for current environment
16
- def config
17
- unless @@config
18
- file_name = File.join(Rails.root, 'config', 'application.yml')
19
- @@config = if File.exists?(file_name)
20
- YAML.load_file(file_name).
21
- to_hash.
22
- with_indifferent_access[Rails.env]
23
- else
24
- {}
25
- end.reverse_merge!(default_config)
26
- end
27
- @@config
15
+ def self.config
16
+ @@config ||= load_config
17
+ end
18
+
19
+ def self.load_config
20
+ file_name = File.join(Rails.root, 'config', 'application.yml')
21
+ @@config = if File.exists?(file_name)
22
+ YAML.load_file(file_name).
23
+ to_hash.
24
+ with_indifferent_access[Rails.env]
25
+ else
26
+ {}
27
+ end.reverse_merge!(default_config)
28
28
  end
29
29
 
30
30
  # Retuns configured canonical host
31
- def canonical_host
31
+ def self.canonical_host
32
32
  config[:canonical_host]
33
33
  end
34
34
 
35
35
  # Returns configured session domain
36
- def domain
36
+ def self.domain
37
37
  config[:domain]
38
38
  end
39
39
 
40
- def passport_url
40
+ def self.passport_url
41
41
  "http://passport#{domain}/"
42
42
  end
43
43
 
44
44
  # Initialize canonical host and cookies (session) domain
45
- def init_engine
45
+ def self.init_engine
46
46
  ActionController::Base.session_options[:domain] = domain
47
47
  ActionController::Dispatcher.middleware.use 'CanonicalHost', canonical_host
48
48
  end
@@ -2,16 +2,25 @@ module TokakEngine
2
2
  module Authentication
3
3
 
4
4
  def self.included(controller)
5
- controller.send(:include, InstanceMethods)
6
5
  controller.extend(ClassMethods)
6
+ controller.send(:include, InstanceMethods)
7
+ controller.helper_method :current_user_session, :current_user, :logged_in?
8
+ controller.hide_action :current_user_session, :current_user, :logged_in?,
9
+ :require_user, :require_no_user,
10
+ :store_location, :redirect_back_or_default
7
11
  end
8
12
 
9
13
  module ClassMethods
10
- def self.extended(controller)
11
- controller.helper_method :current_user_session, :current_user, :logged_in?
12
- controller.hide_action :current_user_session, :current_user, :logged_in?,
13
- :require_user, :require_no_user,
14
- :store_location, :redirect_back_or_default
14
+ # Shortcut for {#require_user} filter
15
+ # @param [Hash] options for filter
16
+ def require_user(options = {})
17
+ before_filter(:require_user, options)
18
+ end
19
+
20
+ # Shortcut for {#require_no_user} filter
21
+ # @param [Hash] options for filter
22
+ def require_no_user(options = {})
23
+ before_filter(:require_no_user, options)
15
24
  end
16
25
  end
17
26
 
@@ -1 +1 @@
1
- require 'tokak­engine'
1
+ require 'tokak_engine'
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tokak_engine}
8
- s.version = "0.0.5"
8
+ s.version = "0.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexander Semyonov"]
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
23
23
  "app/helpers/tokak_helper.rb",
24
24
  "app/models/identifier.rb",
25
25
  "app/models/openid_identifier.rb",
26
- "app/models/user.rb",
27
26
  "app/models/user_avatar.rb",
28
27
  "app/models/user_session.rb",
29
28
  "app/views/user_avatars/_user_avatar.html.haml",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tokak_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Semyonov
@@ -30,7 +30,6 @@ files:
30
30
  - app/helpers/tokak_helper.rb
31
31
  - app/models/identifier.rb
32
32
  - app/models/openid_identifier.rb
33
- - app/models/user.rb
34
33
  - app/models/user_avatar.rb
35
34
  - app/models/user_session.rb
36
35
  - app/views/user_avatars/_user_avatar.html.haml
@@ -1,168 +0,0 @@
1
- class User < ActiveRecord::Base
2
- OPENID_GENDER_MAP = {
3
- 'M' => 1,
4
- 'F' => 2
5
- }
6
- PERSONAL_INFORMATION = %w(first_name last_name nick_name gender was_born_on)
7
- OPTIONAL_OPENID_FIELDS = %w(email fullname nickname timezone language country gender dob).map(&:to_sym)
8
-
9
- include TokakEngine::User
10
-
11
- with_options :dependent => :destroy do |d|
12
- d.has_many :openid_identifiers
13
- end
14
- attr_accessor :openid_identifier
15
- accepts_nested_attributes_for :openid_identifiers, :allow_destroy => true
16
-
17
- after_create :set_openid
18
- after_save :discover_avatar
19
-
20
- acts_as_authentic do |c|
21
- c.openid_optional_fields(OPTIONAL_OPENID_FIELDS)
22
- c.validate :validate_openid
23
- c.validates_length_of_password_field_options validates_length_of_password_field_options.merge(:if => :validate_password_with_openid?)
24
- c.validates_confirmation_of_password_field_options validates_confirmation_of_password_field_options.merge(:if => :validate_password_with_openid?)
25
- c.validates_length_of_password_confirmation_field_options validates_length_of_password_confirmation_field_options.merge(:if => :validate_password_with_openid?)
26
- end
27
-
28
- def self.name_field; :email end
29
-
30
- def self.find_by_openid_identifier(identifier)
31
- first(:conditions => {
32
- Identifier.table_name => {
33
- :openid_identifier => identifier}},
34
- :joins => :openid_identifiers)
35
- end
36
-
37
- def openid_identifier=(value)
38
- @openid_identifier = value.blank? ? nil : OpenIdAuthentication.normalize_identifier(value)
39
- reset_persistence_token if openid_identifier_changed?
40
- rescue OpenIdAuthentication::InvalidOpenId => e
41
- @openid_error = e.message
42
- end
43
-
44
- private
45
-
46
- def using_openid?
47
- !@openid_identifier.blank? || openid_identifiers.any?
48
- end
49
-
50
- def openid_identifier_changed?
51
- !openid_identifiers.detect { |i| i.openid_identifier == @openid_identifier }
52
- end
53
-
54
- def authenticate_with_openid
55
- @openid_error = nil
56
-
57
- if !openid_complete?
58
- session_class.controller.session[:openid_attributes] = attributes_to_save
59
- else
60
- map_saved_attributes(session_class.controller.session[:openid_attributes])
61
- session_class.controller.session[:openid_attributes] = nil
62
- end
63
-
64
- options = {}
65
- options[:required] = self.class.openid_required_fields
66
- options[:optional] = self.class.openid_optional_fields
67
- options[:return_to] = session_class.controller.url_for(:for_model => "1")
68
-
69
- session_class.controller.send(:authenticate_with_open_id, openid_identifier, options) do |result, openid_identifier, registration|
70
- if result.unsuccessful?
71
- @openid_error = result.message
72
- else
73
- self.openid_identifier = openid_identifier
74
- map_openid_registration(registration.symbolize_keys)
75
- end
76
-
77
- return true
78
- end
79
-
80
- return false
81
- end
82
-
83
- def set_openid
84
- self.openid_identifiers.create(:openid_identifier => @openid_identifier) unless @openid_identifier.blank?
85
- end
86
-
87
- def map_openid_registration(registration) # :doc:
88
- unless registration[:email].blank? || self.email.present?
89
- self.email = registration[:email]
90
- end
91
-
92
- unless registration[:fullname].blank?
93
- if respond_to?(:name)
94
- self.name = registration[:fullname] if name.blank? && !registration[:fullname].blank?
95
- else
96
- first, last = registration[:fullname].split(/\s+/, 2)
97
- self.first_name = first if first_name.blank?
98
- self.last_name = last if last_name.blank?
99
- end
100
- end
101
-
102
- unless registration[:gender].blank? || gender.present?
103
- self.gender_id = OPENID_GENDER_MAP[registration[:gender].upcase]
104
- end
105
-
106
- unless registration[:nickname].blank? || nick_name.present?
107
- self.nick_name = registration[:nickname]
108
- end
109
-
110
- unless registration[:dob].blank? || was_born_on.present?
111
- self.was_born_on = Date.parse(registration[:dob])
112
- end
113
-
114
- unless registration[:country].blank? || country.present?
115
- self.country = Country.find_or_create_by_code(registration[:country])
116
- end
117
-
118
- unless registration[:language].blank? || language.present?
119
- self.language = Language.find_or_create_by_code(registration[:language])
120
- end
121
-
122
- unless registration[:timezone].blank? || timezone.present?
123
- self.timezone = registration[:timezone]
124
- end
125
- end
126
-
127
- def validate_openid
128
- errors.add(:openid_identifier, "had the following error: #{@openid_error}") if @openid_error && @openid_identifier
129
- end
130
-
131
- def discover_avatar
132
- if email_changed?
133
- UserAvatar.discover_from_user(self)
134
- end
135
- end
136
-
137
- end
138
-
139
- # == Schema Info
140
- #
141
- # Table name: users
142
- #
143
- # id :integer not null, primary key
144
- # avatar_id :integer
145
- # country_id :integer
146
- # gender_id :integer
147
- # language_id :integer
148
- # crypted_password :string(255)
149
- # current_login_ip :string(255)
150
- # email :string(255)
151
- # failed_login_count :integer not null, default(0)
152
- # first_name :string(255)
153
- # last_login_ip :string(255)
154
- # last_name :string(255)
155
- # login_count :integer not null, default(0)
156
- # nick_name :string(255)
157
- # password_salt :string(255)
158
- # perishable_token :string(255) not null
159
- # persistence_token :string(255) not null
160
- # postcode :string(255)
161
- # single_access_token :string(255) not null
162
- # timezone :string(255)
163
- # was_born_on :date
164
- # created_at :datetime
165
- # current_login_at :datetime
166
- # last_login_at :datetime
167
- # last_request_at :datetime
168
- # updated_at :datetime