Skip to content

Commit

Permalink
added favicon, layout
Browse files Browse the repository at this point in the history
  • Loading branch information
richardvanhook committed May 15, 2012
1 parent c2f3857 commit 4e26290
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 93 deletions.
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ source :rubygems
gem "sinatra"
gem "thin"
gem "rack-ssl"
gem "encrypted_cookie"
gem "haml"
gem "omniauth"
gem "omniauth-salesforce", ">=1.0.3"
gem "omniauth-salesforce"

group :development do
gem "wirble"
gem "foreman"
gem "heroku"
gem "sqlite3"
end
6 changes: 1 addition & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ GEM
specs:
addressable (2.2.8)
daemons (1.1.4)
encrypted_cookie (0.0.4)
eventmachine (0.12.10)
faraday (0.8.0)
multipart-post (~> 1.1)
Expand Down Expand Up @@ -48,7 +47,6 @@ GEM
rack (~> 1.3, >= 1.3.4)
rack-protection (~> 1.1, >= 1.1.2)
tilt (~> 1.3, >= 1.3.3)
sqlite3 (1.3.6)
thin (1.3.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
Expand All @@ -61,14 +59,12 @@ PLATFORMS
ruby

DEPENDENCIES
encrypted_cookie
foreman
haml
heroku
omniauth
omniauth-salesforce (>= 1.0.3)
omniauth-salesforce
rack-ssl
sinatra
sqlite3
thin
wirble
27 changes: 18 additions & 9 deletions lib/app.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "sinatra/base"
require "encrypted_cookie"
require "rack/ssl" unless ENV['RACK_ENV'] == "development"
require "haml"
require "omniauth"
Expand All @@ -8,6 +7,7 @@
class OmniAuthSalesforceExample < Sinatra::Base

configure do
enable :logging
set :app_file, __FILE__
set :root, File.expand_path("../..",__FILE__)
set :port, ENV['PORT']
Expand All @@ -18,14 +18,15 @@ class OmniAuthSalesforceExample < Sinatra::Base
use Rack::SSL unless ENV['RACK_ENV'] == "development"
use Rack::Session::Pool

OmniAuth.config.on_failure do |env|
p "#{env['omniauth.error'].class.to_s}: #{env['omniauth.error'].message}"
p "code: #{env['omniauth.error'].code}"
p "response: #{env['omniauth.error'].response}"
env['omniauth.error'].backtrace.each{|b| p b}
p env['omniauth.error'].response.inspect if env['omniauth.error'].respond_to?(:response)
[302, {'Location' => '/auth/failure'}, ['302 Redirect']]
end
# OmniAuth.config.on_failure do |env|
# logger.info "loading data"
# logger.info "#{env['omniauth.error'].class.to_s}: #{env['omniauth.error'].message}"
# logger.info "code: #{env['omniauth.error'].code}"
# logger.info "response: #{env['omniauth.error'].response}"
# env['omniauth.error'].backtrace.each{|b| logger.info b}
# logger.info env['omniauth.error'].response.inspect if env['omniauth.error'].respond_to?(:response)
# [302, {'Location' => '/auth/failure'}, ['302 Redirect']]
# end

use OmniAuth::Builder do
provider :salesforce,
Expand All @@ -42,6 +43,10 @@ class OmniAuthSalesforceExample < Sinatra::Base
ENV['DATABASE_DOT_COM_SECRET']
end

before do
logger.info "hit: #{request.path_info}"
end

post '/authenticate' do
provider = sanitize_provider(params[:options]['provider'])
auth_params = {
Expand All @@ -63,6 +68,10 @@ class OmniAuthSalesforceExample < Sinatra::Base
redirect '/' unless session[:auth_hash] == nil
end

get '/error' do
haml :error, :locals => { :message => "Message goes here 123" }
end

get '/*' do
haml :index
end
Expand Down
Binary file added public/favicon.ico
Binary file not shown.
4 changes: 4 additions & 0 deletions views/error.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%div{:"data-role" => "header", :"data-theme" => "e"}
%h1 Error Occurred!
%div{:class => "ui-body ui-body-e"}
%p #{message}
129 changes: 53 additions & 76 deletions views/index.haml
Original file line number Diff line number Diff line change
@@ -1,76 +1,53 @@
!!! 5
%html{ :lang => "en"}
%head
%title= "omniauth-salesforce-example"
%meta{ :name => "viewport", :content => "width=device-width, initial-scale=1"}
%link{ :href => url("/jquery.mobile-1.1.0.css"), :media => "screen", :rel => "stylesheet", :type => "text/css" }
%script{ :src => url("/jquery-1.7.2.min.js")}
%script{ :src => url("/jquery.mobile-1.1.0.js")}
%body
%div{ :id => "foo", :"data-role" => "page", :"data-title" => "omniauth-salesforce-example"}
%div{ :"data-role" => "header"}
%h1 omniauth-salesforce-example
%div{ :"data-role" => "content"}
- if session[:auth_hash] == nil
%h3 You are NOT authenticated.
%a{:"data-role" => "button", :"data-ajax" => "false", :href => "#", :onclick => "document.authenticate_form.submit();"} Authenticate using your salesforce credentials
%form{:id => "authenticate_form", :name => "authenticate_form", :action => "/authenticate", :method => "post"}
%div{:class => "ui-body"}
%div{:"data-role" => "collapsible", :"data-collapsed" => "true", :"data-theme" => "b", :"data-content-theme" => "c"}
%h3 Authentication Options
%p
%div{:"data-role" => "fieldcontain"}
%fieldset{:"data-role" => "controlgroup"}
%legend Environment
%input{:type => "radio", :name => "options[provider]", :id => "options[provider]-1", :value => "salesforce", :checked => true}
%label{:for => "options[provider]-1"} production (login.salesforce.com)
%input{:type => "radio", :name => "options[provider]", :id => "options[provider]-2", :value => "salesforcesandbox"}
%label{:for => "options[provider]-2"} sandbox (test.salesforce.com)
%input{:type => "radio", :name => "options[provider]", :id => "options[provider]-3", :value => "salesforceprerelease"}
%label{:for => "options[provider]-3"} pre-release (prerellogin.pre.salesforce.com)
%input{:type => "radio", :name => "options[provider]", :id => "options[provider]-4", :value => "databasedotcom"}
%label{:for => "options[provider]-4"} database.com (login.database.com)
%div{:"data-role" => "fieldcontain"}
%fieldset{:"data-role" => "controlgroup"}
%legend Display
%input{:type => "radio", :name => "options[display]", :id => "options[display]-1", :value => "page", :checked => true}
%label{:for => "options[display]-1"} page: full-page authorization screen
%input{:type => "radio", :name => "options[display]", :id => "options[display]-2", :value => "popup"}
%label{:for => "options[display]-2"} popup: compact dialog optimized for modern web browser popup windows.
%input{:type => "radio", :name => "options[display]", :id => "options[display]-3", :value => "touch"}
%label{:for => "options[display]-3"} touch: mobile-optimized dialog designed for modern smartphones, such as Android and iPhone.
%fieldset{:"data-role" => "controlgroup"}
%legend Access Level
- default_scopes = Set.new(%w(api id refresh_token))
- %w(api chatter_api full id refresh_token visualforce web).each do |scope|
%input{:type => "checkbox", :name => "options[scope|#{scope}]", :id => "options[scope|#{scope}]", :class => "custom", :checked => default_scopes.include?(scope)}
%label{:for => "options[scope|#{scope}]"} #{scope}
%div{:"data-role" => "fieldcontain"}
%label{:for => "options[immediate]"} Immediate
%select{:id => "options[immediate]", :name => "options[immediate]", :"data-role" => "slider"}
%option{:value => "false"} No
%option{:value => "true"} Yes
- else
%h3 You've been authenticated as:
%div{:class => "ui-body"}
%img{:align => "left", :src => session[:auth_hash][:info][:image], :style => "margin-right: 12px"}
%strong #{session[:auth_hash][:info][:name]}
%br
#{session[:auth_hash][:extra][:username]}
%br
#{session[:auth_hash][:extra][:organization_id]}
%br
#{session[:auth_hash][:extra][:instance_url]}
%a{:"data-role" => "button", :"data-ajax" => "false", :href => "/unauthenticate"} Log out (from this app only, not salesforce.com)
%div{:class => "ui-body"}
= htmlize_hash("ENV['omniauth.auth']",session[:auth_hash])
%a{:href => "https://github.com/richardvanhook/omniauth-salesforce-example"}
%img{:style => "position: absolute; top: 0; right: 0; border: 0;", :src => "https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png", :alt => "Fork me on GitHub"}
:javascript
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
:javascript
try{
var pageTracker = _gat._getTracker("UA-31738053-1");
pageTracker._trackPageview();
} catch(err) {}
- if session[:auth_hash] == nil
%h3 You are NOT authenticated.
%a{:"data-role" => "button", :"data-ajax" => "false", :href => "#", :onclick => "document.authenticate_form.submit();"} Authenticate using your salesforce credentials
%form{:id => "authenticate_form", :name => "authenticate_form", :action => "/authenticate", :method => "post"}
%div{:class => "ui-body"}
%div{:"data-role" => "collapsible", :"data-collapsed" => "true", :"data-theme" => "b", :"data-content-theme" => "c"}
%h3 Authentication Options
%p
%div{:"data-role" => "fieldcontain"}
%fieldset{:"data-role" => "controlgroup"}
%legend Environment
%input{:type => "radio", :name => "options[provider]", :id => "options[provider]-1", :value => "salesforce", :checked => true}
%label{:for => "options[provider]-1"} production (login.salesforce.com)
%input{:type => "radio", :name => "options[provider]", :id => "options[provider]-2", :value => "salesforcesandbox"}
%label{:for => "options[provider]-2"} sandbox (test.salesforce.com)
%input{:type => "radio", :name => "options[provider]", :id => "options[provider]-3", :value => "salesforceprerelease"}
%label{:for => "options[provider]-3"} pre-release (prerellogin.pre.salesforce.com)
%input{:type => "radio", :name => "options[provider]", :id => "options[provider]-4", :value => "databasedotcom"}
%label{:for => "options[provider]-4"} database.com (login.database.com)
%div{:"data-role" => "fieldcontain"}
%fieldset{:"data-role" => "controlgroup"}
%legend Display
%input{:type => "radio", :name => "options[display]", :id => "options[display]-1", :value => "page", :checked => true}
%label{:for => "options[display]-1"} page: full-page authorization screen
%input{:type => "radio", :name => "options[display]", :id => "options[display]-2", :value => "popup"}
%label{:for => "options[display]-2"} popup: compact dialog optimized for modern web browser popup windows.
%input{:type => "radio", :name => "options[display]", :id => "options[display]-3", :value => "touch"}
%label{:for => "options[display]-3"} touch: mobile-optimized dialog designed for modern smartphones, such as Android and iPhone.
%fieldset{:"data-role" => "controlgroup"}
%legend Access Level
- default_scopes = Set.new(%w(api id refresh_token))
- %w(api chatter_api full id refresh_token visualforce web).each do |scope|
%input{:type => "checkbox", :name => "options[scope|#{scope}]", :id => "options[scope|#{scope}]", :class => "custom", :checked => default_scopes.include?(scope)}
%label{:for => "options[scope|#{scope}]"} #{scope}
%div{:"data-role" => "fieldcontain"}
%label{:for => "options[immediate]"} Immediate
%select{:id => "options[immediate]", :name => "options[immediate]", :"data-role" => "slider"}
%option{:value => "false"} No
%option{:value => "true"} Yes
- else
%h3 You've been authenticated as:
%div{:class => "ui-body"}
%img{:align => "left", :src => session[:auth_hash][:info][:image], :style => "margin-right: 12px"}
%strong #{session[:auth_hash][:info][:name]}
%br
#{session[:auth_hash][:extra][:username]}
%br
#{session[:auth_hash][:extra][:organization_id]}
%br
#{session[:auth_hash][:extra][:instance_url]}
%a{:"data-role" => "button", :"data-ajax" => "false", :href => "/unauthenticate"} Log out (from this app only, not salesforce.com)
%div{:class => "ui-body"}
= htmlize_hash("ENV['omniauth.auth']",session[:auth_hash])
24 changes: 24 additions & 0 deletions views/layout.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
!!! 5
%html{ :lang => "en"}
%head
%title= "omniauth salesforce example"
%meta{ :name => "viewport", :content => "width=device-width, initial-scale=1"}
%link{ :href => url("/jquery.mobile-1.1.0.css"), :media => "screen", :rel => "stylesheet", :type => "text/css" }
%script{ :src => url("/jquery-1.7.2.min.js")}
%script{ :src => url("/jquery.mobile-1.1.0.js")}
%body
#page{:"data-role" => "page", :"data-title" => "omniauth salesforce example"}
#header{ :"data-role" => "header"}
%h1 omniauth salesforce example
#content{ :"data-role" => "content"}
= yield
%a{:href => "https://github.com/richardvanhook/omniauth-salesforce-example"}
%img{:style => "position: absolute; top: 0; right: 0; border: 0;", :src => "https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png", :alt => "Fork me on GitHub"}
:javascript
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
:javascript
try{
var pageTracker = _gat._getTracker("UA-31738053-1");
pageTracker._trackPageview();
} catch(err) {}

0 comments on commit 4e26290

Please sign in to comment.