This repository has been archived by the owner on Jan 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
149 additions
and
247 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class HomeController < ApplicationController | ||
def index | ||
end | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,28 @@ | ||
class SessionsController < ApplicationController | ||
def callback | ||
def old_callback | ||
auth # Do what you want with the auth hash! | ||
end | ||
|
||
def callback | ||
if user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) | ||
user.update_with_meetup(auth) | ||
user.save! | ||
else | ||
user = User.create_with_meetup(auth) | ||
end | ||
session[:user_id] = user.id | ||
redirect_to root_url, :notice => "Signed in!" | ||
end | ||
|
||
def destroy | ||
session[:user_id] = nil | ||
redirect_to root_url, :notice => "Signed out!" | ||
end | ||
|
||
def failure | ||
raise auth.to_yaml | ||
redirect_to root_url, :error => "Failed to authenticate: #{params[:message]}" | ||
end | ||
|
||
def auth; request.env['omniauth.auth'] end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module HomeHelper | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
class User < ActiveRecord::Base | ||
def self.create_with_meetup(auth) | ||
user = create! do |user| | ||
user.provider = auth["provider"] | ||
user.uid = auth["uid"] | ||
user.update_with_omniauth(auth) | ||
end | ||
end | ||
|
||
# Sets User attributes based on omniauth/meetup.com fields | ||
# NOTE: does not save the record | ||
def update_with_meetup(auth) | ||
self.name = auth["user_info"]["name"] | ||
self.location = auth["user_info"]["location"] | ||
self.image_url = auth["user_info"]["image"] | ||
self.profile_url = auth["user_info"]["urls"]["profile"] | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
%h1 Home#index | ||
%p Find me in app/views/home/index.html.haml |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
if Rails.env.production? | ||
provider :meetup, '5bh4rgdj9937o65aoeots5n2ro', '8eoeuefatomrhfjsk90k15ghlf' # http://awards.svruby.com | ||
else | ||
provider :meetup, 'jr86pidmke1mr51ldq491oepln', 'd07p50nq5j4h9r0l58jc1hfoqn' # http://svruby-awards.dev | ||
end | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class AddFieldsToUsers < ActiveRecord::Migration | ||
def self.up | ||
add_column :users, :image_url, :string | ||
add_column :users, :location, :string | ||
add_column :users, :profile_url, :string | ||
end | ||
|
||
def self.down | ||
remove_column :users, :profile_url | ||
remove_column :users, :location | ||
remove_column :users, :image_url | ||
end | ||
end |
This file contains 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
Oops, something went wrong.