Improved login wording (Username or email). Added functionality.

This commit is contained in:
Martin Edenhofer 2012-04-20 10:58:31 +02:00
parent cb4e9a8745
commit 47df83c4f7
2 changed files with 22 additions and 5 deletions

View file

@ -8,9 +8,9 @@
<div class="span12"> <div class="span12">
Sign in with Sign in with
<form id="login" class="form-search"> <form id="login" class="form-search">
<input name="username" type="text" class="input span3" placeholder="Username" value="<%= @item.username %>" autocapitalize="off"/> <input name="username" type="text" class="input span3" placeholder="Username or email" value="<%= @item.username %>" autocapitalize="off"/>
<input name="password" type="password" class="input span3" placeholder="Password"/> <input name="password" type="password" class="input span3" placeholder="Password"/>
<button class="btn-primary" type="submit">Sign in</button> <button class="btn btn-primary" type="submit">Sign in</button>
</form> </form>
</div> </div>
</div> </div>

View file

@ -13,10 +13,27 @@ class User < ApplicationModel
store :preferences store :preferences
def self.authenticate( username, password ) def self.authenticate( username, password )
# try to find user based on login
user = User.where( :login => username, :active => true ).first user = User.where( :login => username, :active => true ).first
return nil if user.nil?
return user if user.password == password # try second lookup with email
return if !user
user = User.where( :email => username, :active => true ).first
end
# no user found
if !user
return nil
end
# auth ok
if user.password == password
return user
end
# auth failed
return false
end end
def self.create_from_hash!(hash) def self.create_from_hash!(hash)