userify 0.2.1 → 0.2.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/Rakefile
CHANGED
@@ -35,7 +35,7 @@ task :default => ['test:all', 'test:features']
|
|
35
35
|
|
36
36
|
gem_spec = Gem::Specification.new do |gem_spec|
|
37
37
|
gem_spec.name = "userify"
|
38
|
-
gem_spec.version = "0.2.
|
38
|
+
gem_spec.version = "0.2.2"
|
39
39
|
gem_spec.summary = "Super simple authentication system for Rails, using username, email and password."
|
40
40
|
gem_spec.email = "kenn.ejima <at> gmail.com"
|
41
41
|
gem_spec.homepage = "http://github.com/kenn/userify"
|
@@ -43,10 +43,10 @@ class Userify::UserController < ApplicationController
|
|
43
43
|
flash[:error] = "Bad email or password."
|
44
44
|
redirect_to :back
|
45
45
|
else
|
46
|
-
if @user.
|
46
|
+
if @user.is_email_confirmed?
|
47
47
|
if params[:signin] and params[:signin][:remember_me] == "1"
|
48
48
|
@user.remember_me!
|
49
|
-
cookies[:remember_token] = { :value
|
49
|
+
cookies[:remember_token] = { :value => @user.token, :expires => @user.token_expires_at }
|
50
50
|
end
|
51
51
|
sign_in(@user)
|
52
52
|
flash[:notice] = "Signed in successfully."
|
@@ -61,7 +61,7 @@ class Userify::UserController < ApplicationController
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def signout
|
64
|
-
current_user.
|
64
|
+
current_user.clear_token! if current_user
|
65
65
|
cookies.delete :remember_token
|
66
66
|
reset_session
|
67
67
|
flash[:notice] = "You have been signed out."
|
@@ -84,7 +84,7 @@ class Userify::UserController < ApplicationController
|
|
84
84
|
|
85
85
|
when :post
|
86
86
|
if user = ::User.find_by_email(params[:forgot][:email])
|
87
|
-
user.
|
87
|
+
user.set_token!(24.hours.from_now)
|
88
88
|
::UserifyMailer.deliver_reset_password user
|
89
89
|
flash[:notice] = "You will receive an email within the next few minutes. " <<
|
90
90
|
"It contains instructions for changing your password."
|
@@ -105,7 +105,7 @@ class Userify::UserController < ApplicationController
|
|
105
105
|
|
106
106
|
when :post
|
107
107
|
if @user.update_password(params[:user][:password])
|
108
|
-
@user.confirm_email! unless @user.
|
108
|
+
@user.confirm_email! unless @user.is_email_confirmed?
|
109
109
|
sign_in(@user)
|
110
110
|
flash[:notice] = "You have successfully reset your password."
|
111
111
|
redirect_to url_after_reset
|
@@ -152,7 +152,7 @@ protected
|
|
152
152
|
end
|
153
153
|
|
154
154
|
def forbid_confirmed_user
|
155
|
-
raise ActionController::Forbidden, "confirmed user" if @user and @user.
|
155
|
+
raise ActionController::Forbidden, "confirmed user" if @user and @user.is_email_confirmed?
|
156
156
|
end
|
157
157
|
|
158
158
|
def generate_error_messages_for(obj)
|
data/config/userify_routes.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
ActionController::Routing::Routes.draw do |map|
|
2
|
-
map.
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
map.with_options(:controller => 'userify/user') do |route|
|
3
|
+
route.signup 'signup', :action => 'signup'
|
4
|
+
route.signin 'signin', :action => 'signin'
|
5
|
+
route.signout 'signout', :action => 'signout'
|
6
|
+
route.activate 'user/activate/:token', :action => 'activate'
|
7
|
+
route.forgot 'user/forgot', :action => 'forgot'
|
8
|
+
route.reset 'user/reset/:token', :action => 'reset'
|
9
|
+
end
|
8
10
|
end
|
@@ -19,7 +19,7 @@ class UserifyCreateUsers < ActiveRecord::Migration
|
|
19
19
|
t.string :salt, :limit => 27, :null => false
|
20
20
|
t.string :token, :limit => 27
|
21
21
|
t.datetime :token_expires_at
|
22
|
-
t.boolean :
|
22
|
+
t.boolean :is_email_confirmed, :default => false, :null => false
|
23
23
|
t.timestamps
|
24
24
|
end
|
25
25
|
|
@@ -18,7 +18,7 @@ module Userify
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def signed_in?
|
21
|
-
!
|
21
|
+
!current_user.nil?
|
22
22
|
end
|
23
23
|
|
24
24
|
protected
|
@@ -30,7 +30,7 @@ module Userify
|
|
30
30
|
def user_from_session
|
31
31
|
if session[:user_id]
|
32
32
|
return nil unless user = ::User.find_by_id(session[:user_id])
|
33
|
-
return user if user.
|
33
|
+
return user if user.is_email_confirmed?
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
data/lib/userify/user.rb
CHANGED
@@ -13,8 +13,6 @@ module Userify
|
|
13
13
|
attr_accessible :username, :email, :password, :fullname
|
14
14
|
attr_accessor :password
|
15
15
|
|
16
|
-
before_validation :normalize_email
|
17
|
-
|
18
16
|
validates_presence_of :username
|
19
17
|
validates_length_of :username, :maximum => columns_hash['username'].limit
|
20
18
|
validates_uniqueness_of :username
|
@@ -25,7 +23,12 @@ module Userify
|
|
25
23
|
validates_presence_of :password, :if => :password_required?
|
26
24
|
validates_length_of :fullname, :maximum => columns_hash['fullname'].limit, :allow_nil => true
|
27
25
|
|
28
|
-
|
26
|
+
before_validation {|record| record.email.downcase! unless self.email.nil? }
|
27
|
+
before_save {|record| record.encrypted_password = encrypt(password) unless password.blank? }
|
28
|
+
before_create {|record|
|
29
|
+
record.salt = UID.new(27).to_s
|
30
|
+
record.set_token 24.hours.from_now
|
31
|
+
}
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
@@ -43,27 +46,18 @@ module Userify
|
|
43
46
|
end
|
44
47
|
|
45
48
|
def remember?
|
46
|
-
token_expires_at and Time.now
|
49
|
+
is_email_confirmed? and token_expires_at and Time.now < token_expires_at
|
47
50
|
end
|
48
51
|
|
49
52
|
def remember_me!(duration=183)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
def forget_me!
|
54
|
-
clear_token
|
55
|
-
save(false)
|
53
|
+
set_token duration.days.from_now unless remember?
|
54
|
+
save
|
56
55
|
end
|
57
56
|
|
58
57
|
def confirm_email!
|
59
|
-
self.
|
58
|
+
self.is_email_confirmed = true
|
60
59
|
clear_token
|
61
|
-
save
|
62
|
-
end
|
63
|
-
|
64
|
-
def forgot_password!
|
65
|
-
generate_token 24.hours.from_now.utc
|
66
|
-
save(false)
|
60
|
+
save
|
67
61
|
end
|
68
62
|
|
69
63
|
def update_password(new_password)
|
@@ -72,29 +66,21 @@ module Userify
|
|
72
66
|
save
|
73
67
|
end
|
74
68
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
UID.new(n).to_s
|
79
|
-
end
|
80
|
-
|
81
|
-
def normalize_email
|
82
|
-
self.email.downcase! unless self.email.nil?
|
83
|
-
return true
|
69
|
+
def set_token!(expires_at=nil)
|
70
|
+
set_token expires_at
|
71
|
+
save
|
84
72
|
end
|
85
73
|
|
86
|
-
def
|
87
|
-
|
74
|
+
def clear_token!
|
75
|
+
clear_token
|
76
|
+
save
|
88
77
|
end
|
89
78
|
|
90
|
-
|
91
|
-
return if password.blank?
|
92
|
-
self.encrypted_password = encrypt(password)
|
93
|
-
end
|
79
|
+
protected
|
94
80
|
|
95
|
-
def
|
96
|
-
self.token =
|
97
|
-
self.token_expires_at =
|
81
|
+
def set_token(expires_at=nil)
|
82
|
+
self.token = UID.new(27).to_s
|
83
|
+
self.token_expires_at = expires_at
|
98
84
|
end
|
99
85
|
|
100
86
|
def clear_token
|
@@ -102,19 +88,9 @@ module Userify
|
|
102
88
|
self.token_expires_at = nil
|
103
89
|
end
|
104
90
|
|
105
|
-
def initialize_token
|
106
|
-
generate_token 24.hours.from_now.utc if new_record?
|
107
|
-
end
|
108
|
-
|
109
91
|
def password_required?
|
110
92
|
encrypted_password.blank? or !password.blank?
|
111
93
|
end
|
112
|
-
|
113
|
-
def remember_me_until!(time)
|
114
|
-
self.token = generate_random_base62
|
115
|
-
self.token_expires_at = time
|
116
|
-
save(false)
|
117
|
-
end
|
118
94
|
end
|
119
95
|
|
120
96
|
module ClassMethods
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: userify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenn Ejima
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-04 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|