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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
faa0ec7c
Commit
faa0ec7c
authored
May 29, 2012
by
Nihad Abbasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup User model
parent
fc74627f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
15 deletions
+7
-15
app/models/user.rb
app/models/user.rb
+6
-14
spec/models/user_spec.rb
spec/models/user_spec.rb
+1
-1
No files found.
app/models/user.rb
View file @
faa0ec7c
class
User
<
ActiveRecord
::
Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise
:database_authenticatable
,
:token_authenticatable
,
:recoverable
,
:rememberable
,
:trackable
,
:validatable
,
:omniauthable
# Setup accessible (or protected) attributes for your model
attr_accessible
:email
,
:password
,
:password_confirmation
,
:remember_me
,
:bio
,
:name
,
:projects_limit
,
:skype
,
:linkedin
,
:twitter
,
:dark_scheme
,
:theme_id
...
...
@@ -46,7 +43,7 @@ class User < ActiveRecord::Base
validates
:bio
,
:length
=>
{
:within
=>
0
..
255
}
before_
creat
e
:ensure_authentication_token
before_
sav
e
:ensure_authentication_token
alias_attribute
:private_token
,
:authentication_token
scope
:not_in_project
,
lambda
{
|
project
|
where
(
"id not in (:ids)"
,
:ids
=>
project
.
users
.
map
(
&
:id
)
)
}
...
...
@@ -76,7 +73,6 @@ class User < ActiveRecord::Base
admin
end
def
require_ssh_key?
keys
.
count
==
0
end
...
...
@@ -89,12 +85,8 @@ class User < ActiveRecord::Base
projects
.
first
end
def
self
.
generate_random_password
(
0
...
8
).
map
{
(
'a'
..
'z'
).
to_a
[
rand
(
26
)]
}.
join
end
def
first_name
name
.
split
(
" "
)
.
first
unless
name
.
blank?
name
.
split
.
first
unless
name
.
blank?
end
def
self
.
find_for_ldap_auth
(
omniauth_info
)
...
...
@@ -104,8 +96,9 @@ class User < ActiveRecord::Base
if
@user
=
User
.
find_by_email
(
email
)
@user
else
password
=
generate_random_password
@user
=
User
.
create
(
:name
=>
name
,
password
=
Devise
.
friendly_token
[
0
,
8
].
downcase
@user
=
User
.
create
(
:name
=>
name
,
:email
=>
email
,
:password
=>
password
,
:password_confirmation
=>
password
...
...
@@ -163,4 +156,3 @@ end
# authentication_token :string(255)
# dark_scheme :boolean default(FALSE), not null
#
spec/models/user_spec.rb
View file @
faa0ec7c
...
...
@@ -14,6 +14,7 @@ describe User do
it
{
should
respond_to
(
:is_admin?
)
}
it
{
should
respond_to
(
:identifier
)
}
it
{
should
respond_to
(
:name
)
}
it
{
should
respond_to
(
:private_token
)
}
end
it
"should return valid identifier"
do
...
...
@@ -67,4 +68,3 @@ end
# authentication_token :string(255)
# dark_scheme :boolean default(FALSE), not null
#
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