Description:
added random user passwords, better user creation by list.
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@429 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r200:3383214a2837 - - 5 files changed: 104 inserted, 14 deleted
@@ -0,0 +1,39 | |||||
|
|
1 | + %h1 Random user passwords | ||
|
|
2 | + | ||
|
|
3 | + -if @changed | ||
|
|
4 | + %p | ||
|
|
5 | + %b Done! | ||
|
|
6 | + Here's a new password list. | ||
|
|
7 | + Go back to | ||
|
|
8 | + = (link_to '[user list]', :action => 'index') + '.' | ||
|
|
9 | + %br/ | ||
|
|
10 | + %table | ||
|
|
11 | + %tr | ||
|
|
12 | + %th Login | ||
|
|
13 | + %th Fullname | ||
|
|
14 | + %th Password | ||
|
|
15 | + -for u in @non_admin_users | ||
|
|
16 | + %tr | ||
|
|
17 | + %td= u.login | ||
|
|
18 | + %td= u.full_name | ||
|
|
19 | + %td | ||
|
|
20 | + %tt= u.password | ||
|
|
21 | + | ||
|
|
22 | + -else | ||
|
|
23 | + -if @prefix!='' | ||
|
|
24 | + Current prefix: | ||
|
|
25 | + = @prefix | ||
|
|
26 | + -form_tag((url_for :action => 'random_all_passwords'), :method => 'get') do | ||
|
|
27 | + Change prefix | ||
|
|
28 | + =text_field_tag 'prefix' | ||
|
|
29 | + =submit_tag 'Change' | ||
|
|
30 | + | ||
|
|
31 | + This will change passwords of the following users. | ||
|
|
32 | + %ul | ||
|
|
33 | + -for u in @non_admin_users | ||
|
|
34 | + %li= u.login | ||
|
|
35 | + | ||
|
|
36 | + -form_tag((url_for :action => 'random_all_passwords'), :method => 'post') do | ||
|
|
37 | + =hidden_field_tag 'prefix', @prefix | ||
|
|
38 | + Are you sure? | ||
|
|
39 | + =submit_tag 'Go ahead' |
@@ -1,175 +1,224 | |||||
|
1 | class UserAdminController < ApplicationController |
|
1 | class UserAdminController < ApplicationController |
|
2 |
|
2 | ||
|
3 | before_filter :admin_authorization |
|
3 | before_filter :admin_authorization |
|
4 |
|
4 | ||
|
5 | def index |
|
5 | def index |
|
6 | list |
|
6 | list |
|
7 | render :action => 'list' |
|
7 | render :action => 'list' |
|
8 | end |
|
8 | end |
|
9 |
|
9 | ||
|
10 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
10 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
11 |
- verify :method => :post, :only => [ :destroy, |
|
11 | + verify :method => :post, :only => [ :destroy, |
|
|
12 | + :create, :create_from_list, | ||
|
|
13 | + :update ], | ||
|
12 | :redirect_to => { :action => :list } |
|
14 | :redirect_to => { :action => :list } |
|
13 |
|
15 | ||
|
14 | def list |
|
16 | def list |
|
15 | @users = User.find(:all) |
|
17 | @users = User.find(:all) |
|
16 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
18 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
17 | end |
|
19 | end |
|
18 |
|
20 | ||
|
19 | def active |
|
21 | def active |
|
20 | sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago]) |
|
22 | sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago]) |
|
21 | @users = [] |
|
23 | @users = [] |
|
22 | sessions.each do |session| |
|
24 | sessions.each do |session| |
|
23 | if session.data[:user_id] |
|
25 | if session.data[:user_id] |
|
24 | @users << User.find(session.data[:user_id]) |
|
26 | @users << User.find(session.data[:user_id]) |
|
25 | end |
|
27 | end |
|
26 | end |
|
28 | end |
|
27 | end |
|
29 | end |
|
28 |
|
30 | ||
|
29 | def show |
|
31 | def show |
|
30 | @user = User.find(params[:id]) |
|
32 | @user = User.find(params[:id]) |
|
31 | end |
|
33 | end |
|
32 |
|
34 | ||
|
33 | def new |
|
35 | def new |
|
34 | @user = User.new |
|
36 | @user = User.new |
|
35 | end |
|
37 | end |
|
36 |
|
38 | ||
|
37 | def create |
|
39 | def create |
|
38 | @user = User.new(params[:user]) |
|
40 | @user = User.new(params[:user]) |
|
39 | @user.activated = true |
|
41 | @user.activated = true |
|
40 | if @user.save |
|
42 | if @user.save |
|
41 | flash[:notice] = 'User was successfully created.' |
|
43 | flash[:notice] = 'User was successfully created.' |
|
42 | redirect_to :action => 'list' |
|
44 | redirect_to :action => 'list' |
|
43 | else |
|
45 | else |
|
44 | render :action => 'new' |
|
46 | render :action => 'new' |
|
45 | end |
|
47 | end |
|
46 | end |
|
48 | end |
|
47 |
|
49 | ||
|
48 | def create_from_list |
|
50 | def create_from_list |
|
49 | lines = params[:user_list] |
|
51 | lines = params[:user_list] |
|
|
52 | + | ||
|
|
53 | + note = [] | ||
|
|
54 | + | ||
|
50 | lines.split("\n").each do |line| |
|
55 | lines.split("\n").each do |line| |
|
51 | items = line.chomp.split(',') |
|
56 | items = line.chomp.split(',') |
|
52 |
- if items.length |
|
57 | + if items.length>=2 |
|
53 | - user = User.new |
|
58 | + login = items[0] |
|
54 |
- |
|
59 | + full_name = items[1] |
|
55 | - user.full_name = items[1] |
|
60 | + |
|
56 | - user.alias = items[2] |
|
61 | + added_random_password = false |
|
57 | - user.password = items[3] |
|
62 | + if items.length>=3 |
|
58 |
- |
|
63 | + password = items[2] |
|
|
64 | + user_alias = (items.length>=4) ? items[3] : login | ||
|
|
65 | + else | ||
|
|
66 | + password = random_password | ||
|
|
67 | + user_alias = (items.length>=4) ? items[3] : login | ||
|
|
68 | + added_random_password = true | ||
|
|
69 | + end | ||
|
|
70 | + | ||
|
|
71 | + user = User.new({:login => login, | ||
|
|
72 | + :full_name => full_name, | ||
|
|
73 | + :password => password, | ||
|
|
74 | + :password_confirmation => password, | ||
|
|
75 | + :alias => user_alias}) | ||
|
59 | user.activated = true |
|
76 | user.activated = true |
|
60 | user.save |
|
77 | user.save |
|
|
78 | + | ||
|
|
79 | + if added_random_password | ||
|
|
80 | + note << "'#{login}' (+)" | ||
|
|
81 | + else | ||
|
|
82 | + note << login | ||
|
61 | end |
|
83 | end |
|
62 | end |
|
84 | end |
|
|
85 | + end | ||
|
|
86 | + flash[:notice] = 'User(s) ' + note.join(', ') + | ||
|
|
87 | + ' were successfully created. ' + | ||
|
|
88 | + '( (+) - created with random passwords.)' | ||
|
63 | redirect_to :action => 'list' |
|
89 | redirect_to :action => 'list' |
|
64 | end |
|
90 | end |
|
65 |
|
91 | ||
|
66 | def edit |
|
92 | def edit |
|
67 | @user = User.find(params[:id]) |
|
93 | @user = User.find(params[:id]) |
|
68 | end |
|
94 | end |
|
69 |
|
95 | ||
|
70 | def update |
|
96 | def update |
|
71 | @user = User.find(params[:id]) |
|
97 | @user = User.find(params[:id]) |
|
72 | if @user.update_attributes(params[:user]) |
|
98 | if @user.update_attributes(params[:user]) |
|
73 | flash[:notice] = 'User was successfully updated.' |
|
99 | flash[:notice] = 'User was successfully updated.' |
|
74 | redirect_to :action => 'show', :id => @user |
|
100 | redirect_to :action => 'show', :id => @user |
|
75 | else |
|
101 | else |
|
76 | render :action => 'edit' |
|
102 | render :action => 'edit' |
|
77 | end |
|
103 | end |
|
78 | end |
|
104 | end |
|
79 |
|
105 | ||
|
80 | def destroy |
|
106 | def destroy |
|
81 | User.find(params[:id]).destroy |
|
107 | User.find(params[:id]).destroy |
|
82 | redirect_to :action => 'list' |
|
108 | redirect_to :action => 'list' |
|
83 | end |
|
109 | end |
|
84 |
|
110 | ||
|
85 | def user_stat |
|
111 | def user_stat |
|
86 | @problems = Problem.find_available_problems |
|
112 | @problems = Problem.find_available_problems |
|
87 | @users = User.find(:all) |
|
113 | @users = User.find(:all) |
|
88 | @scorearray = Array.new |
|
114 | @scorearray = Array.new |
|
89 | @users.each do |u| |
|
115 | @users.each do |u| |
|
90 | ustat = Array.new |
|
116 | ustat = Array.new |
|
91 | ustat[0] = u |
|
117 | ustat[0] = u |
|
92 | @problems.each do |p| |
|
118 | @problems.each do |p| |
|
93 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
119 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
94 | if (sub!=nil) and (sub.points!=nil) |
|
120 | if (sub!=nil) and (sub.points!=nil) |
|
95 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
121 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
96 | else |
|
122 | else |
|
97 | ustat << [0,false] |
|
123 | ustat << [0,false] |
|
98 | end |
|
124 | end |
|
99 | end |
|
125 | end |
|
100 | @scorearray << ustat |
|
126 | @scorearray << ustat |
|
101 | end |
|
127 | end |
|
102 | end |
|
128 | end |
|
103 |
|
129 | ||
|
104 | def import |
|
130 | def import |
|
105 | if params[:file]=='' |
|
131 | if params[:file]=='' |
|
106 | flash[:notice] = 'Error importing no file' |
|
132 | flash[:notice] = 'Error importing no file' |
|
107 | redirect_to :action => 'list' and return |
|
133 | redirect_to :action => 'list' and return |
|
108 | end |
|
134 | end |
|
109 | import_from_file(params[:file]) |
|
135 | import_from_file(params[:file]) |
|
110 | end |
|
136 | end |
|
111 |
|
137 | ||
|
|
138 | + def random_all_passwords | ||
|
|
139 | + users = User.find(:all) | ||
|
|
140 | + @prefix = params[:prefix] || '' | ||
|
|
141 | + @non_admin_users = User.find_non_admin_with_prefix(@prefix) | ||
|
|
142 | + @changed = false | ||
|
|
143 | + if request.request_method == :post | ||
|
|
144 | + @non_admin_users.each do |user| | ||
|
|
145 | + password = random_password | ||
|
|
146 | + user.password = password | ||
|
|
147 | + user.password_confirmation = password | ||
|
|
148 | + user.save | ||
|
|
149 | + end | ||
|
|
150 | + @changed = true | ||
|
|
151 | + end | ||
|
|
152 | + end | ||
|
|
153 | + | ||
|
112 | protected |
|
154 | protected |
|
113 |
|
155 | ||
|
|
156 | + def random_password(length=5) | ||
|
|
157 | + chars = 'abcdefghijkmnopqrstuvwxyz23456789' | ||
|
|
158 | + newpass = "" | ||
|
|
159 | + length.times { newpass << chars[rand(chars.size-1)] } | ||
|
|
160 | + return newpass | ||
|
|
161 | + end | ||
|
|
162 | + | ||
|
114 | def import_from_file(f) |
|
163 | def import_from_file(f) |
|
115 | data_hash = YAML.load(f) |
|
164 | data_hash = YAML.load(f) |
|
116 | @import_log = "" |
|
165 | @import_log = "" |
|
117 |
|
166 | ||
|
118 | country_data = data_hash[:countries] |
|
167 | country_data = data_hash[:countries] |
|
119 | site_data = data_hash[:sites] |
|
168 | site_data = data_hash[:sites] |
|
120 | user_data = data_hash[:users] |
|
169 | user_data = data_hash[:users] |
|
121 |
|
170 | ||
|
122 | # import country |
|
171 | # import country |
|
123 | countries = {} |
|
172 | countries = {} |
|
124 | country_data.each_pair do |id,country| |
|
173 | country_data.each_pair do |id,country| |
|
125 | c = Country.find_by_name(country[:name]) |
|
174 | c = Country.find_by_name(country[:name]) |
|
126 | if c!=nil |
|
175 | if c!=nil |
|
127 | countries[id] = c |
|
176 | countries[id] = c |
|
128 | @import_log << "Found #{country[:name]}\n" |
|
177 | @import_log << "Found #{country[:name]}\n" |
|
129 | else |
|
178 | else |
|
130 | countries[id] = Country.new(:name => country[:name]) |
|
179 | countries[id] = Country.new(:name => country[:name]) |
|
131 | countries[id].save |
|
180 | countries[id].save |
|
132 | @import_log << "Created #{country[:name]}\n" |
|
181 | @import_log << "Created #{country[:name]}\n" |
|
133 | end |
|
182 | end |
|
134 | end |
|
183 | end |
|
135 |
|
184 | ||
|
136 | # import sites |
|
185 | # import sites |
|
137 | sites = {} |
|
186 | sites = {} |
|
138 | site_data.each_pair do |id,site| |
|
187 | site_data.each_pair do |id,site| |
|
139 | s = Site.find_by_name(site[:name]) |
|
188 | s = Site.find_by_name(site[:name]) |
|
140 | if s!=nil |
|
189 | if s!=nil |
|
141 | @import_log << "Found #{site[:name]}\n" |
|
190 | @import_log << "Found #{site[:name]}\n" |
|
142 | else |
|
191 | else |
|
143 | s = Site.new(:name => site[:name]) |
|
192 | s = Site.new(:name => site[:name]) |
|
144 | @import_log << "Created #{site[:name]}\n" |
|
193 | @import_log << "Created #{site[:name]}\n" |
|
145 | end |
|
194 | end |
|
146 | s.password = site[:password] |
|
195 | s.password = site[:password] |
|
147 | s.country = countries[site[:country_id]] |
|
196 | s.country = countries[site[:country_id]] |
|
148 | s.save |
|
197 | s.save |
|
149 | sites[id] = s |
|
198 | sites[id] = s |
|
150 | end |
|
199 | end |
|
151 |
|
200 | ||
|
152 | # import users |
|
201 | # import users |
|
153 | user_data.each_pair do |id,user| |
|
202 | user_data.each_pair do |id,user| |
|
154 | u = User.find_by_login(user[:login]) |
|
203 | u = User.find_by_login(user[:login]) |
|
155 | if u!=nil |
|
204 | if u!=nil |
|
156 | @import_log << "Found #{user[:login]}\n" |
|
205 | @import_log << "Found #{user[:login]}\n" |
|
157 | else |
|
206 | else |
|
158 | u = User.new(:login => user[:login]) |
|
207 | u = User.new(:login => user[:login]) |
|
159 | @import_log << "Created #{user[:login]}\n" |
|
208 | @import_log << "Created #{user[:login]}\n" |
|
160 | end |
|
209 | end |
|
161 | u.full_name = user[:name] |
|
210 | u.full_name = user[:name] |
|
162 | u.password = user[:password] |
|
211 | u.password = user[:password] |
|
163 | u.country = countries[user[:country_id]] |
|
212 | u.country = countries[user[:country_id]] |
|
164 | u.site = sites[user[:site_id]] |
|
213 | u.site = sites[user[:site_id]] |
|
165 | u.activated = true |
|
214 | u.activated = true |
|
166 | u.email = "empty-#{u.login}@none.com" |
|
215 | u.email = "empty-#{u.login}@none.com" |
|
167 | if not u.save |
|
216 | if not u.save |
|
168 | @import_log << "Errors\n" |
|
217 | @import_log << "Errors\n" |
|
169 | u.errors.each { |attr,msg| @import_log << "#{attr} - #{msg}\n" } |
|
218 | u.errors.each { |attr,msg| @import_log << "#{attr} - #{msg}\n" } |
|
170 | end |
|
219 | end |
|
171 | end |
|
220 | end |
|
172 |
|
221 | ||
|
173 | end |
|
222 | end |
|
174 |
|
223 | ||
|
175 | end |
|
224 | end |
@@ -20,150 +20,155 | |||||
|
20 | belongs_to :country |
|
20 | belongs_to :country |
|
21 |
|
21 | ||
|
22 | named_scope :activated_users, :conditions => {:activated => true} |
|
22 | named_scope :activated_users, :conditions => {:activated => true} |
|
23 |
|
23 | ||
|
24 | validates_presence_of :login |
|
24 | validates_presence_of :login |
|
25 | validates_uniqueness_of :login |
|
25 | validates_uniqueness_of :login |
|
26 | validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/ |
|
26 | validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/ |
|
27 | validates_length_of :login, :within => 3..30 |
|
27 | validates_length_of :login, :within => 3..30 |
|
28 |
|
28 | ||
|
29 | validates_presence_of :full_name |
|
29 | validates_presence_of :full_name |
|
30 | validates_length_of :full_name, :minimum => 1 |
|
30 | validates_length_of :full_name, :minimum => 1 |
|
31 |
|
31 | ||
|
32 | validates_presence_of :password, :if => :password_required? |
|
32 | validates_presence_of :password, :if => :password_required? |
|
33 | validates_length_of :password, :within => 4..20, :if => :password_required? |
|
33 | validates_length_of :password, :within => 4..20, :if => :password_required? |
|
34 | validates_confirmation_of :password, :if => :password_required? |
|
34 | validates_confirmation_of :password, :if => :password_required? |
|
35 |
|
35 | ||
|
36 | validates_format_of :email, |
|
36 | validates_format_of :email, |
|
37 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
37 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
38 | :if => :email_validation? |
|
38 | :if => :email_validation? |
|
39 | validate :uniqueness_of_email_from_activated_users, |
|
39 | validate :uniqueness_of_email_from_activated_users, |
|
40 | :if => :email_validation? |
|
40 | :if => :email_validation? |
|
41 | validate :enough_time_interval_between_same_email_registrations, |
|
41 | validate :enough_time_interval_between_same_email_registrations, |
|
42 | :if => :email_validation? |
|
42 | :if => :email_validation? |
|
43 |
|
43 | ||
|
44 | # these are for ytopc |
|
44 | # these are for ytopc |
|
45 | # disable for now |
|
45 | # disable for now |
|
46 | #validates_presence_of :province |
|
46 | #validates_presence_of :province |
|
47 |
|
47 | ||
|
48 | attr_accessor :password |
|
48 | attr_accessor :password |
|
49 |
|
49 | ||
|
50 | before_save :encrypt_new_password |
|
50 | before_save :encrypt_new_password |
|
51 | before_save :assign_default_site |
|
51 | before_save :assign_default_site |
|
52 |
|
52 | ||
|
53 | def self.authenticate(login, password) |
|
53 | def self.authenticate(login, password) |
|
54 | user = find_by_login(login) |
|
54 | user = find_by_login(login) |
|
55 | return user if user && user.authenticated?(password) |
|
55 | return user if user && user.authenticated?(password) |
|
56 | end |
|
56 | end |
|
57 |
|
57 | ||
|
58 | def authenticated?(password) |
|
58 | def authenticated?(password) |
|
59 | if self.activated |
|
59 | if self.activated |
|
60 | hashed_password == User.encrypt(password,self.salt) |
|
60 | hashed_password == User.encrypt(password,self.salt) |
|
61 | else |
|
61 | else |
|
62 | false |
|
62 | false |
|
63 | end |
|
63 | end |
|
64 | end |
|
64 | end |
|
65 |
|
65 | ||
|
66 | def admin? |
|
66 | def admin? |
|
67 | self.roles.detect {|r| r.name == 'admin' } |
|
67 | self.roles.detect {|r| r.name == 'admin' } |
|
68 | end |
|
68 | end |
|
69 |
|
69 | ||
|
70 | def email_for_editing |
|
70 | def email_for_editing |
|
71 | if self.email==nil |
|
71 | if self.email==nil |
|
72 | "(unknown)" |
|
72 | "(unknown)" |
|
73 | elsif self.email=='' |
|
73 | elsif self.email=='' |
|
74 | "(blank)" |
|
74 | "(blank)" |
|
75 | else |
|
75 | else |
|
76 | self.email |
|
76 | self.email |
|
77 | end |
|
77 | end |
|
78 | end |
|
78 | end |
|
79 |
|
79 | ||
|
80 | def email_for_editing=(e) |
|
80 | def email_for_editing=(e) |
|
81 | self.email=e |
|
81 | self.email=e |
|
82 | end |
|
82 | end |
|
83 |
|
83 | ||
|
84 | def alias_for_editing |
|
84 | def alias_for_editing |
|
85 | if self.alias==nil |
|
85 | if self.alias==nil |
|
86 | "(unknown)" |
|
86 | "(unknown)" |
|
87 | elsif self.alias=='' |
|
87 | elsif self.alias=='' |
|
88 | "(blank)" |
|
88 | "(blank)" |
|
89 | else |
|
89 | else |
|
90 | self.alias |
|
90 | self.alias |
|
91 | end |
|
91 | end |
|
92 | end |
|
92 | end |
|
93 |
|
93 | ||
|
94 | def alias_for_editing=(e) |
|
94 | def alias_for_editing=(e) |
|
95 | self.alias=e |
|
95 | self.alias=e |
|
96 | end |
|
96 | end |
|
97 |
|
97 | ||
|
98 | def activation_key |
|
98 | def activation_key |
|
99 | if self.hashed_password==nil |
|
99 | if self.hashed_password==nil |
|
100 | encrypt_new_password |
|
100 | encrypt_new_password |
|
101 | end |
|
101 | end |
|
102 | Digest::SHA1.hexdigest(self.hashed_password)[0..7] |
|
102 | Digest::SHA1.hexdigest(self.hashed_password)[0..7] |
|
103 | end |
|
103 | end |
|
104 |
|
104 | ||
|
105 | def verify_activation_key(key) |
|
105 | def verify_activation_key(key) |
|
106 | key == activation_key |
|
106 | key == activation_key |
|
107 | end |
|
107 | end |
|
108 |
|
108 | ||
|
109 | def self.random_password(length=5) |
|
109 | def self.random_password(length=5) |
|
110 | chars = 'abcdefghjkmnopqrstuvwxyz' |
|
110 | chars = 'abcdefghjkmnopqrstuvwxyz' |
|
111 | password = '' |
|
111 | password = '' |
|
112 | length.times { password << chars[rand(chars.length - 1)] } |
|
112 | length.times { password << chars[rand(chars.length - 1)] } |
|
113 | password |
|
113 | password |
|
114 | end |
|
114 | end |
|
115 |
|
115 | ||
|
|
116 | + def self.find_non_admin_with_prefix(prefix='') | ||
|
|
117 | + users = User.find(:all) | ||
|
|
118 | + return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 } | ||
|
|
119 | + end | ||
|
|
120 | + | ||
|
116 | protected |
|
121 | protected |
|
117 | def encrypt_new_password |
|
122 | def encrypt_new_password |
|
118 | return if password.blank? |
|
123 | return if password.blank? |
|
119 | self.salt = (10+rand(90)).to_s |
|
124 | self.salt = (10+rand(90)).to_s |
|
120 | self.hashed_password = User.encrypt(self.password,self.salt) |
|
125 | self.hashed_password = User.encrypt(self.password,self.salt) |
|
121 | end |
|
126 | end |
|
122 |
|
127 | ||
|
123 | def assign_default_site |
|
128 | def assign_default_site |
|
124 | # have to catch error when migrating (because self.site is not available). |
|
129 | # have to catch error when migrating (because self.site is not available). |
|
125 | begin |
|
130 | begin |
|
126 | if self.site==nil |
|
131 | if self.site==nil |
|
127 | self.site = Site.find_by_name('default') |
|
132 | self.site = Site.find_by_name('default') |
|
128 | if self.site==nil |
|
133 | if self.site==nil |
|
129 | self.site = Site.find(1) # when 'default has be renamed' |
|
134 | self.site = Site.find(1) # when 'default has be renamed' |
|
130 | end |
|
135 | end |
|
131 | end |
|
136 | end |
|
132 | rescue |
|
137 | rescue |
|
133 | end |
|
138 | end |
|
134 | end |
|
139 | end |
|
135 |
|
140 | ||
|
136 | def password_required? |
|
141 | def password_required? |
|
137 | self.hashed_password.blank? || !self.password.blank? |
|
142 | self.hashed_password.blank? || !self.password.blank? |
|
138 | end |
|
143 | end |
|
139 |
|
144 | ||
|
140 | def self.encrypt(string,salt) |
|
145 | def self.encrypt(string,salt) |
|
141 | Digest::SHA1.hexdigest(salt + string) |
|
146 | Digest::SHA1.hexdigest(salt + string) |
|
142 | end |
|
147 | end |
|
143 |
|
148 | ||
|
144 | def uniqueness_of_email_from_activated_users |
|
149 | def uniqueness_of_email_from_activated_users |
|
145 | user = User.activated_users.find_by_email(self.email) |
|
150 | user = User.activated_users.find_by_email(self.email) |
|
146 | if user and (user.login != self.login) |
|
151 | if user and (user.login != self.login) |
|
147 | self.errors.add_to_base("Email has already been taken") |
|
152 | self.errors.add_to_base("Email has already been taken") |
|
148 | end |
|
153 | end |
|
149 | end |
|
154 | end |
|
150 |
|
155 | ||
|
151 | def enough_time_interval_between_same_email_registrations |
|
156 | def enough_time_interval_between_same_email_registrations |
|
152 | return if !self.new_record? |
|
157 | return if !self.new_record? |
|
153 | return if self.activated |
|
158 | return if self.activated |
|
154 | open_user = User.find_by_email(self.email, |
|
159 | open_user = User.find_by_email(self.email, |
|
155 | :order => 'created_at DESC') |
|
160 | :order => 'created_at DESC') |
|
156 | if open_user and open_user.created_at and |
|
161 | if open_user and open_user.created_at and |
|
157 | (open_user.created_at > Time.now.gmtime - 5.minutes) |
|
162 | (open_user.created_at > Time.now.gmtime - 5.minutes) |
|
158 | self.errors.add_to_base("There are already unactivated registrations with this e-mail address (please wait for 5 minutes)") |
|
163 | self.errors.add_to_base("There are already unactivated registrations with this e-mail address (please wait for 5 minutes)") |
|
159 | end |
|
164 | end |
|
160 | end |
|
165 | end |
|
161 |
|
166 | ||
|
162 | def email_validation? |
|
167 | def email_validation? |
|
163 | begin |
|
168 | begin |
|
164 | return VALIDATE_USER_EMAILS |
|
169 | return VALIDATE_USER_EMAILS |
|
165 | rescue |
|
170 | rescue |
|
166 | return false |
|
171 | return false |
|
167 | end |
|
172 | end |
|
168 | end |
|
173 | end |
|
169 | end |
|
174 | end |
@@ -1,63 +1,64 | |||||
|
1 | <h1>Listing users</h1> |
|
1 | <h1>Listing users</h1> |
|
2 |
|
2 | ||
|
3 | <div class="submitbox"> |
|
3 | <div class="submitbox"> |
|
4 | <b>Quick add</b> |
|
4 | <b>Quick add</b> |
|
5 | <% form_tag :action => 'create' do %> |
|
5 | <% form_tag :action => 'create' do %> |
|
6 | <table border="0"> |
|
6 | <table border="0"> |
|
7 | <tr> |
|
7 | <tr> |
|
8 | <td><label for="user_login">Login</label></td> |
|
8 | <td><label for="user_login">Login</label></td> |
|
9 | <td><label for="user_full_name">Full name</label></td> |
|
9 | <td><label for="user_full_name">Full name</label></td> |
|
10 | <td><label for="user_password">Password</label></td> |
|
10 | <td><label for="user_password">Password</label></td> |
|
11 | <td><label for="user_password_confirmation">Confirm</label></td> |
|
11 | <td><label for="user_password_confirmation">Confirm</label></td> |
|
12 | <td><label for="user_email">Email</label></td> |
|
12 | <td><label for="user_email">Email</label></td> |
|
13 | </tr> |
|
13 | </tr> |
|
14 | <tr> |
|
14 | <tr> |
|
15 | <td><%= text_field 'user', 'login', :size => 10 %></td> |
|
15 | <td><%= text_field 'user', 'login', :size => 10 %></td> |
|
16 | <td><%= text_field 'user', 'full_name', :size => 30 %></td> |
|
16 | <td><%= text_field 'user', 'full_name', :size => 30 %></td> |
|
17 | <td><%= password_field 'user', 'password', :size => 10 %></td> |
|
17 | <td><%= password_field 'user', 'password', :size => 10 %></td> |
|
18 | <td><%= password_field 'user', 'password_confirmation', :size => 10 %></td> |
|
18 | <td><%= password_field 'user', 'password_confirmation', :size => 10 %></td> |
|
19 | <td><%= text_field 'user', 'email', :size => 15 %></td> |
|
19 | <td><%= text_field 'user', 'email', :size => 15 %></td> |
|
20 | <td><%= submit_tag "Create" %></td> |
|
20 | <td><%= submit_tag "Create" %></td> |
|
21 | </tr></table> |
|
21 | </tr></table> |
|
22 | <% end %> |
|
22 | <% end %> |
|
23 | <br/> |
|
23 | <br/> |
|
24 | <b>Import from site management</b> |
|
24 | <b>Import from site management</b> |
|
25 | <% form_tag({:action => 'import'}, :multipart => true) do %> |
|
25 | <% form_tag({:action => 'import'}, :multipart => true) do %> |
|
26 | File: <%= file_field_tag 'file' %> <%= submit_tag 'Import' %> |
|
26 | File: <%= file_field_tag 'file' %> <%= submit_tag 'Import' %> |
|
27 | <% end %> |
|
27 | <% end %> |
|
28 | <br/> |
|
28 | <br/> |
|
29 | <b>What else: </b> |
|
29 | <b>What else: </b> |
|
30 | <%= link_to '[New user]', :action => 'new' %> |
|
30 | <%= link_to '[New user]', :action => 'new' %> |
|
31 | <%= link_to '[New list of users]', :action => 'new_list' %> |
|
31 | <%= link_to '[New list of users]', :action => 'new_list' %> |
|
|
32 | + <%= link_to '[Random passwords]', :action => 'random_all_passwords' %> | ||
|
32 | <%= link_to '[View active users]', :action => 'active' %> |
|
33 | <%= link_to '[View active users]', :action => 'active' %> |
|
33 |
|
34 | ||
|
34 | </div> |
|
35 | </div> |
|
35 |
|
36 | ||
|
36 | <table> |
|
37 | <table> |
|
37 | <tr> |
|
38 | <tr> |
|
38 | <% for column in User.content_columns %> |
|
39 | <% for column in User.content_columns %> |
|
39 | <% if !@hidden_columns.index(column.name) %> |
|
40 | <% if !@hidden_columns.index(column.name) %> |
|
40 | <th><%= column.human_name %></th> |
|
41 | <th><%= column.human_name %></th> |
|
41 | <% end %> |
|
42 | <% end %> |
|
42 | <% end %> |
|
43 | <% end %> |
|
43 | </tr> |
|
44 | </tr> |
|
44 |
|
45 | ||
|
45 | <% for user in @users %> |
|
46 | <% for user in @users %> |
|
46 | <tr> |
|
47 | <tr> |
|
47 | <% for column in User.content_columns %> |
|
48 | <% for column in User.content_columns %> |
|
48 | <% if !@hidden_columns.index(column.name) %> |
|
49 | <% if !@hidden_columns.index(column.name) %> |
|
49 | <td><%=h user.send(column.name) %></td> |
|
50 | <td><%=h user.send(column.name) %></td> |
|
50 | <% end %> |
|
51 | <% end %> |
|
51 | <% end %> |
|
52 | <% end %> |
|
52 | <td><%= link_to 'Show', :action => 'show', :id => user %></td> |
|
53 | <td><%= link_to 'Show', :action => 'show', :id => user %></td> |
|
53 | <td><%= link_to 'Edit', :action => 'edit', :id => user %></td> |
|
54 | <td><%= link_to 'Edit', :action => 'edit', :id => user %></td> |
|
54 | <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td> |
|
55 | <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td> |
|
55 | </tr> |
|
56 | </tr> |
|
56 | <% end %> |
|
57 | <% end %> |
|
57 | </table> |
|
58 | </table> |
|
58 |
|
59 | ||
|
59 |
|
60 | ||
|
60 | <br /> |
|
61 | <br /> |
|
61 |
|
62 | ||
|
62 | <%= link_to 'New user', :action => 'new' %> |
|
63 | <%= link_to 'New user', :action => 'new' %> |
|
63 | <%= link_to 'New list of users', :action => 'new_list' %> |
|
64 | <%= link_to 'New list of users', :action => 'new_list' %> |
@@ -1,12 +1,8 | |||||
|
1 | <h1>Adding list of users</h1> |
|
1 | <h1>Adding list of users</h1> |
|
2 |
|
2 | ||
|
3 | - <div class="usermenu"> |
|
||
|
4 | - <%= link_to 'User admin', :action => 'list' %> |
|
||
|
5 | - <%= link_to 'Main', :controller => 'main', :action => 'list' %> |
|
||
|
6 | - </div> |
|
||
|
7 | - |
|
||
|
8 | <% form_tag :action => 'create_from_list' do %> |
|
3 | <% form_tag :action => 'create_from_list' do %> |
|
9 | <%= submit_tag 'create users' %><br/> |
|
4 | <%= submit_tag 'create users' %><br/> |
|
10 |
- List of user information: user_id,name |
|
5 | + List of user information in this format: <tt>user_id,name(,passwd(,alias))</tt><br/> |
|
|
6 | + Note that <tt>passwd</tt> and <tt>alias</tt> is optional.<br/> | ||
|
11 | <%= text_area_tag 'user_list', nil, :rows => 50, :cols => 80 %> |
|
7 | <%= text_area_tag 'user_list', nil, :rows => 50, :cols => 80 %> |
|
12 | <% end %> |
|
8 | <% end %> |
You need to be logged in to leave comments.
Login now