Fix broken Yahoo! signup.
This commit is contained in:
parent
f850fe1e75
commit
f00006ee7d
|
@ -124,6 +124,10 @@ class Users::OmniauthCallbacksController < ApplicationController
|
|||
|
||||
email = data[:email]
|
||||
|
||||
# If the auth supplies a name / username, use those. Otherwise start with email.
|
||||
name = data[:name] || data[:email]
|
||||
username = data[:nickname] || data[:email]
|
||||
|
||||
user_open_id = UserOpenId.find_by_url(identity_url)
|
||||
|
||||
if user_open_id.blank? && user = User.find_by_email(email)
|
||||
|
@ -147,8 +151,8 @@ class Users::OmniauthCallbacksController < ApplicationController
|
|||
else
|
||||
@data = {
|
||||
email: email,
|
||||
name: User.suggest_name(email),
|
||||
username: User.suggest_username(email),
|
||||
name: User.suggest_name(name),
|
||||
username: User.suggest_username(username),
|
||||
email_valid: true ,
|
||||
auth_provider: data[:provider]
|
||||
}
|
||||
|
|
|
@ -51,6 +51,9 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.suggest_username(name)
|
||||
|
||||
return nil unless name.present?
|
||||
|
||||
# If it's an email
|
||||
if name =~ /([^@]+)@([^\.]+)/
|
||||
name = Regexp.last_match[1]
|
||||
|
|
|
@ -394,6 +394,11 @@ describe User do
|
|||
end
|
||||
|
||||
describe '.suggest_username' do
|
||||
|
||||
it "doesn't raise an error on nil username" do
|
||||
User.suggest_username(nil).should be_nil
|
||||
end
|
||||
|
||||
it 'corrects weird characters' do
|
||||
User.suggest_username("Darth%^Vadar").should == "Darth_Vadar"
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue