My favorites
▼
|
Sign in
substruct
Open-source Ruby on Rails E-Commerce
Project Home
Downloads
Wiki
Issues
Source
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
59
attachment: validate_users_password_v2.patch
(5.5 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
Index: /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/models/user.rb
===================================================================
--- /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/models/user.rb (revision 43)
+++ /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/models/user.rb (working copy)
@@ -10,21 +10,30 @@
validates_uniqueness_of :login, :on => :create
validates_length_of :login, :within => 3..40
validates_presence_of :login
-
- def validate
- if (5 > self.password.length && 40 < self.password.length)
- errors.add(:password, "Password must be between 5 and 40 characters.")
- end
-
- # check presence of password & matching if they both aren't blank
- if (self.password != self.password_confirmation) then
- errors.add(:password, "Password and Confirmation don't match.")
- end
- end
+
+ validates_presence_of :password, :if => Proc.new { |u| u.validate_password? }
+ validates_length_of :password, :within => 5..40, :if => Proc.new { |u| u.validate_password? }
+ validates_confirmation_of :password, :if => Proc.new { |u| u.validate_password? }
+
@@salt = '20ac4d290c2293702c64b3b287ae5ea79b26a5c1'
cattr_accessor :salt
- attr_accessor :password_confirmation
+ attr_accessor :password_confirmation, :validate_password
+
+ # Its a little hard to work with booleans, so as default we work with "0" or "1".
+ # By default a validate_password? consider "" as false. We don't want that an empty
+ # string turn off the validation. Here we define what we consider truth.
+ def validate_password?
+ self.validate_password == "1" ||
+ self.validate_password == "true" ||
+ self.validate_password == "y"
+ end
+
+ # We must define if we want that the password be validated, if not defined it
+ # defaults to yes.
+ def validate_password
+ @validate_password || "1"
+ end
# Authenticate a user.
#
Index: /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/controllers/admin/users_controller.rb
===================================================================
--- /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/controllers/admin/users_controller.rb (revision 43)
+++ /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/controllers/admin/users_controller.rb (working copy)
@@ -34,6 +34,12 @@
def edit
@title = "Editing User"
@user = User.find(params[:id])
+
+ # Here we set that by default we don't want to validate the password because we
+ # don't want to change it.
+ @user.validate_password = "0"
+ # If we are changing a password the checkbox filled in the form will redefine
+ # the validation.
@user.attributes = params["user"]
@roles = Role.find(:all, :order => 'name ASC')
Index: /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/views/admin/users/_form.rhtml
===================================================================
--- /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/views/admin/users/_form.rhtml (revision 43)
+++ /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/views/admin/users/_form.rhtml (working copy)
@@ -5,7 +5,16 @@
<%= text_field 'user', 'login', :class => 'textInput' %>
</p>
-<div id="change_password" style="<%= @action_name != 'new' ? 'display:none;' : '' %>">
+<% if @action_name != 'new' then %>
+ <p>
+ <label>
+ <%= check_box('user', 'validate_password', { :onchange => "$('want_to_change_password').toggle();" }, "1", "0") %>
+ I want to change the password
+ </label>
+ </p>
+<% end %>
+
+<div id="want_to_change_password" style="<%= (@action_name != 'new' && !@user.validate_password?) ? 'display:none;' : '' %>">
<p>
<label for="user_password">Password:</label>
<%= password_field 'user', 'password', :class => 'textInput' %>
@@ -16,10 +25,6 @@
<%= password_field 'user', 'password_confirmation', :class => 'textInput' %>
</p>
</div>
-<% if @action_name != 'new' then %>
- <a href="#" onclick="$('change_password').toggle();$('change_password_link').toggle();return false;" id="change_password_link">Change this user's password</a>
-<% end %>
-
<h2>User Roles</h2>
<!--
Index: /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/views/admin/users/edit.rhtml
===================================================================
--- /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/views/admin/users/edit.rhtml (revision 43)
+++ /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/views/admin/users/edit.rhtml (working copy)
@@ -6,7 +6,7 @@
<li><a href="/admin/users/list/">Back to User List</a></li>
</ul>
- <%= render_partial "form" %>
+ <%= render :partial => "form" %>
<!-- SAVE BUTTON -->
<div class="line" style="margin-top:20px;"> </div>
Index: /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/views/admin/users/new.rhtml
===================================================================
--- /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/views/admin/users/new.rhtml (revision 43)
+++ /home/edmundo/workspace_aptana/substruct_trunk/vendor/plugins/substruct/app/views/admin/users/new.rhtml (working copy)
@@ -5,7 +5,7 @@
</ul>
<%= form_tag :action=>"new" %>
- <%= render_partial "form" %>
+ <%= render :partial => "form" %>
<%= submit_tag 'Save New User', :class => 'button hundredthirty' %>
</form>
Powered by
Google Project Hosting