tokak_engine 0.0.2
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/.gitignore +1 -0
- data/MIT-LICENSE +20 -0
- data/README +13 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/app/helpers/tokak_helper.rb +9 -0
- data/app/models/identifier.rb +14 -0
- data/app/models/openid_identifier.rb +23 -0
- data/app/models/user.rb +168 -0
- data/app/models/user_avatar.rb +36 -0
- data/app/models/user_session.rb +3 -0
- data/app/views/user_avatars/_user_avatar.html.haml +3 -0
- data/app/views/user_avatars/index.html.haml +3 -0
- data/app/views/users/_user_bar.html.haml +11 -0
- data/db/migrate/20090926100710_create_users.rb +19 -0
- data/db/migrate/20091017071436_create_identifiers.rb +14 -0
- data/db/migrate/20091017071522_create_openid_identifiers.rb +9 -0
- data/db/migrate/20091017071730_add_open_id_authentication_tables.rb +20 -0
- data/db/migrate/20091017090208_do_not_require_password.rb +14 -0
- data/db/migrate/20091017102110_add_info_to_user.rb +16 -0
- data/db/migrate/20091019040959_create_user_avatars.rb +14 -0
- data/db/migrate/20091019041254_discover_avatars_from_openid.rb +10 -0
- data/db/migrate/20091019043008_discover_avatars_from_email.rb +10 -0
- data/db/migrate/20091019051628_add_current_avatar_to_user.rb +9 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/canonical_host.rb +22 -0
- data/lib/tokak_engine/application.rb +9 -0
- data/lib/tokak_engine/authentication.rb +75 -0
- data/lib/tokak_engine/user.rb +49 -0
- data/lib/tokak_engine.rb +8 -0
- data/rails/init.rb +1 -0
- data/tasks/tokak_engine_tasks.rake +4 -0
- data/test/test_helper.rb +3 -0
- data/test/tokak_engine_test.rb +8 -0
- data/tokak_engine.gemspec +76 -0
- data/uninstall.rb +1 -0
- metadata +92 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = 'tokak_engine'
|
8
|
+
gem.summary = %Q{TokakEngine is an engine to use same users trough all applications}
|
9
|
+
gem.email = 'rotuka@tokak.ru'
|
10
|
+
gem.homepage = 'http://vnutri.tokak.ru/projects/tokak_engine'
|
11
|
+
gem.authors = ['Alexander Semyonov']
|
12
|
+
end
|
13
|
+
Jeweler::GemcutterTasks.new
|
14
|
+
rescue LoadError
|
15
|
+
puts 'Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler'
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'rake/testtask'
|
19
|
+
desc 'Test the tokak_engine plugin.'
|
20
|
+
Rake::TestTask.new(:test) do |t|
|
21
|
+
t.libs << 'lib' << 'test'
|
22
|
+
t.pattern = 'test/**/*_test.rb'
|
23
|
+
t.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'Default: run unit tests.'
|
40
|
+
task :default => :test
|
41
|
+
|
42
|
+
begin
|
43
|
+
require 'yard'
|
44
|
+
YARD::Rake::YardocTask.new
|
45
|
+
rescue LoadError
|
46
|
+
task :yardoc do
|
47
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
48
|
+
end
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Identifier < ActiveRecord::Base
|
2
|
+
belongs_to :user
|
3
|
+
end
|
4
|
+
|
5
|
+
# == Schema Info
|
6
|
+
#
|
7
|
+
# Table name: identifiers
|
8
|
+
#
|
9
|
+
# id :integer not null, primary key
|
10
|
+
# user_id :integer
|
11
|
+
# openid_identifier :string(255)
|
12
|
+
# type :string(255)
|
13
|
+
# created_at :datetime
|
14
|
+
# updated_at :datetime
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class OpenidIdentifier < Identifier
|
2
|
+
validates_uniqueness_of :openid_identifier
|
3
|
+
validates_presence_of :openid_identifier
|
4
|
+
after_create :discover_avatar
|
5
|
+
|
6
|
+
def self.name_field; :openid_identifier end
|
7
|
+
|
8
|
+
protected
|
9
|
+
def discover_avatar
|
10
|
+
UserAvatar.discover_from_openid_identifier(self)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# == Schema Info
|
15
|
+
#
|
16
|
+
# Table name: identifiers
|
17
|
+
#
|
18
|
+
# id :integer not null, primary key
|
19
|
+
# user_id :integer
|
20
|
+
# openid_identifier :string(255)
|
21
|
+
# type :string(255)
|
22
|
+
# created_at :datetime
|
23
|
+
# updated_at :datetime
|
data/app/models/user.rb
ADDED
@@ -0,0 +1,168 @@
|
|
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
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class UserAvatar < ActiveRecord::Base
|
2
|
+
unloadable
|
3
|
+
|
4
|
+
belongs_to :user, :class_name => 'User'
|
5
|
+
|
6
|
+
validates_presence_of :user_id, :url
|
7
|
+
validates_uniqueness_of :url
|
8
|
+
|
9
|
+
def self.discover_from_openid_identifier(openid_identifier)
|
10
|
+
pavatar = Avatar::Source::PavatarSource.new
|
11
|
+
if url = pavatar.avatar_url_for(openid_identifier, :pavatar_field => :openid_identifier)
|
12
|
+
openid_identifier.user.avatars.create(:url => url)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.discover_from_user(user)
|
17
|
+
gravatar = Avatar::Source::GravatarSource.new
|
18
|
+
if url = gravatar.avatar_url_for(user)
|
19
|
+
user.avatars.create(:url => url)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
url
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# == Schema Info
|
29
|
+
#
|
30
|
+
# Table name: user_avatars
|
31
|
+
#
|
32
|
+
# id :integer not null, primary key
|
33
|
+
# user_id :integer
|
34
|
+
# url :string(255)
|
35
|
+
# created_at :datetime
|
36
|
+
# updated_at :datetime
|
@@ -0,0 +1,11 @@
|
|
1
|
+
%aside.b_user_bar
|
2
|
+
- if logged_in?
|
3
|
+
= user_avatar(current_user)
|
4
|
+
%h2= link_to(h(current_user), account_path)
|
5
|
+
%ul.actions<
|
6
|
+
%li>= link_to(t('.edit'), edit_account_path)
|
7
|
+
%li>= link_to(t('.signout'), signout_path)
|
8
|
+
- else
|
9
|
+
%ul.actions<
|
10
|
+
%li>= link_to(t('.signin'), signin_path)
|
11
|
+
%li>= link_to(t('.signup'), signup_path)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateUsers < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :users do |t|
|
4
|
+
t.string :email, :crypted_password, :password_salt,
|
5
|
+
:persistence_token, :single_access_token, :perishable_token,
|
6
|
+
:null => false
|
7
|
+
t.integer :login_count, :failed_login_count,
|
8
|
+
:null => false, :default => 0
|
9
|
+
t.string :current_login_ip, :last_login_ip
|
10
|
+
t.datetime :last_request_at, :current_login_at, :last_login_at
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
drop_table :users
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class AddOpenIdAuthenticationTables < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :open_id_authentication_associations, :force => true do |t|
|
4
|
+
t.integer :issued, :lifetime
|
5
|
+
t.string :handle, :assoc_type
|
6
|
+
t.binary :server_url, :secret
|
7
|
+
end
|
8
|
+
|
9
|
+
create_table :open_id_authentication_nonces, :force => true do |t|
|
10
|
+
t.integer :timestamp, :null => false
|
11
|
+
t.string :server_url, :null => true
|
12
|
+
t.string :salt, :null => false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
drop_table :open_id_authentication_associations
|
18
|
+
drop_table :open_id_authentication_nonces
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class DoNotRequirePassword < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_column :users, :email, :string, :default => nil, :null => true
|
4
|
+
change_column :users, :crypted_password, :string, :default => nil, :null => true
|
5
|
+
change_column :users, :password_salt, :string, :default => nil, :null => true
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.down
|
9
|
+
[:email, :crypted_password, :password_salt].each do |field|
|
10
|
+
User.all(:conditions => "#{field} is NULL").each { |user| user.update_attribute(field, "") if user.send(field).nil? }
|
11
|
+
change_column :users, field, :string, :default => "", :null => false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class AddInfoToUser < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_table :users do |t|
|
4
|
+
t.string :first_name, :last_name, :nick_name, :postcode, :timezone
|
5
|
+
t.date :was_born_on
|
6
|
+
t.integer :gender_id, :country_id, :language_id
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
change_table :users do |t|
|
12
|
+
t.remove :first_name, :last_name, :nick_name, :postcode, :timezone,
|
13
|
+
:was_born_on, :gender_id, :country_id, :language_id
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'tokak_engine'
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CanonicalHost
|
2
|
+
def initialize(app, host=nil, &block)
|
3
|
+
@app = app
|
4
|
+
@host = (block_given? && block.call) || host
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
if url = url(env)
|
9
|
+
[301, { 'Location' => url }, ['Redirecting...']]
|
10
|
+
else
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def url(env)
|
16
|
+
if @host && env['SERVER_NAME'] != @host
|
17
|
+
url = Rack::Request.new(env).url
|
18
|
+
url.sub(/dispatch\.fcgi/, '').sub(%r{\A(https?://)(.*?)(:\d+)?(/|$)}, "\\1#{@host}\\3/")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
private :url
|
22
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module TokakEngine
|
2
|
+
module Authentication
|
3
|
+
|
4
|
+
def self.included(controller)
|
5
|
+
controller.send(:include, InstanceMethods)
|
6
|
+
controller.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
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
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module InstanceMethods
|
19
|
+
def current_user_session
|
20
|
+
return @current_user_session if defined?(@current_user_session)
|
21
|
+
@current_user_session = UserSession.find
|
22
|
+
end
|
23
|
+
|
24
|
+
def current_user
|
25
|
+
return @current_user if defined?(@current_user)
|
26
|
+
@current_user = current_user_session && current_user_session.user
|
27
|
+
end
|
28
|
+
|
29
|
+
def logged_in?
|
30
|
+
current_user
|
31
|
+
end
|
32
|
+
|
33
|
+
def require_user
|
34
|
+
return deny_access unless logged_in?
|
35
|
+
end
|
36
|
+
|
37
|
+
def require_no_user
|
38
|
+
return deny_access(:error,
|
39
|
+
'You must be logged out to access this page',
|
40
|
+
account_path) if current_user
|
41
|
+
end
|
42
|
+
|
43
|
+
def deny_access(status = :error, message = 'You must be logged in to access this page', redirect = nil)
|
44
|
+
store_location
|
45
|
+
set_flash_message!(status, message)
|
46
|
+
redirect_to(redirect || signin_path(:return_to => request.request_uri))
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
def store_location
|
52
|
+
if request.get?
|
53
|
+
session[:return_to] = request.request_uri
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def redirect_back_or(default)
|
58
|
+
redirect_to(return_to || default)
|
59
|
+
clear_return_to
|
60
|
+
end
|
61
|
+
|
62
|
+
def return_to
|
63
|
+
session[:return_to] || params[:return_to]
|
64
|
+
end
|
65
|
+
|
66
|
+
def clear_return_to
|
67
|
+
session[:return_to] = nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def redirect_to_root
|
71
|
+
redirect_to(root_path)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module TokakEngine
|
2
|
+
module User
|
3
|
+
unloadable
|
4
|
+
|
5
|
+
GENDERS = {
|
6
|
+
1 => :male,
|
7
|
+
2 => :female
|
8
|
+
}
|
9
|
+
|
10
|
+
def self.included(model)
|
11
|
+
model.send(:include, Associtations)
|
12
|
+
model.send(:include, InstanceMethods)
|
13
|
+
end
|
14
|
+
|
15
|
+
module Associtations
|
16
|
+
def self.included(model)
|
17
|
+
model.class_eval do
|
18
|
+
with_options :class_name => 'UserAvatar' do |ua|
|
19
|
+
ua.has_many :avatars,
|
20
|
+
:dependent => :destroy
|
21
|
+
ua.belongs_to :avatar
|
22
|
+
end
|
23
|
+
accepts_nested_attributes_for :avatars, :allow_destroy => true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module InstanceMethods
|
29
|
+
unloadable
|
30
|
+
|
31
|
+
def user_avatars(*args)
|
32
|
+
self.avatars(*args)
|
33
|
+
end
|
34
|
+
|
35
|
+
def name
|
36
|
+
[self.first_name, self.last_name].compact.join(' ')
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
self.nick_name || self.name || self.email
|
41
|
+
end
|
42
|
+
|
43
|
+
def gender
|
44
|
+
I18n.t(GENDERS[self.gender_id], :prefix => 'options.user.gender', :default => GENDERS[self.gender_id].to_s.humanize)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/tokak_engine.rb
ADDED
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Include hook code here
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{tokak_engine}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Alexander Semyonov"]
|
12
|
+
s.date = %q{2009-11-07}
|
13
|
+
s.email = %q{rotuka@tokak.ru}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"README"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
".gitignore",
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"app/helpers/tokak_helper.rb",
|
24
|
+
"app/models/identifier.rb",
|
25
|
+
"app/models/openid_identifier.rb",
|
26
|
+
"app/models/user.rb",
|
27
|
+
"app/models/user_avatar.rb",
|
28
|
+
"app/models/user_session.rb",
|
29
|
+
"app/views/user_avatars/_user_avatar.html.haml",
|
30
|
+
"app/views/user_avatars/index.html.haml",
|
31
|
+
"app/views/users/_user_bar.html.haml",
|
32
|
+
"db/migrate/20090926100710_create_users.rb",
|
33
|
+
"db/migrate/20091017071436_create_identifiers.rb",
|
34
|
+
"db/migrate/20091017071522_create_openid_identifiers.rb",
|
35
|
+
"db/migrate/20091017071730_add_open_id_authentication_tables.rb",
|
36
|
+
"db/migrate/20091017090208_do_not_require_password.rb",
|
37
|
+
"db/migrate/20091017102110_add_info_to_user.rb",
|
38
|
+
"db/migrate/20091019040959_create_user_avatars.rb",
|
39
|
+
"db/migrate/20091019041254_discover_avatars_from_openid.rb",
|
40
|
+
"db/migrate/20091019043008_discover_avatars_from_email.rb",
|
41
|
+
"db/migrate/20091019051628_add_current_avatar_to_user.rb",
|
42
|
+
"init.rb",
|
43
|
+
"install.rb",
|
44
|
+
"lib/canonical_host.rb",
|
45
|
+
"lib/tokak_engine.rb",
|
46
|
+
"lib/tokak_engine/application.rb",
|
47
|
+
"lib/tokak_engine/authentication.rb",
|
48
|
+
"lib/tokak_engine/user.rb",
|
49
|
+
"rails/init.rb",
|
50
|
+
"tasks/tokak_engine_tasks.rake",
|
51
|
+
"test/test_helper.rb",
|
52
|
+
"test/tokak_engine_test.rb",
|
53
|
+
"tokak_engine.gemspec",
|
54
|
+
"uninstall.rb"
|
55
|
+
]
|
56
|
+
s.homepage = %q{http://vnutri.tokak.ru/projects/tokak_engine}
|
57
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
58
|
+
s.require_paths = ["lib"]
|
59
|
+
s.rubygems_version = %q{1.3.5}
|
60
|
+
s.summary = %q{TokakEngine is an engine to use same users trough all applications}
|
61
|
+
s.test_files = [
|
62
|
+
"test/tokak_engine_test.rb",
|
63
|
+
"test/test_helper.rb"
|
64
|
+
]
|
65
|
+
|
66
|
+
if s.respond_to? :specification_version then
|
67
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
68
|
+
s.specification_version = 3
|
69
|
+
|
70
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
71
|
+
else
|
72
|
+
end
|
73
|
+
else
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tokak_engine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Semyonov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-07 00:00:00 +03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: rotuka@tokak.ru
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- .gitignore
|
26
|
+
- MIT-LICENSE
|
27
|
+
- README
|
28
|
+
- Rakefile
|
29
|
+
- VERSION
|
30
|
+
- app/helpers/tokak_helper.rb
|
31
|
+
- app/models/identifier.rb
|
32
|
+
- app/models/openid_identifier.rb
|
33
|
+
- app/models/user.rb
|
34
|
+
- app/models/user_avatar.rb
|
35
|
+
- app/models/user_session.rb
|
36
|
+
- app/views/user_avatars/_user_avatar.html.haml
|
37
|
+
- app/views/user_avatars/index.html.haml
|
38
|
+
- app/views/users/_user_bar.html.haml
|
39
|
+
- db/migrate/20090926100710_create_users.rb
|
40
|
+
- db/migrate/20091017071436_create_identifiers.rb
|
41
|
+
- db/migrate/20091017071522_create_openid_identifiers.rb
|
42
|
+
- db/migrate/20091017071730_add_open_id_authentication_tables.rb
|
43
|
+
- db/migrate/20091017090208_do_not_require_password.rb
|
44
|
+
- db/migrate/20091017102110_add_info_to_user.rb
|
45
|
+
- db/migrate/20091019040959_create_user_avatars.rb
|
46
|
+
- db/migrate/20091019041254_discover_avatars_from_openid.rb
|
47
|
+
- db/migrate/20091019043008_discover_avatars_from_email.rb
|
48
|
+
- db/migrate/20091019051628_add_current_avatar_to_user.rb
|
49
|
+
- init.rb
|
50
|
+
- install.rb
|
51
|
+
- lib/canonical_host.rb
|
52
|
+
- lib/tokak_engine.rb
|
53
|
+
- lib/tokak_engine/application.rb
|
54
|
+
- lib/tokak_engine/authentication.rb
|
55
|
+
- lib/tokak_engine/user.rb
|
56
|
+
- rails/init.rb
|
57
|
+
- tasks/tokak_engine_tasks.rake
|
58
|
+
- test/test_helper.rb
|
59
|
+
- test/tokak_engine_test.rb
|
60
|
+
- tokak_engine.gemspec
|
61
|
+
- uninstall.rb
|
62
|
+
has_rdoc: true
|
63
|
+
homepage: http://vnutri.tokak.ru/projects/tokak_engine
|
64
|
+
licenses: []
|
65
|
+
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options:
|
68
|
+
- --charset=UTF-8
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0"
|
76
|
+
version:
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
version:
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.3.5
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: TokakEngine is an engine to use same users trough all applications
|
90
|
+
test_files:
|
91
|
+
- test/tokak_engine_test.rb
|
92
|
+
- test/test_helper.rb
|