muck-users 0.3.4 → 0.3.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/README.rdoc +13 -0
- data/VERSION +1 -1
- data/app/controllers/muck/users_controller.rb +13 -7
- data/config/muck_users_routes.rb +1 -1
- data/lib/active_record/acts/muck_user.rb +2 -0
- data/locales/en.yml +1 -0
- data/muck-users.gemspec +2 -2
- data/public/javascripts/muck-users.js +6 -0
- data/test/rails_root/app/controllers/application_controller.rb +7 -6
- data/test/rails_root/public/javascripts/jquery/jquery.autocomplete.js.readme +1 -1
- data/test/rails_root/public/javascripts/muck-users.js +6 -0
- data/test/rails_root/test/functional/users_controller_test.rb +66 -7
- data/test/rails_root/test/unit/user_test.rb +25 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -104,6 +104,19 @@ By default when a user logs out they are sent to the login page. You can add a
|
|
104
104
|
|
105
105
|
muck-users sends out emails that need to be able to generate links. Be sure to set a value for application_url in global_config.yml
|
106
106
|
|
107
|
+
=== Helpers
|
108
|
+
Muck users provides an autocomplete login search. To enable this functionality create a text box with the class 'login-search' and add
|
109
|
+
the following code to include the needed javascript and css:
|
110
|
+
|
111
|
+
<% content_for :head do -%>
|
112
|
+
<%= javascript_include_tag 'jquery/jquery.autocomplete.min' %>
|
113
|
+
<%= javascript_include_tag 'muck-users' %>
|
114
|
+
<%= stylesheet_link_tag 'jquery/jquery.autocomplete' %>
|
115
|
+
<% end -%>
|
116
|
+
|
117
|
+
If you override the users controller you will also need to include login_search in your routes:
|
118
|
+
map.resources :users, :collection => { :login_search => :get }
|
119
|
+
|
107
120
|
|
108
121
|
== General information
|
109
122
|
This engine implements authlogic. Some of the code contained was taken from here:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.6
|
@@ -77,6 +77,16 @@ class Muck::UsersController < ApplicationController
|
|
77
77
|
after_destroy_response
|
78
78
|
end
|
79
79
|
|
80
|
+
def login_search
|
81
|
+
if params[:q]
|
82
|
+
@users = User.by_login_alpha.by_login(params[:q], :limit => params[:limit] || 100)
|
83
|
+
end
|
84
|
+
respond_to do |format|
|
85
|
+
format.js { render :text => @users.collect{|user| user.login }.join("\n") }
|
86
|
+
format.json { render :json => @users.collect{|user| { :login => user.login } }.to_json }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
80
90
|
def is_login_available
|
81
91
|
result = t('muck.users.username_not_available')
|
82
92
|
if params[:user_login].nil?
|
@@ -85,13 +95,9 @@ class Muck::UsersController < ApplicationController
|
|
85
95
|
result = t('muck.users.login_empty')
|
86
96
|
elsif !User.login_exists?(params[:user_login])
|
87
97
|
@user = User.new(:login => params[:user_login])
|
88
|
-
|
89
|
-
|
90
|
-
@user.errors.
|
91
|
-
if !message.include? 'blank'
|
92
|
-
result += "<br />#{message}"
|
93
|
-
end
|
94
|
-
end
|
98
|
+
@user.valid? # we aren't interested in the output of this.
|
99
|
+
if @user.errors.on(:login)
|
100
|
+
result = "#{t('muck.users.invalid_username')} <br /> #{t('muck.users.username')} #{@user.errors.on(:login)}"
|
95
101
|
else
|
96
102
|
result = t('muck.users.username_available')
|
97
103
|
end
|
data/config/muck_users_routes.rb
CHANGED
@@ -3,7 +3,7 @@ ActionController::Routing::Routes.draw do |map|
|
|
3
3
|
# users
|
4
4
|
map.resources :users, :controller => 'muck/users',
|
5
5
|
:member => { :enable => :put, :welcome => :get, :activation_instructions => :get },
|
6
|
-
:collection => { :is_login_available => :post, :is_email_available => :post }
|
6
|
+
:collection => { :is_login_available => :post, :is_email_available => :post, :login_search => :get }
|
7
7
|
|
8
8
|
map.with_options(:controller => 'muck/users') do |users|
|
9
9
|
users.signup "/signup", :action => 'new', :requirements => {:protocol => muck_routes_protocol}
|
@@ -16,6 +16,8 @@ module ActiveRecord
|
|
16
16
|
named_scope :active, :conditions => "activated_at IS NOT NULL"
|
17
17
|
named_scope :inactive, :conditions => "activated_at IS NULL"
|
18
18
|
named_scope :recent, lambda { { :conditions => ['created_at > ?', 1.week.ago] } }
|
19
|
+
named_scope :by_login_alpha, :order => "login ASC"
|
20
|
+
named_scope :by_login, lambda { |*args| { :conditions => ["login LIKE ?", args.first + '%'] } }
|
19
21
|
|
20
22
|
belongs_to :access_code
|
21
23
|
accepts_nested_attributes_for :access_code
|
data/locales/en.yml
CHANGED
@@ -62,6 +62,7 @@ en:
|
|
62
62
|
access_code_delete_link: Delete Access Code
|
63
63
|
request_access_code: Request Access Code
|
64
64
|
first_name: First Name
|
65
|
+
username: Username
|
65
66
|
forgot_username: Forgot Username
|
66
67
|
updated_permissions: Updated Permissions
|
67
68
|
account_activated: Your account has been activated! You can now login.
|
data/muck-users.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{muck-users}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Justin Ball", "Joel Duffin"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-10}
|
13
13
|
s.description = %q{Easily add user signup, login and other features to your application}
|
14
14
|
s.email = %q{justin@tatemae.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -15,4 +15,10 @@ jQuery(document).ready(function() {
|
|
15
15
|
jQuery("#user_email").keydown(function() {
|
16
16
|
jQuery("#email-availibility").html('');
|
17
17
|
});
|
18
|
+
jQuery(".login-search").autocomplete('/users/login_search.js', {
|
19
|
+
minChars: 1,
|
20
|
+
delay: 200,
|
21
|
+
autoFill: true,
|
22
|
+
mustMatch: false
|
23
|
+
});
|
18
24
|
});
|
@@ -13,12 +13,13 @@ class ApplicationController < ActionController::Base
|
|
13
13
|
access_denied unless admin?
|
14
14
|
end
|
15
15
|
|
16
|
-
# only require ssl if
|
16
|
+
# only require ssl if it is turned on
|
17
17
|
def ssl_required?
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
if GlobalConfig.enable_ssl
|
19
|
+
(self.class.read_inheritable_attribute(:ssl_required_actions) || []).include?(action_name.to_sym)
|
20
|
+
else
|
21
|
+
false
|
22
|
+
end
|
22
23
|
end
|
23
|
-
|
24
|
+
|
24
25
|
end
|
@@ -15,4 +15,10 @@ jQuery(document).ready(function() {
|
|
15
15
|
jQuery("#user_email").keydown(function() {
|
16
16
|
jQuery("#email-availibility").html('');
|
17
17
|
});
|
18
|
+
jQuery(".login-search").autocomplete('/users/login_search.js', {
|
19
|
+
minChars: 1,
|
20
|
+
delay: 200,
|
21
|
+
autoFill: true,
|
22
|
+
mustMatch: false
|
23
|
+
});
|
18
24
|
});
|
@@ -232,32 +232,91 @@ class Muck::UsersControllerTest < ActionController::TestCase
|
|
232
232
|
should_redirect_to("login") { login_path }
|
233
233
|
end
|
234
234
|
end
|
235
|
-
|
236
|
-
context "
|
235
|
+
|
236
|
+
context "GET to login_search" do
|
237
|
+
setup do
|
238
|
+
@auser = Factory(:user, :login => 'aaaa')
|
239
|
+
@zuser = Factory(:user, :login => 'zzzz')
|
240
|
+
end
|
241
|
+
context "valid params" do
|
242
|
+
setup do
|
243
|
+
get :login_search, :q => 'a', :format => 'js'
|
244
|
+
end
|
245
|
+
should_respond_with :success
|
246
|
+
should "find a user" do
|
247
|
+
assert @response.body.include?('aaaa')
|
248
|
+
assert assigns(:users).include?(@auser)
|
249
|
+
end
|
250
|
+
should "not find a non-matching user" do
|
251
|
+
assert !@response.body.include?('zzzz')
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
context "POST to is_login_available" do
|
257
|
+
context "no params" do
|
258
|
+
setup do
|
259
|
+
post :is_login_available
|
260
|
+
end
|
261
|
+
should_respond_with :success
|
262
|
+
should_render_text ""
|
263
|
+
end
|
264
|
+
context "empty login" do
|
265
|
+
setup do
|
266
|
+
post :is_login_available, :user_login => ''
|
267
|
+
end
|
268
|
+
should_respond_with :success
|
269
|
+
should_render_text I18n.t('muck.users.login_empty')
|
270
|
+
end
|
271
|
+
context "valid login" do
|
272
|
+
setup do
|
273
|
+
post :is_login_available, :user_login => 'testdude1945'
|
274
|
+
end
|
275
|
+
should_respond_with :success
|
276
|
+
should_render_text I18n.t('muck.users.username_available')
|
277
|
+
end
|
278
|
+
context "invalid login" do
|
279
|
+
setup do
|
280
|
+
post :is_login_available, :user_login => 'testdude1945@example.comm'
|
281
|
+
end
|
282
|
+
should_respond_with :success
|
283
|
+
should_render_partial_text I18n.t('muck.users.invalid_username')
|
284
|
+
end
|
285
|
+
context "login not available" do
|
286
|
+
setup do
|
287
|
+
@user = Factory(:user)
|
288
|
+
post :is_login_available, :user_login => @user.login
|
289
|
+
end
|
290
|
+
should_respond_with :success
|
291
|
+
should_render_partial_text I18n.t('muck.users.username_not_available')
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
context "POST to is_email_available" do
|
237
296
|
context "no params" do
|
238
297
|
setup do
|
239
|
-
|
298
|
+
post :is_email_available
|
240
299
|
end
|
241
300
|
should_respond_with :success
|
242
301
|
should_render_text ""
|
243
302
|
end
|
244
303
|
context "empty email" do
|
245
304
|
setup do
|
246
|
-
|
305
|
+
post :is_email_available, :user_email => ''
|
247
306
|
end
|
248
307
|
should_respond_with :success
|
249
308
|
should_render_text I18n.t('muck.users.email_empty')
|
250
309
|
end
|
251
310
|
context "valid email" do
|
252
311
|
setup do
|
253
|
-
|
312
|
+
post :is_email_available, :user_email => 'testdude1945@example.com'
|
254
313
|
end
|
255
314
|
should_respond_with :success
|
256
315
|
should_render_text I18n.t('muck.users.email_available')
|
257
316
|
end
|
258
317
|
context "invalid email" do
|
259
318
|
setup do
|
260
|
-
|
319
|
+
post :is_email_available, :user_email => 'testdude1945@com'
|
261
320
|
end
|
262
321
|
should_respond_with :success
|
263
322
|
should_render_text I18n.t('muck.users.email_invalid')
|
@@ -265,7 +324,7 @@ class Muck::UsersControllerTest < ActionController::TestCase
|
|
265
324
|
context "email not available" do
|
266
325
|
setup do
|
267
326
|
@user = Factory(:user)
|
268
|
-
|
327
|
+
post :is_email_available, :user_email => @user.email
|
269
328
|
end
|
270
329
|
should_respond_with :success
|
271
330
|
should_render_partial_text I18n.t('muck.users.email_not_available', :reset_password_help => '')
|
@@ -75,6 +75,31 @@ class UserTest < ActiveSupport::TestCase
|
|
75
75
|
assert !User.inactive.include?(@active_user)
|
76
76
|
end
|
77
77
|
end
|
78
|
+
context "by_login_alpha" do
|
79
|
+
setup do
|
80
|
+
@user1 = Factory(:user, :login => 'atest')
|
81
|
+
@user2 = Factory(:user, :login => 'btest')
|
82
|
+
end
|
83
|
+
should "order by login" do
|
84
|
+
users = User.by_login_alpha
|
85
|
+
assert users.index(@user1) < users.index(@user2)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
context "by_login" do
|
89
|
+
setup do
|
90
|
+
@zuser = Factory(:user, :login => 'zasdf')
|
91
|
+
@xuser = Factory(:user, :login => 'xasdf')
|
92
|
+
end
|
93
|
+
should "find login by character match" do
|
94
|
+
assert User.by_login('z').include?(@zuser)
|
95
|
+
end
|
96
|
+
should "not find login that doesn't match" do
|
97
|
+
assert !User.by_login('x').include?(@zuser)
|
98
|
+
end
|
99
|
+
should "not find login that start with a matching character" do
|
100
|
+
assert User.by_login('asdf').blank?
|
101
|
+
end
|
102
|
+
end
|
78
103
|
end
|
79
104
|
end
|
80
105
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: muck-users
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Ball
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-02-
|
13
|
+
date: 2010-02-10 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|