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
|
include Diaspora::UserModules::Friending
|
||||||
devise :database_authenticatable, :registerable,
|
devise :database_authenticatable, :registerable,
|
||||||
:recoverable, :rememberable, :trackable, :validatable
|
:recoverable, :rememberable, :trackable, :validatable
|
||||||
|
key :username, :unique => true
|
||||||
|
|
||||||
key :friend_ids, Array
|
key :friend_ids, Array
|
||||||
key :pending_request_ids, Array
|
key :pending_request_ids, Array
|
||||||
|
|
@ -23,6 +24,14 @@ class User
|
||||||
before_validation_on_create :setup_person
|
before_validation_on_create :setup_person
|
||||||
before_validation :do_bad_things
|
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 ########
|
######## Making things work ########
|
||||||
key :email, String
|
key :email, String
|
||||||
ensure_index :email
|
ensure_index :email
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
|
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
|
||||||
= devise_error_messages!
|
= devise_error_messages!
|
||||||
|
%p
|
||||||
|
= f.label :username
|
||||||
|
= f.text_field :username
|
||||||
%p
|
%p
|
||||||
= f.label :email
|
= f.label :email
|
||||||
= f.text_field :email
|
= f.text_field :email
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
|
= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
|
||||||
%p
|
%p
|
||||||
= f.label :email
|
= f.label :username
|
||||||
= f.text_field :email
|
= f.text_field :username
|
||||||
%p
|
%p
|
||||||
= f.label :password
|
= f.label :password
|
||||||
= f.password_field :password
|
= f.password_field :password
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ Devise.setup do |config|
|
||||||
# authenticating an user, both parameters are required. Remember that those
|
# authenticating an user, both parameters are required. Remember that those
|
||||||
# parameters are used only when authenticating and not when retrieving from
|
# parameters are used only when authenticating and not when retrieving from
|
||||||
# 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.
|
||||||
# config.authentication_keys = [ :email ]
|
config.authentication_keys = [ :username ]
|
||||||
|
|
||||||
# Tell if authentication through request.params is enabled. True by default.
|
# Tell if authentication through request.params is enabled. True by default.
|
||||||
# config.params_authenticatable = true
|
# config.params_authenticatable = true
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ def create
|
||||||
# Create seed user
|
# Create seed user
|
||||||
username = backer_info[backer_number]['username'].gsub(/ /,'').downcase
|
username = backer_info[backer_number]['username'].gsub(/ /,'').downcase
|
||||||
user = User.create( :email => "#{username}@#{username}.joindiaspora.com",
|
user = User.create( :email => "#{username}@#{username}.joindiaspora.com",
|
||||||
|
:username => username,
|
||||||
:password => "#{username+backer_info[backer_number]['pin'].to_s}",
|
:password => "#{username+backer_info[backer_number]['pin'].to_s}",
|
||||||
:person => Person.new(
|
:person => Person.new(
|
||||||
:email => "#{username}@#{username}.joindiaspora.com",
|
:email => "#{username}@#{username}.joindiaspora.com",
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ host = "localhost:3000"
|
||||||
url = "http://#{host}/"
|
url = "http://#{host}/"
|
||||||
# Create seed user
|
# Create seed user
|
||||||
user = User.instantiate!( :email => "tom@tom.joindiaspora.com",
|
user = User.instantiate!( :email => "tom@tom.joindiaspora.com",
|
||||||
|
:username => "tom",
|
||||||
:password => "evankorth",
|
:password => "evankorth",
|
||||||
:person => Person.new(
|
:person => Person.new(
|
||||||
:email => "tom@tom.joindiaspora.com",
|
:email => "tom@tom.joindiaspora.com",
|
||||||
|
|
@ -13,6 +14,7 @@ user = User.instantiate!( :email => "tom@tom.joindiaspora.com",
|
||||||
user.person.save!
|
user.person.save!
|
||||||
|
|
||||||
user2 = User.instantiate!( :email => "korth@tom.joindiaspora.com",
|
user2 = User.instantiate!( :email => "korth@tom.joindiaspora.com",
|
||||||
|
:username => "korth",
|
||||||
:password => "evankorth",
|
:password => "evankorth",
|
||||||
:person => Person.new( :email => "korth@tom.joindiaspora.com",
|
:person => Person.new( :email => "korth@tom.joindiaspora.com",
|
||||||
:url => url,
|
:url => url,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ require 'config/environment'
|
||||||
remote_url = "http://tom.joindiaspora.com/"
|
remote_url = "http://tom.joindiaspora.com/"
|
||||||
# Create seed user
|
# Create seed user
|
||||||
user = User.instantiate!( :email => "tom@tom.joindiaspora.com",
|
user = User.instantiate!( :email => "tom@tom.joindiaspora.com",
|
||||||
|
:username => "tom",
|
||||||
:password => "evankorth",
|
:password => "evankorth",
|
||||||
:person => {
|
:person => {
|
||||||
:email => "tom@tom.joindiaspora.com",
|
:email => "tom@tom.joindiaspora.com",
|
||||||
|
|
@ -14,6 +15,7 @@ user.person.save!
|
||||||
|
|
||||||
user2 = User.instantiate!( :email => "korth@tom.joindiaspora.com",
|
user2 = User.instantiate!( :email => "korth@tom.joindiaspora.com",
|
||||||
:password => "evankorth",
|
:password => "evankorth",
|
||||||
|
:username => "korth",
|
||||||
:person => { :email => "korth@tom.joindiaspora.com",
|
:person => { :email => "korth@tom.joindiaspora.com",
|
||||||
:url => remote_url,
|
:url => remote_url,
|
||||||
:profile => { :first_name => "Evan",
|
:profile => { :first_name => "Evan",
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ Factory.define :person_with_user, :parent => :person_with_private_key do |p|
|
||||||
end
|
end
|
||||||
|
|
||||||
Factory.define :user do |u|
|
Factory.define :user do |u|
|
||||||
|
u.sequence(:username) {|n| "bob#{n}"}
|
||||||
u.sequence(:email) {|n| "bob#{n}@aol.com"}
|
u.sequence(:email) {|n| "bob#{n}@aol.com"}
|
||||||
u.password "bluepin7"
|
u.password "bluepin7"
|
||||||
u.password_confirmation "bluepin7"
|
u.password_confirmation "bluepin7"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue