Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Meetup login

  • Loading branch information...
commit 3fcc11b9f5f2913dbc57a71fdc7ad42819425aea 1 parent 102d039
@jarthod jarthod authored
View
2  Gemfile
@@ -34,6 +34,8 @@ gem 'activeadmin'
gem 'rails-i18n'
+gem 'omniauth-meetup'
+
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
View
23 Gemfile.lock
@@ -93,6 +93,8 @@ GEM
eventmachine (1.0.0)
execjs (1.4.0)
multi_json (~> 1.0)
+ faraday (0.8.5)
+ multipart-post (~> 1.1)
fastercsv (1.5.5)
ffi (1.1.5)
formtastic (2.2.1)
@@ -102,7 +104,9 @@ GEM
json (>= 1.4.6)
haml (3.1.7)
has_scope (0.5.1)
+ hashie (1.2.0)
hike (1.2.1)
+ httpauth (0.2.0)
i18n (0.6.1)
inherited_resources (1.3.1)
has_scope (~> 0.5.0)
@@ -112,6 +116,8 @@ GEM
railties (>= 3.1.0, < 5.0)
thor (~> 0.14)
json (1.7.6)
+ jwt (0.1.5)
+ multi_json (>= 1.0)
kaminari (0.14.1)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
@@ -130,8 +136,24 @@ GEM
polyamorous (~> 0.5.0)
mime-types (1.19)
multi_json (1.5.0)
+ multipart-post (1.1.5)
newrelic_rpm (3.5.5.38)
nokogiri (1.5.5)
+ oauth2 (0.8.0)
+ faraday (~> 0.8)
+ httpauth (~> 0.1)
+ jwt (~> 0.1.4)
+ multi_json (~> 1.0)
+ rack (~> 1.2)
+ omniauth (1.1.2)
+ hashie (~> 1.2)
+ rack
+ omniauth-meetup (0.0.6)
+ omniauth (~> 1.0)
+ omniauth-oauth2 (~> 1.0)
+ omniauth-oauth2 (1.1.1)
+ oauth2 (~> 0.8.0)
+ omniauth (~> 1.0)
orm_adapter (0.4.0)
pg (0.14.1)
polyamorous (0.5.0)
@@ -238,6 +260,7 @@ DEPENDENCIES
jquery-rails
launchy
newrelic_rpm
+ omniauth-meetup
pg
rails
rails-i18n
View
11 README.md
@@ -1,5 +1,16 @@
# Présentations ([Ruby Paris](http://www.rubyparis.org)) [![Build Status](https://travis-ci.org/tibastral/presentations.png?branch=master)](https://travis-ci.org/tibastral/presentations)
+## Meetup
+
+Add the meetup keys in `config/initializers/omniauth`
+
+```ruby
+ Rails.application.config.middleware.use OmniAuth::Builder do
+ provider :meetup, ENV['MEETUP_KEY'], ENV['MEETUP_SECRET']
+ # provider :meetup, 'MEETUP_KEY, MEETUP_SECRET if not a env var
+ end
+```
+
## Contributing
1. Fork it
View
8 app/controllers/application_controller.rb
@@ -1,3 +1,11 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+
+ helper_method :current_user
+
+ private
+
+ def current_user
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
+ end
end
View
17 app/controllers/sessions_controller.rb
@@ -0,0 +1,17 @@
+# encoding: utf-8
+
+class SessionsController < ApplicationController
+
+ def create
+ auth = request.env["omniauth.auth"]
+ user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
+ session[:user_id] = user.id
+ redirect_to root_url, :notice => "Authentification réussie !"
+ end
+
+ def destroy
+ session[:user_id] = nil
+ redirect_to root_url, :notice => "A bientôt !"
+ end
+
+end
View
12 app/models/user.rb
@@ -0,0 +1,12 @@
+class User < ActiveRecord::Base
+
+ def self.create_with_omniauth(auth)
+ create! do |user|
+ user.provider = auth["provider"]
+ user.uid = auth["uid"]
+ user.name = auth["info"]["name"]
+ user.link = auth["extra"]["raw_info"]["link"]
+ end
+ end
+
+end
View
5 app/views/layouts/_session.html.haml
@@ -0,0 +1,5 @@
+- if current_user
+ .auth= link_to current_user.name, current_user.link
+ .logout= link_to "Se déconnecter", signout_path
+- else
+ .auth= link_to "S'identifier !", "/auth/meetup"
View
3  app/views/layouts/application.html.haml
@@ -1,7 +1,7 @@
!!! 5
%html
%head
- %title Appel À Presentations
+ %title= [@title, "Paris.rb : Apéro Ruby à Paris"].compact.join(' | ')
= stylesheet_link_tag "application"
= javascript_include_tag "application"
%meta{"content" => 'text/html; charset=utf-8', "http-equiv" => 'Content-Type'}
@@ -11,6 +11,7 @@
%body
= github_banner
.wrapper
+ = render 'layouts/session'
- if notice
.flash.notice= notice
= yield
View
3  config/initializers/omniauth.rb
@@ -0,0 +1,3 @@
+Rails.application.config.middleware.use OmniAuth::Builder do
+ provider :meetup, ENV['MEETUP_KEY'], ENV['MEETUP_SECRET']
+end
View
55 config/routes.rb
@@ -4,60 +4,9 @@
devise_for :admin_users, ActiveAdmin::Devise.config
resources :presentations
- # The priority is based upon order of creation:
- # first created -> highest priority.
+ match "/auth/meetup/callback" => "sessions#create"
+ match "/signout" => "sessions#destroy", :as => :signout
- # Sample of regular route:
- # match 'products/:id' => 'catalog#view'
- # Keep in mind you can assign values other than :controller and :action
-
- # Sample of named route:
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
- # This route can be invoked with purchase_url(:id => product.id)
-
- # Sample resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Sample resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Sample resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Sample resource route with more complex sub-resources
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', :on => :collection
- # end
- # end
-
- # Sample resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
-
- # You can have the root of your site routed with "root"
- # just remember to delete public/index.html.
root :to => 'presentations#new'
- # See how all your routes lay out with "rake routes"
-
- # This is a legacy wild controller route that's not recommended for RESTful applications.
- # Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id(.:format)))'
end
View
11 db/migrate/20130212095045_create_users.rb
@@ -0,0 +1,11 @@
+class CreateUsers < ActiveRecord::Migration
+ def change
+ create_table :users do |t|
+ t.string :provider
+ t.string :uid
+ t.string :name
+ t.string :link
+ t.timestamps
+ end
+ end
+end
View
11 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121206120910) do
+ActiveRecord::Schema.define(:version => 20130212095045) do
create_table "active_admin_comments", :force => true do |t|
t.string "resource_id", :null => false
@@ -77,4 +77,13 @@
t.datetime "updated_at", :null => false
end
+ create_table "users", :force => true do |t|
+ t.string "provider"
+ t.string "uid"
+ t.string "name"
+ t.string "link"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.