Add instagram background implementation and generalize application for other identity providers

This commit is contained in:
2014-12-22 15:34:23 +01:00
parent 82b1585b30
commit 22bbe5bbfa
29 changed files with 122 additions and 90 deletions
+1
View File
@@ -54,6 +54,7 @@ gem 'simply_stored', github: 'bterkuile/simply_stored'
gem 'devise', github: 'plataformatec/devise', branch: 'lm-rails-4-2' #, '3.1.0' #, '2.0.4'
gem 'devise_simply_stored', github: 'bterkuile/devise_simply_stored'
gem "omniauth-facebook"
gem "omniauth-instagram"
#gem 'simple_form'
gem 'active_decorator' #, path: '/Users/bterkuile/companytools/development/rails/components/active_decorator'
#gem 'cmtool', github: 'bterkuile/cmtool'
+33 -26
View File
@@ -115,7 +115,7 @@ GEM
sass (~> 3.3)
thor
builder (3.2.2)
capistrano (3.3.4)
capistrano (3.3.5)
capistrano-stats (~> 1.1.0)
i18n
rake (>= 10.0.0)
@@ -129,7 +129,7 @@ GEM
capistrano-rvm (0.1.2)
capistrano (~> 3.0)
sshkit (~> 1.2)
capistrano-stats (1.1.0)
capistrano-stats (1.1.1)
capybara (2.4.4)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
@@ -156,7 +156,7 @@ GEM
execjs
coffee-script-source (1.8.0)
colored (1.2)
colorize (0.7.4)
colorize (0.7.5)
cookiejar (0.3.2)
couchrest (1.2.0)
mime-types (~> 1.15)
@@ -177,7 +177,7 @@ GEM
activemodel
ember-data-source (1.0.0.beta.12)
ember-source
ember-rails (0.15.0)
ember-rails (0.15.1)
active_model_serializers
barber (>= 0.4.1)
ember-data-source (>= 1.0.0.beta.5)
@@ -198,7 +198,7 @@ GEM
ember-rails (>= 0.14.0)
emblem-source (0.3.17)
erubis (2.7.0)
eventmachine (1.0.3)
eventmachine (1.0.4)
execjs (2.2.2)
factory_girl (4.5.0)
activesupport (>= 3.0.0)
@@ -215,14 +215,14 @@ GEM
multi_json (>= 1.0.0)
rack (>= 1.0.0)
websocket-driver (>= 0.3.0)
faye-websocket (0.8.0)
faye-websocket (0.9.2)
eventmachine (>= 0.12.0)
websocket-driver (>= 0.4.0)
websocket-driver (>= 0.5.1)
font-awesome-rails (4.2.0.0)
railties (>= 3.2, < 5.0)
foundation-rails (5.4.5.0)
foundation-rails (5.5.0.0)
railties (>= 3.1.0)
sass (>= 3.2.0)
sass (>= 3.2.0, < 3.4)
fuubar (2.0.0)
rspec (~> 3.0)
ruby-progressbar (~> 1.4)
@@ -234,11 +234,11 @@ GEM
hashie (3.3.2)
hike (1.2.3)
http_parser.rb (0.6.0)
i18n (0.7.0.beta1)
i18n (0.7.0)
iso_country_codes (0.6.1)
jquery-rails (4.0.0)
jquery-rails (4.0.1)
rails-dom-testing (~> 1.0)
railties (>= 4.2.0.beta, < 5.0)
railties (>= 4.2.0.beta)
thor (>= 0.14, < 2.0)
jquery-ui-rails (5.0.3)
railties (>= 3.2.16)
@@ -262,7 +262,7 @@ GEM
mime-types (1.25.1)
mini_magick (4.0.1)
mini_portile (0.6.1)
minitest (5.4.3)
minitest (5.5.0)
multi_json (1.10.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
@@ -282,6 +282,9 @@ GEM
rack (~> 1.0)
omniauth-facebook (2.0.0)
omniauth-oauth2 (~> 1.2)
omniauth-instagram (1.0.1)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.0)
omniauth-oauth2 (1.2.0)
faraday (>= 0.8, < 0.10)
multi_json (~> 1.3)
@@ -301,8 +304,8 @@ GEM
pry (>= 0.9.10)
quiet_assets (1.0.3)
railties (>= 3.1, < 5.0)
rack (1.6.0.beta2)
rack-cors (0.2.9)
rack (1.6.0)
rack-cors (0.3.0)
rack-test (0.6.2)
rack (>= 1.0)
rails (4.2.0.rc2)
@@ -361,8 +364,8 @@ GEM
rspec-mocks (~> 3.1.0)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
ruby-progressbar (1.7.0)
sass (3.4.9)
ruby-progressbar (1.7.1)
sass (3.3.14)
sass-rails (5.0.0.beta1)
railties (>= 4.0.0, < 5.0)
sass (~> 3.2)
@@ -373,17 +376,18 @@ GEM
multi_json (~> 1.0)
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
slim (2.1.0)
temple (~> 0.6.9)
slim (3.0.0)
temple (~> 0.7.3)
tilt (>= 1.3.3, < 2.1)
slim-rails (2.1.5)
slim-rails (3.0.0)
actionmailer (>= 3.0, < 4.2)
actionpack (>= 3.0, < 4.2)
activesupport (>= 3.0, < 4.2)
railties (>= 3.0, < 4.2)
slim (~> 2.0)
slim (~> 3.0)
slop (3.6.0)
spring (1.2.0)
spring-commands-rspec (1.0.3)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
sprockets (2.12.3)
hike (~> 1.2)
@@ -394,11 +398,11 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sshkit (1.5.1)
colorize
sshkit (1.6.1)
colorize (>= 0.7.0)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
temple (0.6.10)
temple (0.7.3)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
@@ -419,7 +423,9 @@ GEM
binding_of_caller (>= 0.7.2)
railties (~> 4.0)
sprockets-rails (>= 2.0, < 4.0)
websocket-driver (0.4.0)
websocket-driver (0.5.1)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.1)
xpath (2.0.0)
nokogiri (~> 1.3)
@@ -459,6 +465,7 @@ DEPENDENCIES
letter_opener
mini_magick
omniauth-facebook
omniauth-instagram
paperclip
pry-rails
quiet_assets
@@ -1,14 +1,13 @@
attr = DS.attr
App.User= DS.Model.extend
facebook_id: attr('string')
email: attr('string')
name: attr('string')
uid: attr('string')
provider: attr('string')
avatar: attr('string')
list: DS.belongsTo('list') # in ember scope not many to many (yet)
join_requests: DS.hasMany('join_request')
facebook_image_tag: (->
facebook_id = @get('facebook_id')
return '' unless facebook_id
url = "http://graph.facebook.com/#{facebook_id}/picture?type=square"
avatar_tag: (->
return unless avatar = @get('avatar')
name = @get('name')
new Handlebars.SafeString "<img src=\"#{url}\" alt=\"#{name}\" title=\"#{name}\" class=\"user-facebook-image\">"
).property('facebook_id', 'name')
"<img src='#{avatar}' alt='#{name}' title='#{name}' class='user-avatar-image #{@get('provider')}'>".htmlSafe()
).property('avatar', 'name')
@@ -14,7 +14,7 @@ if list.closed_at
.display-field= view "close-list-button" content=list
.user-info-container
each user in list.users
=user.facebook_image_tag
=user.avatar_tag
if list.sorted_orders
.list-orders-container
each order in list.sorted_orders
@@ -1,6 +1,6 @@
td.user-info.show-for-large-up
each user in view.content.users
= user.facebook_image_tag
= user.avatar_tag
td.status-icons
if view.content.needs_help
span.icon.needs-help
@@ -1,6 +1,6 @@
td.user-info.show-for-large-up
each user in view.content.list.users
= user.facebook_image_tag
= user.avatar_tag
td.status-icons
if view.content.active
span.active-order.fa.fa-check.fa-lg
@@ -14,7 +14,7 @@ table.table
tr
td
each user in order.list.users
= user.facebook_image_tag
= user.avatar_tag
td.status-icons
if order.active
span.active-order.fa.fa-check.fa-lg
@@ -18,7 +18,7 @@ if table.active_list
/.table-action-row
a{action "editTable" table}: span.fa.fa-lg.fa-wrench
each user in table.active_list.users
= user.facebook_image_tag
= user.avatar_tag
if editmodedisabled
.table-settings
select
@@ -1,12 +1,3 @@
#FB.init appId: '168928633304849'
#Ember.Application.initializer
#name: 'authentication',
#initialize: (container, application)->
## register the Facebook authenticator so the session can find it
#container.register 'authenticators:facebook', App.FacebookAuthenticator
#Ember.SimpleAuth.setup(container, application)
@App = Ember.Application.create
LOG_TRANSITIONS: true
rootElement: '#ember-app-container'
@@ -1,18 +1,13 @@
attr = DS.attr
App.User = DS.Model.extend
facebook_id: attr('string')
email: attr('string')
name: attr('string')
uid: attr('string')
provider: attr('string')
avatar: attr('string')
list: DS.belongsTo('list') # in ember scope not many to many (yet)
join_requests: DS.hasMany('join_request')
facebook_image_tag: (->
facebook_id = @get('facebook_id')
return '' unless facebook_id
<% if Rails.env.test? %>
url = ""
<% else %>
url = "http://graph.facebook.com/#{facebook_id}/picture?type=square"
<% end %>
avatar_tag: (->
return unless avatar = @get('avatar')
name = @get('name')
new Handlebars.SafeString "<img src=\"#{url}\" alt=\"#{name}\" title=\"#{name}\" class=\"user-facebook-image\">"
).property('facebook_id', 'name')
"<img src='#{avatar}' alt='#{name}' title='#{name}' class='user-avatar-image #{@get('provider')}'>".htmlSafe()
).property('avatar', 'name')
@@ -1,5 +1,5 @@
each user in list.users
img.facebook-image src="http://graph.facebook.com/#{unbound user.facebook_id}/picture?type=square" alt="f"
user.avatar_tag
.display-row
.display-label=t 'attributes.list.created_at'
.display-field=time list.created_at
@@ -2,8 +2,8 @@
h2= t 'join_request.existing_user.title'
each join_request in join_requests
.join-request-container
= join_request.user.facebook_image_tag
span.user-email= join_request.user.email
= join_request.user.avatar_tag
span.user-name= join_request.user.name
.right
button.join-request-reject{action "rejectRequest" join_request}=t 'join_request.existing_user.reject_request'
button.join-request-approve{action "approveRequest" join_request}=t 'join_request.existing_user.approve_request'
@@ -67,6 +67,7 @@ $primary-color: #008349
// $secondary-color: #e7e7e7;
$secondary-color: #d7d7d7
//$alert-color: #f04124;
$alert-color: #ee3e41
// $success-color: #43AC6A;
// $warning-color: #f08a24;
// $info-color: #a0d3e8;
@@ -1,7 +1,5 @@
//$qbrown: #634227
$qbrown: #853d15
$qbrown-active: lighten($qbrown, 20%)
$green: #7BB459 //Heineken
//$wood: image-url('textures/wood001-vertical.jpg')
$wood: image-url('textures/theme1.jpg')
$background-brown: #57351f
@@ -4,7 +4,7 @@ header.top-menu
background-repeat: no-repeat, no-repeat
background-position: left bottom, right bottom
background-image: image-url('theme1/button-bar-left.png'), image-url('theme1/button-bar-right.png')
color: $green
color: $primary-color
padding-left: 48px
padding-right: 52px
.menu-content
@@ -1,10 +1,4 @@
//$qbrown: #634227
$qbrown: #853d15
$qbrown-active: lighten($qbrown, 20%)
$green: #7BB459 //Heineken
//$wood: image-url('textures/wood001-vertical.jpg')
$wood: image-url('theme1/wall-bg.jpg')
$background-brown: #57351f
$current-color: #fc3
$active-color: #f70
$top-menu-height: 76px
@@ -1,5 +1,5 @@
.join-request-container
.user-email
.user-name
padding-left: 12px
.join-request-reject
+button($bg: $secondary-color)
@@ -9,7 +9,7 @@
background-image: image-url('theme1/wall-bg.jpg')
height: $top-menu-height
.top-menu-bar
color: $green
color: $primary-color
height: $top-menu-height
background-image: image-url('theme1/button-bar-left.png'), image-url('theme1/button-bar-right.png')
background-color: transparent
@@ -59,9 +59,11 @@
// We use these as default colors throughout
// $primary-color: #008CBA;
$primary-color: green
// $primary-color: green
$primary-color: #008349
// $secondary-color: #e7e7e7;
$secondary-color: #d7d7d7
$alert-color: #ee3e41
// $alert-color: #f04124;
// $success-color: #43AC6A;
// $warning-color: #f08a24;
@@ -7,22 +7,24 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
end
def facebook
@user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)
@user = User.find_for_oauth(request.env["omniauth.auth"], current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => @user.provider.to_s.capitalize
sign_in @user
#redirect_to user_root_path, :event => :authentication, :current_user => @user # infinite loop
redirect_to user_obtain_token_path, :event => :authentication, :current_user => @user
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
Rails.logger.error("Failed to persist user: #{@user.errors.full_messages.join(', ')}")
#TAG: facebook
# redirect_to new_user_registration_url
redirect_to '/'
end
end
def instagram
facebook # same same
end
def failure(env = {})
#binding.pry
show_404
+23 -4
View File
@@ -13,7 +13,7 @@ class User
property :oauth_expires_at
property :auth_data
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :omniauthable, :omniauth_providers => [:facebook] #, :token_authenticatable , :registerable
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :omniauthable, :omniauth_providers => [:facebook, :instagram] #, :token_authenticatable , :registerable
property :authentication_token
@@ -28,10 +28,11 @@ class User
view :by_authentication_token, key: :authentication_token
view :by_email, key: :email
view :by_facebook, key: [:provider, :uid]
view :by_facebook, key: [:provider, :uid] #DEPRICATE on successful change to by_provider
view :by_provider, key: [:provider, :uid]
def self.find_for_facebook_oauth(auth_data, user)
user = database.view(self.by_facebook(key: [auth_data.provider, auth_data.uid], limit: 1)).first
def self.find_for_oauth(auth_data, user)
user = database.view(self.by_provider(key: [auth_data.provider, auth_data.uid], limit: 1)).first
user || create(
provider: auth_data.provider,
@@ -49,6 +50,24 @@ class User
uid
end
def provider_info
case provider.to_sym
when :facebook then {}
when :instagram
uri = URI.parse("https://api.instagram.com/v1/users/#{uid}?access_token=#{auth_data['credentials']['token']}")
JSON.parse(Net::HTTP.get(uri)) rescue {ok: false, error: 'cannot_parse_response'}
else
{ok: false, error: 'provider_unknown'}
end
end
def avatar
case provider.to_sym
when :facebook then "http://graph.facebook.com/#{uid}/picture?type=square"
when :instagram then auth_data['info'].try(:[], 'image')
end
end
def self.from_omniauth(auth)
#binding.pry
end
+1 -1
View File
@@ -1,6 +1,6 @@
class SupplierUserSerializer < Qwaiter::Serializer
self.root = :user
attributes :email, :facebook_id, :name
attributes :email, :provider, :uid, :name, :avatar
def name
object.supplier_name
+1 -1
View File
@@ -1,6 +1,6 @@
class UserUserSerializer < Qwaiter::Serializer
self.root = :user
attributes :email, :facebook_id, :name
attributes :email, :provider, :uid, :name, :avatar
def name
object.friends_name
+2
View File
@@ -239,9 +239,11 @@ Devise.setup do |config|
# scope: 'email,user_birthday,publish_stream'
config.omniauth :facebook, "653729178057509", "d4cea86f70803f1b75ed03c506a4d78e",
scope: 'email,user_birthday,publish_stream'
config.omniauth :instagram, "cd7bdfbee825499b94fb3783d1bc143b", "6b4f9ecf251c462993a696eebc0189be"
else
config.omniauth :facebook, "168928633304849", "22bc53e1a390c1e62d004195c55fe336",
scope: 'email,user_birthday,publish_stream'
config.omniauth :instagram, "81c78b969a7046d6b6b5b5fe3f30929c", "3697c16762ad4f1ca088e829efbaddde"
end
# ==> Warden configuration
+1 -1
View File
@@ -29,7 +29,7 @@ step "the user should be redirected to the archived list path" do
end
step 'there is another user' do
@other_user ||= create :user
@other_user ||= create :user, :other_auth
end
step "the other user clicks the join table button" do
@@ -4,7 +4,7 @@ step "the original user should see a join request message" do
request_title = page.evaluate_script(%|t('join_request.existing_user.title')|)
request_title.should be_present
page.should have_content request_title
page.should have_content @other_user.email
page.should have_content "UOther" # spec/factories/user
end
step "the original user should not see the join request anymore" do
+14
View File
@@ -2,5 +2,19 @@ FactoryGirl.define do
factory :user do
sequence( :email ){|i| "test#{i}@example.com" }
password "secret"
trait :other_auth do
auth_data( {
'info' => {
'nickname' => "UOther",
"name" => "USR Other",
"first_name" => "Usother"
},
"credentials" => {
"token" => "fbAuthToken234",
'expires' => false
}
})
end
end
end
+4
View File
@@ -56,6 +56,10 @@ class TestCounter < InMemoryQCounter
#end
end
# No external images in test suite... slow....
User.send(:define_method, :avatar, ->{})
if defined?(Couchbase)
class Couchbase::View
alias :old_initialize :initialize
+5 -2
View File
@@ -18,6 +18,8 @@ User
- test met veel producten
- product variants
- remove active orders on list close
- Explanation page before opening facebook login
- Add instagram login
Bugs
----
@@ -28,8 +30,9 @@ Bugs
General
-------
- split off faye server
- split off counter server
- split off faye server (really low)
- split off counter server (really low)
- Loading pages
Post release
============