Add username, login with username or email
This commit is contained in:
parent
5fd1602731
commit
960d40278c
8 changed files with 21 additions and 3 deletions
|
|
@ -5,6 +5,7 @@ class User
|
|||
include Diaspora::UserModules::Friending
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
key :username, :unique => true
|
||||
|
||||
key :friend_ids, Array
|
||||
key :pending_request_ids, Array
|
||||
|
|
@ -23,6 +24,14 @@ class User
|
|||
before_validation_on_create :setup_person
|
||||
before_validation :do_bad_things
|
||||
|
||||
def self.find_for_authentication(conditions={})
|
||||
puts conditions
|
||||
if conditions[:username] =~ /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i # email regex
|
||||
conditions[:email] = conditions.delete(:username)
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
######## Making things work ########
|
||||
key :email, String
|
||||
ensure_index :email
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
|
||||
= devise_error_messages!
|
||||
%p
|
||||
= f.label :username
|
||||
= f.text_field :username
|
||||
%p
|
||||
= f.label :email
|
||||
= f.text_field :email
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
|
||||
%p
|
||||
= f.label :email
|
||||
= f.text_field :email
|
||||
= f.label :username
|
||||
= f.text_field :username
|
||||
%p
|
||||
= f.label :password
|
||||
= f.password_field :password
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ Devise.setup do |config|
|
|||
# authenticating an user, both parameters are required. Remember that those
|
||||
# parameters are used only when authenticating and not when retrieving from
|
||||
# session. If you need permissions, you should implement that in a before filter.
|
||||
# config.authentication_keys = [ :email ]
|
||||
config.authentication_keys = [ :username ]
|
||||
|
||||
# Tell if authentication through request.params is enabled. True by default.
|
||||
# config.params_authenticatable = true
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ def create
|
|||
# Create seed user
|
||||
username = backer_info[backer_number]['username'].gsub(/ /,'').downcase
|
||||
user = User.create( :email => "#{username}@#{username}.joindiaspora.com",
|
||||
:username => username,
|
||||
:password => "#{username+backer_info[backer_number]['pin'].to_s}",
|
||||
:person => Person.new(
|
||||
:email => "#{username}@#{username}.joindiaspora.com",
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ host = "localhost:3000"
|
|||
url = "http://#{host}/"
|
||||
# Create seed user
|
||||
user = User.instantiate!( :email => "tom@tom.joindiaspora.com",
|
||||
:username => "tom",
|
||||
:password => "evankorth",
|
||||
:person => Person.new(
|
||||
:email => "tom@tom.joindiaspora.com",
|
||||
|
|
@ -13,6 +14,7 @@ user = User.instantiate!( :email => "tom@tom.joindiaspora.com",
|
|||
user.person.save!
|
||||
|
||||
user2 = User.instantiate!( :email => "korth@tom.joindiaspora.com",
|
||||
:username => "korth",
|
||||
:password => "evankorth",
|
||||
:person => Person.new( :email => "korth@tom.joindiaspora.com",
|
||||
:url => url,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ require 'config/environment'
|
|||
remote_url = "http://tom.joindiaspora.com/"
|
||||
# Create seed user
|
||||
user = User.instantiate!( :email => "tom@tom.joindiaspora.com",
|
||||
:username => "tom",
|
||||
:password => "evankorth",
|
||||
:person => {
|
||||
:email => "tom@tom.joindiaspora.com",
|
||||
|
|
@ -14,6 +15,7 @@ user.person.save!
|
|||
|
||||
user2 = User.instantiate!( :email => "korth@tom.joindiaspora.com",
|
||||
:password => "evankorth",
|
||||
:username => "korth",
|
||||
:person => { :email => "korth@tom.joindiaspora.com",
|
||||
:url => remote_url,
|
||||
:profile => { :first_name => "Evan",
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ Factory.define :person_with_user, :parent => :person_with_private_key do |p|
|
|||
end
|
||||
|
||||
Factory.define :user do |u|
|
||||
u.sequence(:username) {|n| "bob#{n}"}
|
||||
u.sequence(:email) {|n| "bob#{n}@aol.com"}
|
||||
u.password "bluepin7"
|
||||
u.password_confirmation "bluepin7"
|
||||
|
|
|
|||
Loading…
Reference in a new issue