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
iv
gitlab-ce
Commits
795bb9cf
Commit
795bb9cf
authored
Mar 25, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/login_with_username'
parents
1496c015
9d92433a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
10 deletions
+27
-10
app/models/user.rb
app/models/user.rb
+17
-0
app/views/devise/sessions/new.html.haml
app/views/devise/sessions/new.html.haml
+8
-8
config/initializers/devise.rb
config/initializers/devise.rb
+1
-1
spec/support/login_helpers.rb
spec/support/login_helpers.rb
+1
-1
No files found.
app/models/user.rb
View file @
795bb9cf
...
@@ -46,6 +46,13 @@ class User < ActiveRecord::Base
...
@@ -46,6 +46,13 @@ class User < ActiveRecord::Base
attr_accessor
:force_random_password
attr_accessor
:force_random_password
# Virtual attribute for authenticating by either username or email
attr_accessor
:login
# Add login to attr_accessible
attr_accessible
:login
#
#
# Relations
# Relations
#
#
...
@@ -140,6 +147,16 @@ class User < ActiveRecord::Base
...
@@ -140,6 +147,16 @@ class User < ActiveRecord::Base
# Class methods
# Class methods
#
#
class
<<
self
class
<<
self
# Devise method overriden to allow sing in with email or username
def
find_for_database_authentication
(
warden_conditions
)
conditions
=
warden_conditions
.
dup
if
login
=
conditions
.
delete
(
:login
)
where
(
conditions
).
where
([
"lower(username) = :value OR lower(email) = :value"
,
{
value:
login
.
downcase
}]).
first
else
where
(
conditions
).
first
end
end
def
filter
filter_name
def
filter
filter_name
case
filter_name
case
filter_name
when
"admins"
;
self
.
admins
when
"admins"
;
self
.
admins
...
...
app/views/devise/sessions/new.html.haml
View file @
795bb9cf
-
if
ldap_enable?
-
if
ldap_enable?
=
render
:partial
=>
'devise/sessions/new_ldap'
=
render
partial:
'devise/sessions/new_ldap'
-
else
-
else
=
form_for
(
resource
,
:as
=>
resource_name
,
:url
=>
session_path
(
resource_name
),
:html
=>
{
:class
=>
"login-box"
})
do
|
f
|
=
form_for
(
resource
,
as:
resource_name
,
url:
session_path
(
resource_name
),
html:
{
class:
"login-box"
})
do
|
f
|
=
image_tag
"login-logo.png"
,
:width
=>
"304"
,
:height
=>
"66"
,
:class
=>
"login-logo"
,
:alt
=>
"Login Logo"
=
image_tag
"login-logo.png"
,
width:
"304"
,
height:
"66"
,
class:
"login-logo"
,
alt:
"Login Logo"
=
f
.
email_field
:email
,
:class
=>
"text top"
,
:placeholder
=>
"Email"
,
:autofocus
=>
"autofocus"
=
f
.
text_field
:login
,
class:
"text top"
,
placeholder:
"Username or Email"
,
autofocus:
"autofocus"
=
f
.
password_field
:password
,
:class
=>
"text bottom"
,
:placeholder
=>
"Password"
=
f
.
password_field
:password
,
class:
"text bottom"
,
placeholder:
"Password"
-
if
devise_mapping
.
rememberable?
-
if
devise_mapping
.
rememberable?
.clearfix.inputs-list
.clearfix.inputs-list
%label
.checkbox.remember_me
{
:for
=>
"user_remember_me"
}
%label
.checkbox.remember_me
{
for:
"user_remember_me"
}
=
f
.
check_box
:remember_me
=
f
.
check_box
:remember_me
%span
Remember me
%span
Remember me
%br
/
%br
/
=
f
.
submit
"Sign in"
,
:class
=>
"btn-create btn"
=
f
.
submit
"Sign in"
,
class:
"btn-create btn"
.pull-right
.pull-right
=
link_to
"Forgot your password?"
,
new_password_path
(
resource_name
),
:class
=>
"btn"
=
link_to
"Forgot your password?"
,
new_password_path
(
resource_name
),
class:
"btn"
%br
/
%br
/
-
if
Gitlab
.
config
.
gitlab
.
signup_enabled
-
if
Gitlab
.
config
.
gitlab
.
signup_enabled
%hr
/
%hr
/
...
...
config/initializers/devise.rb
View file @
795bb9cf
...
@@ -23,7 +23,7 @@ Devise.setup do |config|
...
@@ -23,7 +23,7 @@ Devise.setup do |config|
# session. If you need permissions, you should implement that in a before filter.
# session. If you need permissions, you should implement that in a before filter.
# You can also supply a hash where the value is a boolean determining whether
# You can also supply a hash where the value is a boolean determining whether
# or not authentication should be aborted when the value is not present.
# or not authentication should be aborted when the value is not present.
# config.authentication_keys = [ :email
]
config
.
authentication_keys
=
[
:login
]
# Configure parameters from the request object used for authentication. Each entry
# Configure parameters from the request object used for authentication. Each entry
# given should be a request method and it will automatically be passed to the
# given should be a request method and it will automatically be passed to the
...
...
spec/support/login_helpers.rb
View file @
795bb9cf
...
@@ -12,7 +12,7 @@ module LoginHelpers
...
@@ -12,7 +12,7 @@ module LoginHelpers
# user - User instance to login with
# user - User instance to login with
def
login_with
(
user
)
def
login_with
(
user
)
visit
new_user_session_path
visit
new_user_session_path
fill_in
"user_
email
"
,
with:
user
.
email
fill_in
"user_
login
"
,
with:
user
.
email
fill_in
"user_password"
,
with:
"123456"
fill_in
"user_password"
,
with:
"123456"
click_button
"Sign in"
click_button
"Sign in"
end
end
...
...
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