appoxy_sessions 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/lib/appoxy_sessions.rb
CHANGED
@@ -2,4 +2,5 @@ require 'simple_record'
|
|
2
2
|
require File.join(File.dirname(__FILE__), "sessions", "user")
|
3
3
|
require File.join(File.dirname(__FILE__), "sessions", "application_controller")
|
4
4
|
require File.join(File.dirname(__FILE__), "sessions", "sessions_controller")
|
5
|
+
require File.join(File.dirname(__FILE__), "sessions", "users_controller")
|
5
6
|
|
@@ -47,6 +47,7 @@ module Appoxy
|
|
47
47
|
|
48
48
|
|
49
49
|
def reset_password
|
50
|
+
before_reset_password
|
50
51
|
|
51
52
|
unless verify_recaptcha
|
52
53
|
flash[:error] = "You are not human! Please try again."
|
@@ -61,31 +62,45 @@ module Appoxy
|
|
61
62
|
return
|
62
63
|
end
|
63
64
|
|
64
|
-
@user = User.find_by_email(@email)
|
65
|
+
@user = ::User.find_by_email(@email)
|
65
66
|
unless @user
|
66
67
|
flash[:error] = "Email not found."
|
67
68
|
render :action=>"forgot_password"
|
68
69
|
return
|
69
70
|
end
|
70
71
|
|
71
|
-
newpass = random_string(8)
|
72
|
+
@newpass = random_string(8)
|
72
73
|
|
73
|
-
@user.password = newpass
|
74
|
+
@user.password = @newpass
|
74
75
|
@user.save(:dirty=>true)
|
75
76
|
|
76
|
-
Mailer.deliver_reset_password(@user, newpass)
|
77
|
-
|
78
77
|
flash[:success] = "Password reset. You should receive an email shortly with a new password."
|
79
78
|
redirect_to :action=>"new"
|
80
79
|
|
80
|
+
after_reset_password
|
81
|
+
end
|
82
|
+
|
83
|
+
def before_reset_password
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
# This is a great spot to send an email with the new password (the only spot actually).
|
88
|
+
def after_reset_password
|
89
|
+
|
81
90
|
end
|
82
91
|
|
83
92
|
def destroy
|
84
93
|
logout
|
94
|
+
end
|
95
|
+
|
96
|
+
def logout
|
97
|
+
@current_user = nil
|
98
|
+
reset_session
|
85
99
|
flash[:info] = "You have been logged out."
|
86
100
|
redirect_to('/')
|
87
101
|
end
|
88
102
|
|
103
|
+
|
89
104
|
end
|
90
105
|
end
|
91
106
|
end
|
data/lib/sessions/user.rb
CHANGED
@@ -5,7 +5,7 @@ module Appoxy
|
|
5
5
|
class User < SimpleRecord::Base
|
6
6
|
|
7
7
|
def self.included(base)
|
8
|
-
puts self.class.name + " included in " + base.class.name
|
8
|
+
# puts self.class.name + " included in " + base.class.name
|
9
9
|
end
|
10
10
|
|
11
11
|
|
@@ -37,19 +37,29 @@ module Appoxy
|
|
37
37
|
|
38
38
|
|
39
39
|
def is_active?
|
40
|
-
|
40
|
+
status == "active"
|
41
41
|
end
|
42
42
|
|
43
43
|
|
44
|
+
|
45
|
+
def set_activation_code
|
46
|
+
self.activation_code=Digest::SHA1.hexdigest(email.to_s+Time.now.to_s)
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def activate!
|
51
|
+
self.activation_code=nil
|
52
|
+
self.status = "active"
|
53
|
+
self.save(:dirty=>true)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
|
44
58
|
def authenticate(password)
|
45
|
-
#RAILS_DEFAULT_LOGGER.info "-------authenticating password------"
|
46
59
|
|
47
|
-
|
48
|
-
# return nil unless u
|
49
|
-
return nil unless is_active?
|
50
|
-
return nil if attributes["password"].nil? # if the user has no password (will this happen? maybe for invites...)
|
60
|
+
return nil if attributes["password"].blank? # if the user has no password (will this happen? maybe for invites...)
|
51
61
|
|
52
|
-
# This is a normal unencrypted password
|
62
|
+
# This is a normal unencrypted password, temporary
|
53
63
|
if attributes["password"][0].length < 100
|
54
64
|
self.password = attributes["password"][0]
|
55
65
|
self.save
|
@@ -1,19 +1,115 @@
|
|
1
1
|
module Appoxy
|
2
2
|
|
3
3
|
module Sessions
|
4
|
-
module
|
4
|
+
module UsersController
|
5
5
|
|
6
6
|
|
7
7
|
def new
|
8
|
-
|
8
|
+
before_new
|
9
|
+
puts 'NEW YO'
|
9
10
|
@user = User.new
|
10
11
|
@user.email = params[:email] if params[:email]
|
11
12
|
@user.activation_code = params[:ac]
|
13
|
+
after_new
|
14
|
+
end
|
15
|
+
|
16
|
+
def before_new
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def after_new
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def create
|
25
|
+
|
26
|
+
before_create
|
27
|
+
|
28
|
+
@user = ::User.new(params[:user])
|
29
|
+
|
30
|
+
existing_user = ::User.find_by_email(@user.email)
|
31
|
+
|
32
|
+
if existing_user
|
33
|
+
if params[:activation_code].present?
|
34
|
+
# hasn't logged in yet, probably invited, need to check access key
|
35
|
+
if existing_user.activation_code == @user.activation_code
|
36
|
+
existing_user.activate!
|
37
|
+
existing_user.password = @user.password
|
38
|
+
@user = existing_user
|
39
|
+
end
|
40
|
+
else
|
41
|
+
flash[:error] = "The email you entered already exists in our system. You might want to try logging in if you already have an account."
|
42
|
+
render :action=>"new"
|
43
|
+
return
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
if @user.password != params[:password_confirmation]
|
49
|
+
flash[:error] = "Confirmation password does not match. Please try again."
|
50
|
+
render :action=>"new"
|
51
|
+
return
|
52
|
+
end
|
53
|
+
|
54
|
+
if params[:user][:password].length < 6
|
55
|
+
flash[:error] = "Password can not be less than 6 characters."
|
56
|
+
render :action=>"new"
|
57
|
+
return
|
58
|
+
end
|
59
|
+
|
60
|
+
@user.status = "active"
|
61
|
+
|
62
|
+
before_save_in_create
|
63
|
+
if @user.save
|
64
|
+
self.current_user = @user
|
65
|
+
flash[:success] = "Your account was created successfully."
|
66
|
+
after_save_in_create
|
67
|
+
else
|
68
|
+
render :action => "new"
|
69
|
+
end
|
70
|
+
after_create
|
12
71
|
|
13
72
|
end
|
14
73
|
|
74
|
+
def before_create
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
def before_save_in_create
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
def after_save_in_create
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
def after_create
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
# Usually a user gets here via an activation link in email.
|
92
|
+
def activate
|
93
|
+
logout_keeping_session!
|
94
|
+
# todo: find by email or user_id AND activation code
|
95
|
+
@user = ::User.find_by_activation_code(params[:activation_code]) unless params[:activation_code].blank?
|
96
|
+
case
|
97
|
+
when params[:activation_code].present? && @user && !@user.is_active?
|
98
|
+
@user.activate!
|
99
|
+
flash[:success] = "Account activated. please login."
|
100
|
+
redirect_to login_url
|
101
|
+
when params[:activation_code].blank?
|
102
|
+
flash[:error] = "The activation code was missing. Please follow the URL from your email."
|
103
|
+
redirect_to(root_url)
|
104
|
+
else
|
105
|
+
flash[:error] = "We couldn't find a user with that activation code -- check your email? Or maybe you've already activated -- try signing in."
|
106
|
+
redirect_to(root_url)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
15
110
|
end
|
16
111
|
|
112
|
+
|
17
113
|
end
|
18
114
|
|
19
115
|
|