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,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'
@@ -66,7 +66,8 @@
$primary-color: #008349
// $secondary-color: #e7e7e7;
$secondary-color: #d7d7d7
// $alert-color: #f04124;
//$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