appoxy_rails 0.0.6 → 0.0.7
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_rails.rb +4 -0
- data/lib/sessions/application_controller.rb +72 -55
- data/lib/sessions/sessions_controller.rb +16 -7
- data/lib/sessions/user.rb +15 -11
- data/lib/ui/application_helper.rb +34 -20
- data/lib/ui/time_zoner.rb +47 -0
- metadata +5 -3
data/lib/appoxy_rails.rb
ADDED
@@ -1,82 +1,99 @@
|
|
1
1
|
module Appoxy
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Sessions
|
4
|
+
module ApplicationController
|
5
5
|
|
6
|
+
def self.included(base)
|
7
|
+
# Initialize module.
|
8
|
+
helper_method :logged_in?
|
9
|
+
helper_method :current_user
|
10
|
+
helper_method :base_url
|
11
|
+
end
|
6
12
|
|
7
|
-
def logout_keeping_session!
|
8
|
-
@current_user = nil # not logged in, and don't do it for me
|
9
|
-
session[:user_id] = nil # keeps the session but kill our variable
|
10
|
-
end
|
11
13
|
|
14
|
+
protected
|
12
15
|
|
13
|
-
def logged_in?
|
14
|
-
#puts 'logged_in??'
|
15
|
-
#puts 'current_user=' + current_user.inspect
|
16
|
-
current_user
|
17
|
-
end
|
18
16
|
|
17
|
+
def logout_keeping_session!
|
18
|
+
@current_user = nil # not logged in, and don't do it for me
|
19
|
+
session[:user_id] = nil # keeps the session but kill our variable
|
20
|
+
end
|
19
21
|
|
20
|
-
def current_user=(new_user)
|
21
|
-
session[:user_id] = new_user ? new_user.id : nil
|
22
|
-
@current_user = new_user
|
23
|
-
end
|
24
22
|
|
23
|
+
def logged_in?
|
24
|
+
#puts 'logged_in??'
|
25
|
+
#puts 'current_user=' + current_user.inspect
|
26
|
+
current_user
|
27
|
+
end
|
25
28
|
|
26
|
-
def current_user
|
27
|
-
@current_user ||= (login_from_session)
|
28
|
-
@current_user
|
29
|
-
end
|
30
29
|
|
30
|
+
def current_user=(new_user)
|
31
|
+
set_current_user(new_user)
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
def set_current_user(user)
|
35
|
+
session[:user_id] = user.id if user
|
36
|
+
@current_user = user
|
37
|
+
end
|
36
38
|
|
37
|
-
#
|
38
|
-
# helper_method :logged_in?
|
39
|
-
# helper_method :current_user
|
40
39
|
|
40
|
+
def current_user
|
41
|
+
@current_user ||= (login_from_session)
|
42
|
+
@current_user
|
43
|
+
end
|
41
44
|
|
42
|
-
protected
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
password
|
49
|
-
end
|
46
|
+
def login_from_session
|
47
|
+
#puts 'Login from session=' + session[:user_id].inspect
|
48
|
+
::User.find_by_id(session[:user_id]) if session[:user_id]
|
49
|
+
end
|
50
50
|
|
51
|
-
def authenticate
|
52
|
-
if !logged_in?
|
53
|
-
flash[:warning] = "You need to login to access this page."
|
54
|
-
session[:return_to] = request.request_uri # return to after logging in
|
55
|
-
puts "ac=" + params[:ac].inspect
|
56
|
-
if params[:user_id] && params[:ac]
|
57
|
-
# todo: should we store ac in cookie? Make it easier to pass around
|
58
|
-
cookies[:ac] = params[:ac]
|
59
|
-
# then from an invite
|
60
|
-
user = ::User.find(params[:user_id])
|
61
|
-
if user && user.password.blank? # is this the best way to decide of user has not logged in? Could also check status.
|
62
|
-
redirect_to :controller=>"users", :action=>"new", :email=>user.email, :ac=>params[:ac]
|
63
|
-
return
|
64
|
-
end
|
65
|
-
end
|
66
|
-
redirect_to :controller=>"sessions", :action=>"new", :ac=>params[:ac]
|
67
|
-
end
|
68
|
-
|
69
|
-
after_authenticate
|
70
51
|
|
52
|
+
def base_url
|
53
|
+
r = "#{request.protocol}#{request.host}"
|
54
|
+
if request.port != 80
|
55
|
+
r << ":#{request.port}"
|
56
|
+
end
|
57
|
+
@base_url = r
|
58
|
+
r
|
59
|
+
end
|
60
|
+
|
61
|
+
def random_string(length=10)
|
62
|
+
chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'
|
63
|
+
password = ''
|
64
|
+
length.times { password << chars[rand(chars.size)] }
|
65
|
+
password
|
66
|
+
end
|
67
|
+
|
68
|
+
def authenticate
|
69
|
+
if !logged_in?
|
70
|
+
flash[:warning] = "You need to login to access this page."
|
71
|
+
session[:return_to] = request.request_uri # return to after logging in
|
72
|
+
puts "ac=" + params[:ac].inspect
|
73
|
+
if params[:user_id] && params[:ac]
|
74
|
+
# todo: should we store ac in cookie? Make it easier to pass around
|
75
|
+
cookies[:ac] = params[:ac]
|
76
|
+
# then from an invite
|
77
|
+
user = ::User.find(params[:user_id])
|
78
|
+
if user && user.password.blank? # is this the best way to decide of user has not logged in? Could also check status.
|
79
|
+
redirect_to :controller=>"users", :action=>"new", :email=>user.email, :ac=>params[:ac]
|
80
|
+
return
|
71
81
|
end
|
72
|
-
|
82
|
+
end
|
83
|
+
redirect_to :controller=>"sessions", :action=>"new", :ac=>params[:ac]
|
84
|
+
end
|
73
85
|
|
74
|
-
|
86
|
+
after_authenticate
|
75
87
|
|
88
|
+
end
|
76
89
|
|
90
|
+
def after_authenticate
|
91
|
+
|
92
|
+
end
|
77
93
|
|
78
|
-
end
|
79
94
|
|
80
95
|
end
|
81
96
|
|
97
|
+
end
|
98
|
+
|
82
99
|
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
module Appoxy
|
2
2
|
|
3
3
|
module Sessions
|
4
|
+
|
5
|
+
|
4
6
|
module SessionsController
|
5
7
|
|
8
|
+
# Todo: have a configuration block for this so user can set things like facebook_api_key and facebook_secret
|
9
|
+
|
6
10
|
def new
|
7
|
-
|
11
|
+
|
8
12
|
end
|
9
13
|
|
10
14
|
def create
|
@@ -12,8 +16,9 @@ module Appoxy
|
|
12
16
|
|
13
17
|
logout_keeping_session!
|
14
18
|
|
15
|
-
|
16
|
-
|
19
|
+
# logger.debug 'params=' + params.inspect
|
20
|
+
|
21
|
+
@email = params[:email]
|
17
22
|
@has_password = params[:has_password]
|
18
23
|
#puts 'has_pass? ' + @has_password.inspect
|
19
24
|
|
@@ -28,12 +33,12 @@ module Appoxy
|
|
28
33
|
# user = User.authenticate(@email, params[:password])
|
29
34
|
if user && user.authenticate(params[:password])
|
30
35
|
self.current_user = user
|
31
|
-
flash[:info]
|
32
|
-
orig_url
|
36
|
+
flash[:info] = "Logged in successfully."
|
37
|
+
orig_url = session[:return_to]
|
33
38
|
puts 'orig_url = ' + orig_url.to_s
|
34
39
|
session[:return_to] = nil
|
35
40
|
if !orig_url.nil?
|
36
|
-
redirect_to orig_url
|
41
|
+
redirect_to orig_url # if entered via a different url
|
37
42
|
else
|
38
43
|
after_create
|
39
44
|
end
|
@@ -51,9 +56,13 @@ module Appoxy
|
|
51
56
|
|
52
57
|
end
|
53
58
|
|
59
|
+
|
60
|
+
|
61
|
+
|
54
62
|
def before_create
|
55
63
|
|
56
64
|
end
|
65
|
+
|
57
66
|
def after_create
|
58
67
|
|
59
68
|
end
|
@@ -82,7 +91,7 @@ module Appoxy
|
|
82
91
|
return
|
83
92
|
end
|
84
93
|
|
85
|
-
@newpass
|
94
|
+
@newpass = random_string(8)
|
86
95
|
|
87
96
|
@user.password = @newpass
|
88
97
|
@user.save(:dirty=>true)
|
data/lib/sessions/user.rb
CHANGED
@@ -9,15 +9,19 @@ module Appoxy
|
|
9
9
|
end
|
10
10
|
|
11
11
|
|
12
|
-
has_strings
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
has_strings :email,
|
13
|
+
:open_id,
|
14
|
+
{:name => :password, :hashed=>true},
|
15
|
+
:first_name,
|
16
|
+
:last_name,
|
17
|
+
:remember_me,
|
18
|
+
:activation_code,
|
19
|
+
:status, # invited, active
|
20
|
+
:oauth_access_key,
|
21
|
+
:oauth_secret_key
|
19
22
|
|
20
|
-
has_dates :last_login
|
23
|
+
has_dates :last_login,
|
24
|
+
:remember_me_expires
|
21
25
|
|
22
26
|
|
23
27
|
def validate
|
@@ -25,6 +29,8 @@ module Appoxy
|
|
25
29
|
|
26
30
|
if status == "invited"
|
27
31
|
# doesn't need password
|
32
|
+
elsif open_id
|
33
|
+
# doesn't need password
|
28
34
|
else
|
29
35
|
errors.add("password", "must be at least 6 characters long.") if password.blank?
|
30
36
|
end
|
@@ -41,7 +47,6 @@ module Appoxy
|
|
41
47
|
end
|
42
48
|
|
43
49
|
|
44
|
-
|
45
50
|
def set_activation_code
|
46
51
|
self.activation_code=Digest::SHA1.hexdigest(email.to_s+Time.now.to_s)
|
47
52
|
end
|
@@ -49,11 +54,10 @@ module Appoxy
|
|
49
54
|
|
50
55
|
def activate!
|
51
56
|
self.activation_code=nil
|
52
|
-
self.status
|
57
|
+
self.status = "active"
|
53
58
|
end
|
54
59
|
|
55
60
|
|
56
|
-
|
57
61
|
def authenticate(password)
|
58
62
|
|
59
63
|
return nil if attributes["password"].blank? # if the user has no password (will this happen? maybe for invites...)
|
@@ -1,35 +1,49 @@
|
|
1
1
|
module Appoxy
|
2
2
|
|
3
|
-
|
3
|
+
module UI
|
4
4
|
|
5
|
-
|
5
|
+
module ApplicationHelper
|
6
6
|
|
7
|
-
|
7
|
+
def self.included(base)
|
8
8
|
# puts self.class.name + " included in " + base.class.name
|
9
|
-
|
9
|
+
end
|
10
10
|
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def current_url
|
13
|
+
request.url
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
else
|
24
|
-
s << content_tag(:div, msg, :class => type)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
s.html_safe
|
16
|
+
def flash_messages
|
17
|
+
s = ""
|
18
|
+
flash.each_pair do |type, msg|
|
19
|
+
if msg.is_a?(Array)
|
20
|
+
msg.each do |m|
|
21
|
+
s << content_tag(:div, m, :class => type)
|
28
22
|
end
|
29
|
-
|
23
|
+
else
|
24
|
+
s << content_tag(:div, msg, :class => type)
|
25
|
+
end
|
30
26
|
end
|
27
|
+
s.html_safe
|
28
|
+
end
|
29
|
+
|
30
|
+
def error_messages_for
|
31
|
+
s = ""
|
32
|
+
flash.each_pair do |type, msg|
|
33
|
+
if msg.is_a?(Array)
|
34
|
+
msg.each do |m|
|
35
|
+
s << content_tag(:div, m, :class => type)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
s << content_tag(:div, msg, :class => type)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
s.html_safe
|
42
|
+
end
|
31
43
|
|
32
44
|
end
|
33
45
|
|
46
|
+
end
|
47
|
+
|
34
48
|
end
|
35
49
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# adds a to_pst method to Time
|
2
|
+
module TimePluginizer # ActiveSupport::CoreExtensions::Time::Conversions
|
3
|
+
|
4
|
+
def self.included(base) #:nodoc:
|
5
|
+
base.class_eval do
|
6
|
+
#puts 'TP mixing'
|
7
|
+
# If we want to_s to ALWAYS be local, uncomment the below line
|
8
|
+
#alias_method :to_s, :to_local_s #
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_pst
|
13
|
+
return in_time_zone('Pacific Time (US & Canada)')
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_user_time(user = nil)
|
17
|
+
local = nil
|
18
|
+
if user && user.time_zone
|
19
|
+
local = in_time_zone(user.time_zone)
|
20
|
+
else
|
21
|
+
local = to_pst
|
22
|
+
end
|
23
|
+
local
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_local_s(format = :default, user = nil)
|
27
|
+
#puts 'calling to_local_s on ' + self.class.name
|
28
|
+
zone = to_user_time(user)
|
29
|
+
return zone.to_formatted_s(format)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
module StringTimezoner
|
35
|
+
def to_user_time(user)
|
36
|
+
tz = ActiveSupport::TimeZone.new(user.time_zone || 'Pacific Time (US & Canada)')
|
37
|
+
# puts 'tz=' + tz.inspect
|
38
|
+
t = tz.parse(self)
|
39
|
+
return t
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Time.send :include, TimePluginizer
|
44
|
+
DateTime.send :include, TimePluginizer
|
45
|
+
#Date.send :include, TimePluginizer
|
46
|
+
|
47
|
+
String.send :include, StringTimezoner
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 7
|
9
|
+
version: 0.0.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Travis Reeder
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-27 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/api/client_helper.rb
|
45
45
|
- lib/api/signatures.rb
|
46
46
|
- lib/appoxy_api.rb
|
47
|
+
- lib/appoxy_rails.rb
|
47
48
|
- lib/appoxy_sessions.rb
|
48
49
|
- lib/appoxy_ui.rb
|
49
50
|
- lib/sessions/application_controller.rb
|
@@ -52,6 +53,7 @@ files:
|
|
52
53
|
- lib/sessions/user.rb
|
53
54
|
- lib/sessions/users_controller.rb
|
54
55
|
- lib/ui/application_helper.rb
|
56
|
+
- lib/ui/time_zoner.rb
|
55
57
|
- README.markdown
|
56
58
|
has_rdoc: true
|
57
59
|
homepage: http://www.appoxy.com
|