Created
April 17, 2013 02:20
-
-
Save amscotti/5401306 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jQuery(function($) { | |
| function gotAssertion(assertion) { | |
| // got an assertion, now send it up to the server for verification | |
| if (assertion !== null) { | |
| $.ajax({ | |
| type: 'POST', | |
| url: '/auth/login', | |
| data: { assertion: assertion }, | |
| success: function(res, status, xhr) { | |
| window.location.reload(); | |
| }, | |
| error: function(res, status, xhr) { | |
| alert("login failure" + res); | |
| } | |
| }); | |
| } | |
| }; | |
| $('#browserid').click(function() { | |
| navigator.id.get(gotAssertion); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "rubygems" | |
| require "haml" | |
| require "sinatra" | |
| require 'nestful' | |
| require 'digest/md5' | |
| enable :sessions | |
| helpers do | |
| def login? | |
| return !session[:email].nil? | |
| end | |
| def getGravatarURL | |
| return "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(session[:email].strip.downcase)}" | |
| end | |
| end | |
| get "/" do | |
| haml :index | |
| end | |
| post "/auth/login" do | |
| if params[:assertion] | |
| data = Nestful.post "https://browserid.org/verify", :format => :json, :params => { :assertion => "#{params[:assertion]}", :audience => "http://#{request.host}:#{request.port}" } | |
| if data["status"] == "okay" | |
| session[:email] = data["email"] | |
| return data.to_json | |
| end | |
| end | |
| return {:status => "error"}.to_json | |
| end | |
| get "/auth/logout" do | |
| session[:email] = nil | |
| redirect "/" | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -if login? | |
| %p="Welcome #{session[:email]}!" | |
| #avatar | |
| %img{:src => getGravatarURL, :alt => "Gravatar"} | |
| %a{:href => "/auth/logout", :title => "Sign-out"} Sign-out | |
| -else | |
| %a#browserid{:href => "#", :title=>"Sign-in with BrowserID"} | |
| %img{:src=> "/images/sign_in_blue.png", :alt=>"Sign-in with BrowserID"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment