Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
4426bc18
Commit
4426bc18
authored
Jun 26, 2012
by
Jakub Troszok
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added option to automaticaly generate passwords for new users.
parent
bea05839
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
12 deletions
+47
-12
app/assets/javascripts/admin.js
app/assets/javascripts/admin.js
+11
-0
app/models/user.rb
app/models/user.rb
+5
-2
app/views/admin/users/_form.html.haml
app/views/admin/users/_form.html.haml
+15
-6
spec/models/user_spec.rb
spec/models/user_spec.rb
+16
-4
No files found.
app/assets/javascripts/admin.js
0 → 100644
View file @
4426bc18
$
(
document
).
ready
(
function
(){
$
(
'
input#user_force_random_password
'
).
on
(
'
change
'
,
function
(
elem
)
{
var
elems
=
$
(
'
#user_password, #user_password_confirmation
'
);
if
(
$
(
this
).
attr
(
'
checked
'
))
{
elems
.
val
(
''
).
attr
(
'
disabled
'
,
true
);
}
else
{
elems
.
removeAttr
(
'
disabled
'
);
}
});
});
app/models/user.rb
View file @
4426bc18
...
@@ -5,7 +5,10 @@ class User < ActiveRecord::Base
...
@@ -5,7 +5,10 @@ class User < ActiveRecord::Base
:recoverable
,
:rememberable
,
:trackable
,
:validatable
,
:omniauthable
:recoverable
,
:rememberable
,
:trackable
,
:validatable
,
:omniauthable
attr_accessible
:email
,
:password
,
:password_confirmation
,
:remember_me
,
:bio
,
attr_accessible
:email
,
:password
,
:password_confirmation
,
:remember_me
,
:bio
,
:name
,
:projects_limit
,
:skype
,
:linkedin
,
:twitter
,
:dark_scheme
,
:theme_id
:name
,
:projects_limit
,
:skype
,
:linkedin
,
:twitter
,
:dark_scheme
,
:theme_id
,
:force_random_password
attr_accessor
:force_random_password
has_many
:users_projects
,
:dependent
=>
:destroy
has_many
:users_projects
,
:dependent
=>
:destroy
has_many
:projects
,
:through
=>
:users_projects
has_many
:projects
,
:through
=>
:users_projects
...
@@ -56,7 +59,7 @@ class User < ActiveRecord::Base
...
@@ -56,7 +59,7 @@ class User < ActiveRecord::Base
before_validation
:generate_password
,
:on
=>
:create
before_validation
:generate_password
,
:on
=>
:create
def
generate_password
def
generate_password
if
self
.
password
.
blank?
&&
self
.
password_confirmation
.
blank?
if
self
.
force_random_password
==
true
self
.
password
=
self
.
password_confirmation
=
Devise
.
friendly_token
.
first
(
8
)
self
.
password
=
self
.
password_confirmation
=
Devise
.
friendly_token
.
first
(
8
)
end
end
end
end
...
...
app/views/admin/users/_form.html.haml
View file @
4426bc18
...
@@ -18,12 +18,21 @@
...
@@ -18,12 +18,21 @@
.input
.input
=
f
.
text_field
:email
=
f
.
text_field
:email
%span
.help-inline
* required
%span
.help-inline
* required
%hr
-
if
f
.
object
.
new_record?
.clearfix
=
f
.
label
:admin
,
:class
=>
"checkbox"
do
=
f
.
check_box
:force_random_password
%span
Generate random password
%div
.password-fields
.clearfix
.clearfix
=
f
.
label
:password
=
f
.
label
:password
.input
=
f
.
password_field
:password
.input
=
f
.
password_field
:password
,
:disabled
=>
f
.
object
.
force_random_password
.clearfix
.clearfix
=
f
.
label
:password_confirmation
=
f
.
label
:password_confirmation
.input
=
f
.
password_field
:password_confirmation
.input
=
f
.
password_field
:password_confirmation
,
:disabled
=>
f
.
object
.
force_random_password
%hr
%hr
.clearfix
.clearfix
=
f
.
label
:skype
=
f
.
label
:skype
...
...
spec/models/user_spec.rb
View file @
4426bc18
...
@@ -22,10 +22,22 @@ describe User do
...
@@ -22,10 +22,22 @@ describe User do
user
.
identifier
.
should
==
"test_mail_com"
user
.
identifier
.
should
==
"test_mail_com"
end
end
it
"should generate password when password is empty"
do
it
"should execute callback when force_random_password specified"
do
user
=
User
.
create
(
:email
=>
"test1@mail.com"
)
user
=
User
.
new
(
:email
=>
"test@mail.com"
,
:force_random_password
=>
true
)
user
.
password
.
should
eql
(
user
.
password_confirmation
)
user
.
should_receive
(
:generate_password
)
user
.
password
.
should_not
be_empty
user
.
save
end
it
"should not generate password by default"
do
user
=
Factory
(
:user
,
:password
=>
'abcdefg'
,
:password_confirmation
=>
'abcdefg'
)
user
.
password
.
should
==
'abcdefg'
end
it
"should generate password when forcing random password"
do
Devise
.
stub
(
:friendly_token
).
and_return
(
'123456789'
)
user
=
User
.
create
(
:email
=>
"test1@mail.com"
,
:force_random_password
=>
true
)
user
.
password
.
should
==
user
.
password_confirmation
user
.
password
.
should
==
'12345678'
end
end
it
"should have authentication token"
do
it
"should have authentication token"
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment