Skip to content

Commit

Permalink
Create and integrate omniauth 🆒
Browse files Browse the repository at this point in the history
  • Loading branch information
shiroginne committed Mar 22, 2012
0 parents commit 02c1bd6
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Gemfile
@@ -0,0 +1,7 @@
source 'https://rubygems.org'
gem 'thin'
gem 'sinatra', :require => 'sinatra/base'
gem 'omniauth'
gem 'omniauth-github'
gem 'slim'
gem 'mongoid'
68 changes: 68 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,68 @@
GEM
remote: https://rubygems.org/
specs:
activemodel (3.2.2)
activesupport (= 3.2.2)
builder (~> 3.0.0)
activesupport (3.2.2)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.2.7)
bson (1.6.1)
builder (3.0.0)
daemons (1.1.8)
eventmachine (0.12.10)
faraday (0.7.6)
addressable (~> 2.2)
multipart-post (~> 1.1)
rack (~> 1.1)
hashie (1.2.0)
i18n (0.6.0)
mongo (1.6.1)
bson (~> 1.6.1)
mongoid (2.4.7)
activemodel (~> 3.1)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
multi_json (1.1.0)
multipart-post (1.1.5)
oauth2 (0.5.2)
faraday (~> 0.7)
multi_json (~> 1.0)
omniauth (1.0.3)
hashie (~> 1.2)
rack
omniauth-github (1.0.1)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.0)
omniauth-oauth2 (1.0.0)
oauth2 (~> 0.5.0)
omniauth (~> 1.0)
rack (1.4.1)
rack-protection (1.1.4)
rack
sinatra (1.3.1)
rack (~> 1.3, >= 1.3.4)
rack-protection (~> 1.1, >= 1.1.2)
tilt (~> 1.3, >= 1.3.3)
slim (1.1.1)
temple (~> 0.4.0)
tilt (~> 1.3.2)
temple (0.4.0)
thin (1.3.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
tilt (1.3.3)
tzinfo (0.3.32)

PLATFORMS
ruby

DEPENDENCIES
mongoid
omniauth
omniauth-github
sinatra
slim
thin
8 changes: 8 additions & 0 deletions app/models/hacker.rb
@@ -0,0 +1,8 @@
class Hacker
include Mongoid::Document

field :uid, type: String
field :name, type: String
field :email, type: String

end
Empty file added app/models/target.rb
Empty file.
7 changes: 7 additions & 0 deletions app/views/home.slim
@@ -0,0 +1,7 @@
h1 "You bro, #{Hacker.last.try(:name)}"
a href='/auth/github'
| Sign in with github

h2 Bros =>
- Hacker.all.each do |hack|
img src="#{gravatar(hack.try(:email))}"
11 changes: 11 additions & 0 deletions config.ru
@@ -0,0 +1,11 @@
require 'rubygems'
require 'bundler'
require 'yaml'
require 'digest'

Bundler.require

require './core'
require './app/models/hacker'
require './app/models/target'
run Core
4 changes: 4 additions & 0 deletions config/mongoid.yml
@@ -0,0 +1,4 @@
development:
host: localhost
database: bro_development

34 changes: 34 additions & 0 deletions core.rb
@@ -0,0 +1,34 @@
class Core < Sinatra::Base
GITHUB = YAML.load_file(File.join(settings.root, 'config/github_key.yml'))
Mongoid.load!(File.join(settings.root, 'config/mongoid.yml'))

set :views, settings.root + '/app/views'
set :slim, :pretty => true

use Rack::Session::Cookie
use OmniAuth::Builder do
provider :github, GITHUB['id'], GITHUB['secret']
end

helpers do
def gravatar email
"http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}" if email
end
end

get '/' do
slim :home
end

get '/auth/failure' do
"Not cool, bro"
end

get '/auth/github/callback' do
Hacker.find_or_create_by(uid: request.env['omniauth.auth']['uid'],
name: request.env['omniauth.auth']['info']['nickname'],
email: request.env['omniauth.auth']['info']['email'])
redirect '/'
end

end

0 comments on commit 02c1bd6

Please sign in to comment.