when connected, external services fill in profile info that you have not yet filled out
This commit is contained in:
parent
aa1623a95f
commit
cb89772a6a
4 changed files with 38 additions and 1 deletions
|
|
@ -26,9 +26,11 @@ class ServicesController < ApplicationController
|
||||||
:uid => auth['uid'])
|
:uid => auth['uid'])
|
||||||
current_user.services << service
|
current_user.services << service
|
||||||
|
|
||||||
|
current_user.update_profile(current_user.person.profile.from_omniauth_hash(user))
|
||||||
|
|
||||||
flash[:notice] = I18n.t 'services.create.success'
|
flash[:notice] = I18n.t 'services.create.success'
|
||||||
if current_user.getting_started
|
if current_user.getting_started
|
||||||
redirect_to getting_started_path(:step => 3)
|
redirect_to getting_started_path
|
||||||
else
|
else
|
||||||
redirect_to services_url
|
redirect_to services_url
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ class Profile < ActiveRecord::Base
|
||||||
before_validation do
|
before_validation do
|
||||||
self.tag_string = self.tag_string.split[0..4].join(' ')
|
self.tag_string = self.tag_string.split[0..4].join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
before_save do
|
before_save do
|
||||||
self.build_tags
|
self.build_tags
|
||||||
self.construct_full_name
|
self.construct_full_name
|
||||||
|
|
@ -77,6 +78,23 @@ class Profile < ActiveRecord::Base
|
||||||
result || '/images/user/default.png'
|
result || '/images/user/default.png'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def from_omniauth_hash(omniauth_user_hash)
|
||||||
|
mappings = {"description" => "bio",
|
||||||
|
'image' => 'image_url',
|
||||||
|
'first_name' => 'first_name',
|
||||||
|
'last_name' => 'last_name',
|
||||||
|
'location' => 'location',
|
||||||
|
'name' => 'full_name'
|
||||||
|
}
|
||||||
|
if omniauth_user_hash['first_name'].blank? || omniauth_user_hash['last_name'].blank?
|
||||||
|
omniauth_user_hash['first_name'], omniauth_user_hash['last_name'] = omniauth_user_hash['name'].split
|
||||||
|
end
|
||||||
|
|
||||||
|
update_hash = Hash[omniauth_user_hash.map {|k, v| [mappings[k], v] }]
|
||||||
|
|
||||||
|
self.attributes.merge(update_hash){|key, old, new| old.blank? ? new : old}
|
||||||
|
end
|
||||||
|
|
||||||
def image_url= url
|
def image_url= url
|
||||||
return image_url if url == ''
|
return image_url if url == ''
|
||||||
if url.nil? || url.match(/^https?:\/\//)
|
if url.nil? || url.match(/^https?:\/\//)
|
||||||
|
|
|
||||||
|
|
@ -309,6 +309,7 @@ class User < ActiveRecord::Base
|
||||||
params[:image_url_medium] = photo.url(:thumb_medium)
|
params[:image_url_medium] = photo.url(:thumb_medium)
|
||||||
params[:image_url_small] = photo.url(:thumb_small)
|
params[:image_url_small] = photo.url(:thumb_small)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.person.profile.update_attributes(params)
|
if self.person.profile.update_attributes(params)
|
||||||
Postzord::Dispatcher.build(self, profile).post
|
Postzord::Dispatcher.build(self, profile).post
|
||||||
true
|
true
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,22 @@ describe Profile do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'from_omniauth_hash' do
|
||||||
|
before do
|
||||||
|
@from_omniauth = {'first_name' => 'bob', 'last_name' => 'jones', 'description' => 'this is my bio', 'location' => 'sf', 'image' => 'http://cats.com/gif.gif'}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'outputs a hash that can update a diaspora profile' do
|
||||||
|
profile = Profile.new
|
||||||
|
profile.from_omniauth_hash(@from_omniauth)['first_name'].should == 'bob'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not overwrite any exsisting profile fields' do
|
||||||
|
profile = Profile.new(:first_name => 'maxwell')
|
||||||
|
profile.from_omniauth_hash(@from_omniauth)['first_name'].should == 'maxwell'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#contruct_full_name' do
|
describe '#contruct_full_name' do
|
||||||
it 'generates a full name given only first name' do
|
it 'generates a full name given only first name' do
|
||||||
profile = Factory(:person).profile
|
profile = Factory(:person).profile
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue