Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done #1083

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Done #1083

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.sqlite3
*.log
tmp/Gemfile.lock
.env
tmp/Gemfile.lock
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ gem 'turbolinks'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

gem 'omniauth'

gem 'omniauth-facebook'

gem 'dotenv-rails'


group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
Expand Down
80 changes: 54 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,46 +39,71 @@ GEM
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (7.1.4)
builder (3.2.3)
byebug (11.0.1)
coderay (1.1.2)
builder (3.2.4)
byebug (11.1.3)
coderay (1.1.3)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.1.x)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.1.5)
crass (1.0.5)
concurrent-ruby (1.1.7)
crass (1.0.6)
daemons (1.3.1)
dotenv (2.7.6)
dotenv-rails (2.7.6)
dotenv (= 2.7.6)
railties (>= 3.2)
erubis (2.7.0)
eventmachine (1.2.7)
execjs (2.7.0)
ffi (1.11.1)
faraday (1.0.1)
multipart-post (>= 1.2, < 3)
ffi (1.13.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.6.0)
hashie (4.1.0)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
jquery-rails (4.3.5)
jquery-rails (4.4.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
loofah (2.3.1)
jwt (2.2.1)
loofah (2.6.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
method_source (0.9.2)
method_source (1.0.0)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.11.3)
nio4r (2.4.0)
nokogiri (1.10.8)
minitest (5.14.1)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.1.1)
nio4r (2.5.2)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
oauth2 (1.4.4)
faraday (>= 0.8, < 2.0)
jwt (>= 1.0, < 3.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
omniauth (1.9.1)
hashie (>= 3.4.6)
rack (>= 1.6.2, < 3)
omniauth-facebook (6.0.0)
omniauth-oauth2 (~> 1.2)
omniauth-oauth2 (1.7.0)
oauth2 (~> 1.4)
omniauth (~> 1.9)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
rack (2.2.3)
rack-test (0.6.3)
rack (>= 1.0)
Expand All @@ -97,17 +122,17 @@ GEM
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (5.0.7.2)
actionpack (= 5.0.7.2)
activesupport (= 5.0.7.2)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.3.3)
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
rake (13.0.1)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
sass (3.7.4)
sass-listen (~> 4.0.0)
Expand All @@ -133,15 +158,15 @@ GEM
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thor (0.20.3)
thor (1.0.1)
thread_safe (0.3.6)
tilt (2.0.9)
turbolinks (5.2.0)
tilt (2.0.10)
turbolinks (5.2.1)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
tzinfo (1.2.5)
tzinfo (1.2.7)
thread_safe (~> 0.1)
uglifier (4.1.20)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
Expand All @@ -153,7 +178,10 @@ PLATFORMS
DEPENDENCIES
byebug
coffee-rails (~> 4.1.0)
dotenv-rails
jquery-rails
omniauth
omniauth-facebook
pry
rails (~> 5.0)
sass-rails (~> 5.0)
Expand Down
19 changes: 19 additions & 0 deletions app/controllers/session_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class SessionsController < ApplicationController
def create
@user = User.find_or_create_by(uid: auth['uid']) do |u|
u.name = auth['info']['name']
u.email = auth['info']['email']
u.image = auth['info']['image']
end

session[:user_id] = @user.id

render 'welcome/home'
end

private

def auth
request.env['omniauth.auth']
end
end
3 changes: 3 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class User < ApplicationRecord
end
8 changes: 8 additions & 0 deletions app/views/welcome/home.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
<%# Add the Facebook login link here %>
<% if session[:user_id] %>
<h1><%= @user.name %></h1>
<h2>Email: <%= @user.email %></h2>
<h2>Facebook UID: <%= @user.uid %></h2>
<img src="<%= @user.image %>">
<% else %>
<%= link_to('Log in with Facebook!', '/auth/facebook') %>
<% end %>
4 changes: 4 additions & 0 deletions config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Rails.application.config.middleware.use OmniAuth::Builder do
# tells rails app to use a piece of middleware created by OmniAuth for the Facebook authentication strategy
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET']
end
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Rails.application.routes.draw do
root 'welcome#home'

get '/auth/:provider/callback', to: 'sessions#create'
post '/auth/:provider/callback', to: 'sessions#create'

# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20200806042701_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateUsers < ActiveRecord::Migration[5.0]
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :image
t.string :uid

t.timestamps
end
end
end
12 changes: 10 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
Expand All @@ -11,6 +10,15 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 0) do
ActiveRecord::Schema.define(version: 20200806042701) do

create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
t.string "image"
t.string "uid"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

end
13 changes: 13 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
name: MyString
email: MyString
image: MyString
uid: MyString

two:
name: MyString
email: MyString
image: MyString
uid: MyString
7 changes: 7 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I"�app/assets/javascripts/application.js?type=application/javascript&pipeline=debug&id=8a33d64b37407201f09c083774635e2a45452d75c8a5f6927b27d5c4a42b6129:ET
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%��B�����șo�$'�A�d��L���xR�U
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%����`���/F� �� ���Y(}H�R�
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I"}app/assets/stylesheets/application.css?type=text/css&id=4af2d6625018d767851f00bb9d4c87d26dcdd74e556009c38fdf94a0b3853fa6:ET
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I"�app/assets/javascripts/application.js?type=application/javascript&pipeline=self&id=1fd309c1109733a31dea74508e498ab0291acc382b020f78c797b7519075cb0c:ET
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%xJ�g&k��"��U���m��X�V�;Fj
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%ó�n���x���|��b�[ģ��Y��xF�
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%����`���/F� �� ���Y(}H�R�
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%Ѱč@�����6H�uZoX�Z�gbh0W��V
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%C6������ܦ�M=��Qu���/�,"c�5u
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%��Rm�v�S3.��O�L���ڹc�ƕq�=_j�
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%����`���/F� �� ���Y(}H�R�
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%C6������ܦ�M=��Qu���/�,"c�5u
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%uW��l��j��Z� xU��>�?]��pc��s
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%�d�-�K���`���8Y��3�͹/Y����a~K
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I"�app/assets/stylesheets/application.css?type=text/css&pipeline=debug&id=0f6a01b5cd81677be3ac1aaf9c51975ba70f662568f20dfe1f885803b4bd4c7c:ET
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[o:Set:
@hash}
I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"mfile-digest:///usr/local/rvm/gems/ruby-2.6.1/gems/jquery-rails-4.4.0/vendor/assets/javascripts/jquery.js;TTF
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%uW��l��j��Z� xU��>�?]��pc��s
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I"�app/assets/javascripts/application.js?type=application/javascript&id=08ecf13bcb4514b939a455bd54558ea30195b9adafaf034b4c4feefb81e7c073:ET
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%uW��l��j��Z� xU��>�?]��pc��s
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%uW��l��j��Z� xU��>�?]��pc��s
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I"�/usr/local/rvm/gems/ruby-2.6.1/gems/turbolinks-source-5.2.0/lib/assets/javascripts/turbolinks.js?type=application/javascript&pipeline=self&id=0e4efb83233dccd84e349e54906d3aa592358aaf576bffe4ba502a39fd7ffd72:ET
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%��Rm�v�S3.��O�L���ڹc�ƕq�=_j�
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I"�app/assets/javascripts/application.js?type=application/javascript&pipeline=debug&id=aa4751cecdf045a09f645cfdf8fbd3449cda7cf8c089e03ba8c15231be128b65:ET
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I"�/usr/local/rvm/gems/ruby-2.6.1/gems/jquery-rails-4.4.0/vendor/assets/javascripts/jquery_ujs.js?type=application/javascript&pipeline=self&id=e3d32c323276bb5fe26e0056b10732d3748e2065ec867ecc075e710738ce0784:ET
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%C6������ܦ�M=��Qu���/�,"c�5u
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I"�/usr/local/rvm/gems/ruby-2.6.1/gems/turbolinks-source-5.2.0/lib/assets/javascripts/turbolinks.js?type=application/javascript&pipeline=self&id=f8b8976e34742cff6683a3a6ba3b3867b8f5a3a76aaf433e3e3cc9e4d9b27369:ET
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%xJ�g&k��"��U���m��X�V�;Fj
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%��Rm�v�S3.��O�L���ڹc�ƕq�=_j�
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%��Rm�v�S3.��O�L���ڹc�ƕq�=_j�
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%C6������ܦ�M=��Qu���/�,"c�5u
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%�d�-�K���`���8Y��3�͹/Y����a~K
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%xJ�g&k��"��U���m��X�V�;Fj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I"�app/assets/javascripts/application.js?type=application/javascript&id=4092888f06391caeeec077519c1ccbd6de41bb7ee2e1b0f39a901893d70859c6:ET
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%�~��2%�a�5�p���L�Je5�-,$�o\2
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%��B�����șo�$'�A�d��L���xR�U
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I"�/usr/local/rvm/gems/ruby-2.6.1/gems/jquery-rails-4.4.0/vendor/assets/javascripts/jquery.js?type=application/javascript&pipeline=self&id=bbf38565fb9004fb6cd27ce6055728e7b75565c059b9fde2d7fada0bcff9e5cf:ET
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%xJ�g&k��"��U���m��X�V�;Fj
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%Ѱč@�����6H�uZoX�Z�gbh0W��V
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%��B�����șo�$'�A�d��L���xR�U
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%C6������ܦ�M=��Qu���/�,"c�5u
Loading