user_authentication 0.2.3 → 1.0.0
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.
- checksums.yaml +4 -4
- data/app/controllers/{users_controller.rb → accounts_controller.rb} +18 -18
- data/app/controllers/application_controller.rb +10 -10
- data/app/helpers/application_helper.rb +2 -2
- data/app/models/{user.rb → account.rb} +3 -3
- data/app/views/{users → accounts}/login.html.erb +0 -0
- data/app/views/{users → accounts}/signup.html.erb +0 -0
- data/config/routes.rb +6 -6
- data/db/migrate/{20121009010000_create_users.rb → 20121009010000_create_accounts.rb} +3 -3
- data/lib/tasks/user_authentication_tasks.rake +1 -1
- data/lib/user_authentication/version.rb +1 -1
- data/lib/user_authentication.rb +1 -1
- metadata +57 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da8dbd2230f17960165977d6aaca13e89a256600
|
4
|
+
data.tar.gz: f1d36aa9488718d692f7772beace69cb5317743d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01b9ca989f7e335fb1bd2a604cb2d35527d666bd1fcaeba0dae71dab09f591d070e79198b10a96da6ce932f654cd2b576f30d5b8c3f6b8b756adba07fa207428
|
7
|
+
data.tar.gz: 6cd2e8a009b7615ed7ef97be04c032ef5ebebcd5185f858c3f2e16ff0c2384e9c8e3ffd960efc769869a4399d41a3be380d576968a4164a78bb6a4174b8b60fb
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class AccountsController < ApplicationController
|
2
2
|
before_filter :authorize, only: [:set_password]
|
3
3
|
|
4
4
|
def login
|
@@ -8,10 +8,10 @@ class UsersController < ApplicationController
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def do_login
|
11
|
-
|
12
|
-
if
|
13
|
-
session[:
|
14
|
-
|
11
|
+
account = Account.find_by_email params[:email]
|
12
|
+
if account && account.authenticate(params[:password])
|
13
|
+
session[:account_id] = account.id
|
14
|
+
set_current_account
|
15
15
|
|
16
16
|
if respond_to? :on_login
|
17
17
|
on_login
|
@@ -24,8 +24,8 @@ class UsersController < ApplicationController
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def do_logout
|
27
|
-
session.delete :
|
28
|
-
|
27
|
+
session.delete :account_id
|
28
|
+
set_current_account
|
29
29
|
|
30
30
|
if respond_to? :on_logout
|
31
31
|
on_logout
|
@@ -35,16 +35,16 @@ class UsersController < ApplicationController
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def do_signup
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
(
|
42
|
-
|
38
|
+
account = Account.new
|
39
|
+
account.email = params[:email]
|
40
|
+
account.password = params[:password]
|
41
|
+
(account.attributes.keys - ['email', 'password_digest']).each do |attr|
|
42
|
+
account.send "#{attr}=", params[attr.to_sym]
|
43
43
|
end
|
44
44
|
|
45
|
-
if
|
46
|
-
session[:
|
47
|
-
|
45
|
+
if account.save
|
46
|
+
session[:account_id] = account.id
|
47
|
+
set_current_account
|
48
48
|
|
49
49
|
if respond_to? :on_signup
|
50
50
|
on_signup
|
@@ -57,8 +57,8 @@ class UsersController < ApplicationController
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def set_password
|
60
|
-
|
61
|
-
|
60
|
+
current_account.password = params[:password]
|
61
|
+
current_account.save
|
62
62
|
|
63
63
|
if respond_to? :on_set_password
|
64
64
|
on_set_password
|
@@ -68,5 +68,5 @@ class UsersController < ApplicationController
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
controller = File.join Rails.root, 'app/controllers/
|
71
|
+
controller = File.join Rails.root, 'app/controllers/accounts_controller.rb'
|
72
72
|
require controller if File.exists? controller
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class ApplicationController < ActionController::Base
|
2
|
-
before_filter :
|
2
|
+
before_filter :set_current_account
|
3
3
|
|
4
4
|
# private
|
5
5
|
|
@@ -7,11 +7,11 @@ class ApplicationController < ActionController::Base
|
|
7
7
|
def authorize(redirect=nil)
|
8
8
|
# Not using skip_before_filter, since main app could inadvertently override that
|
9
9
|
# by using a before_filter :authorize in its application_controller.
|
10
|
-
if params[:controller] == '
|
10
|
+
if params[:controller] == 'accounts' && ['do_login', 'login', 'do_logout', 'do_signup', 'signup'].include?(params[:action])
|
11
11
|
return true
|
12
12
|
end
|
13
13
|
|
14
|
-
if
|
14
|
+
if current_account.nil?
|
15
15
|
session[:redirect] = url_for params
|
16
16
|
redirect_to redirect || login_path, alert: 'Please log in to access this page.'
|
17
17
|
else
|
@@ -19,15 +19,15 @@ class ApplicationController < ActionController::Base
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
@
|
22
|
+
def current_account
|
23
|
+
@current_account
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
if session[:
|
28
|
-
@
|
29
|
-
elsif @
|
30
|
-
@
|
26
|
+
def set_current_account
|
27
|
+
if session[:account_id].nil?
|
28
|
+
@current_account = nil
|
29
|
+
elsif @current_account.nil? || @current_account.id != session[:account_id]
|
30
|
+
@current_account = Account.find session[:account_id]
|
31
31
|
end
|
32
32
|
|
33
33
|
true
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.expand_path('../../../lib/random', __FILE__)
|
2
2
|
|
3
|
-
class
|
3
|
+
class Account < ActiveRecord::Base
|
4
4
|
has_secure_password
|
5
5
|
|
6
|
-
before_validation { |
|
6
|
+
before_validation { |account| account.password = Random.password if account.password.nil? }
|
7
7
|
validates :email, presence: true, uniqueness: true, email: true
|
8
8
|
end
|
9
9
|
|
10
|
-
app_model = File.join Rails.root, 'app/models/
|
10
|
+
app_model = File.join Rails.root, 'app/models/account.rb'
|
11
11
|
require app_model if File.exists? app_model
|
File without changes
|
File without changes
|
data/config/routes.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
match "login" => "
|
3
|
-
match "login" => "
|
2
|
+
match "login" => "accounts#login", :via => :get
|
3
|
+
match "login" => "accounts#do_login", :via => :post
|
4
4
|
|
5
|
-
match "logout" => "
|
5
|
+
match "logout" => "accounts#do_logout", :via => :get
|
6
6
|
|
7
|
-
match "signup" => "
|
8
|
-
match "signup" => "
|
7
|
+
match "signup" => "accounts#signup", :via => :get
|
8
|
+
match "signup" => "accounts#do_signup", :via => :post
|
9
9
|
|
10
|
-
match "set_password" => "
|
10
|
+
match "set_password" => "accounts#set_password", :via => :post
|
11
11
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
class
|
1
|
+
class CreateAccounts < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
create_table :
|
3
|
+
create_table :accounts do |t|
|
4
4
|
t.string :email, :null => false
|
5
5
|
t.string :password_digest
|
6
6
|
|
7
7
|
t.timestamps
|
8
8
|
end
|
9
9
|
|
10
|
-
add_index :
|
10
|
+
add_index :accounts, [:email]
|
11
11
|
end
|
12
12
|
end
|
data/lib/user_authentication.rb
CHANGED
metadata
CHANGED
@@ -1,165 +1,165 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: user_authentication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sujoy Gupta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.1
|
19
|
+
version: '4.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.1
|
26
|
+
version: '4.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: bcrypt
|
28
|
+
name: bcrypt
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.1
|
33
|
+
version: '3.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.1
|
40
|
+
version: '3.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: capybara
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - '
|
45
|
+
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 2.4.4
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - '
|
52
|
+
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 2.4.4
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: factory_girl_rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '4.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '4.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec-rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '3.1'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '3.1'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: specstar-controllers
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: '0.1'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: '0.1'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: specstar-models
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
103
|
+
version: '0.2'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
110
|
+
version: '0.2'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name: specstar-
|
112
|
+
name: specstar-support-random
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - ~>
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.
|
117
|
+
version: '0.1'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - ~>
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.
|
124
|
+
version: '0.1'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: sqlite3
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
-
description: A rails engine for email and password based
|
139
|
+
description: A rails engine for email and password based account authentication.
|
140
140
|
email:
|
141
141
|
- sujoyg@gmail.com
|
142
142
|
executables: []
|
143
143
|
extensions: []
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
|
+
- MIT-LICENSE
|
147
|
+
- Rakefile
|
148
|
+
- app/controllers/accounts_controller.rb
|
146
149
|
- app/controllers/application_controller.rb
|
147
|
-
- app/controllers/users_controller.rb
|
148
150
|
- app/helpers/application_helper.rb
|
149
|
-
- app/models/
|
151
|
+
- app/models/account.rb
|
150
152
|
- app/validators/email_validator.rb
|
153
|
+
- app/views/accounts/login.html.erb
|
154
|
+
- app/views/accounts/signup.html.erb
|
151
155
|
- app/views/shared/_login.html.erb
|
152
156
|
- app/views/shared/_signup.html.erb
|
153
|
-
- app/views/users/login.html.erb
|
154
|
-
- app/views/users/signup.html.erb
|
155
157
|
- config/routes.rb
|
156
|
-
- db/migrate/
|
158
|
+
- db/migrate/20121009010000_create_accounts.rb
|
157
159
|
- lib/random.rb
|
158
160
|
- lib/tasks/user_authentication_tasks.rake
|
159
|
-
- lib/user_authentication/version.rb
|
160
161
|
- lib/user_authentication.rb
|
161
|
-
-
|
162
|
-
- Rakefile
|
162
|
+
- lib/user_authentication/version.rb
|
163
163
|
homepage: http://github.com/sujoyg/user_authentication
|
164
164
|
licenses:
|
165
165
|
- MIT
|
@@ -170,18 +170,18 @@ require_paths:
|
|
170
170
|
- lib
|
171
171
|
required_ruby_version: !ruby/object:Gem::Requirement
|
172
172
|
requirements:
|
173
|
-
- -
|
173
|
+
- - ">="
|
174
174
|
- !ruby/object:Gem::Version
|
175
175
|
version: '0'
|
176
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- -
|
178
|
+
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
181
|
requirements: []
|
182
182
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.
|
183
|
+
rubygems_version: 2.2.2
|
184
184
|
signing_key:
|
185
185
|
specification_version: 4
|
186
|
-
summary: A rails engine for email and password based
|
186
|
+
summary: A rails engine for email and password based account authentication.
|
187
187
|
test_files: []
|