diff --git a/.gitignore b/.gitignore
index 7559b50b..64c671b9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,7 +16,8 @@
/tmp/*
!/log/.keep
!/tmp/.keep
+.env
# Ignore Byebug command history file.
.byebug_history
-.env
\ No newline at end of file
+.env
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 00000000..0fcc4a44
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,7 @@
+FROM ruby:2.3.1
+
+# app dependencies
+RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
+
+# app directory
+RUN mkdir /usr/src/app
diff --git a/Gemfile b/Gemfile
index 2c1ef168..084a990e 100644
--- a/Gemfile
+++ b/Gemfile
@@ -50,7 +50,6 @@ end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
-gem 'devise', '4.2.0'
gem 'omniauth', '1.3.1'
gem 'omniauth-twitter', '1.2.1'
gem 'omniauth-google-oauth2', '0.4.1'
diff --git a/Gemfile.lock b/Gemfile.lock
index 3a9be8f7..b24c67ff 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -39,7 +39,6 @@ GEM
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (7.1.4)
- bcrypt (3.1.11)
bigbluebutton-api-ruby (1.6.0)
xml-simple (~> 1.1)
bootstrap-sass (3.3.0.0)
@@ -57,12 +56,6 @@ GEM
coffee-script-source (1.10.0)
concurrent-ruby (1.0.2)
debug_inspector (0.0.2)
- devise (4.2.0)
- bcrypt (~> 3.0)
- orm_adapter (~> 0.1)
- railties (>= 4.1.0, < 5.1)
- responders
- warden (~> 1.2.3)
dotenv (2.1.1)
dotenv-rails (2.1.1)
dotenv (= 2.1.1)
@@ -135,7 +128,6 @@ GEM
omniauth-twitter (1.2.1)
json (~> 1.3)
omniauth-oauth (~> 1.1)
- orm_adapter (0.5.0)
puma (3.6.0)
rack (2.0.1)
rack-test (0.6.3)
@@ -167,8 +159,6 @@ GEM
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
- responders (2.3.0)
- railties (>= 4.2.0, < 5.1)
sass (3.4.22)
sass-rails (5.0.6)
railties (>= 4.0.0, < 6)
@@ -199,8 +189,6 @@ GEM
thread_safe (~> 0.1)
uglifier (3.0.2)
execjs (>= 0.3.0, < 3)
- warden (1.2.6)
- rack (>= 1.0)
web-console (3.3.1)
actionview (>= 5.0)
activemodel (>= 5.0)
@@ -220,7 +208,6 @@ DEPENDENCIES
bootstrap-social-rails (~> 4.12)
byebug
coffee-rails (~> 4.2)
- devise (= 4.2.0)
dotenv-rails
jbuilder (~> 2.5)
jquery-datatables-rails (~> 3.4.0)
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 0a71c41d..06835456 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -4,4 +4,9 @@ require 'digest/sha1'
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include ApplicationHelper
+
+ def current_user
+ @current_user ||= User.find_by(id: session[:user_id])
+ end
+ helper_method :current_user
end
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
new file mode 100644
index 00000000..e2ab24aa
--- /dev/null
+++ b/app/controllers/sessions_controller.rb
@@ -0,0 +1,17 @@
+class SessionsController < ApplicationController
+ def create
+ @user = User.from_omniauth(request.env['omniauth.auth'])
+ session[:user_id] = @user.id
+ rescue => e
+ logger.error "Error authenticating via omniauth: #{e}"
+ ensure
+ redirect_to root_path
+ end
+
+ def destroy
+ if current_user
+ session.delete(:user_id)
+ end
+ redirect_to root_path
+ end
+end
diff --git a/app/helpers/bbb_helper.rb b/app/helpers/bbb_helper.rb
index d99712bf..c603b4a9 100644
--- a/app/helpers/bbb_helper.rb
+++ b/app/helpers/bbb_helper.rb
@@ -4,7 +4,7 @@ module BbbHelper
if !bbb
return { :returncode => false, :messageKey => "BBBAPICallInvalid", :message => "BBB API call invalid." }
else
- meeting_id = (Digest::SHA1.hexdigest("Rails.application.secrets.secret_key_base"+meeting_token)).to_s
+ meeting_id = (Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base]+meeting_token)).to_s
#See if the meeting is running
begin
diff --git a/app/models/user.rb b/app/models/user.rb
new file mode 100644
index 00000000..80c35a02
--- /dev/null
+++ b/app/models/user.rb
@@ -0,0 +1,9 @@
+class User < ApplicationRecord
+
+ def self.from_omniauth(auth_hash)
+ user = find_or_create_by(uid: auth_hash['uid'], provider: auth_hash['provider'])
+ user.name = auth_hash['info']['name']
+ user.save!
+ user
+ end
+end
diff --git a/app/views/landing/index.html.erb b/app/views/landing/index.html.erb
index 9334ddba..58d2872c 100644
--- a/app/views/landing/index.html.erb
+++ b/app/views/landing/index.html.erb
@@ -66,3 +66,13 @@ $(document).ready(function($) {
});
});
+
+<% if current_user.nil? %>
+
+ - <%= link_to 'Twitter', '/auth/twitter' %>
+ - <%= link_to 'Google', '/auth/google' %>
+
+<% else %>
+Hello <%= current_user.name %>
+<%= link_to 'Logout', '/logout' %>
+<% end %>
diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb
new file mode 100644
index 00000000..0a60c18d
--- /dev/null
+++ b/config/initializers/omniauth.rb
@@ -0,0 +1,5 @@
+Rails.application.config.middleware.use OmniAuth::Builder do
+ provider :twitter, ENV['TWITTER_ID'], ENV['TWITTER_SECRET']
+ provider :google_oauth2, ENV['GOOGLE_OAUTH2_ID'], ENV['GOOGLE_OAUTH2_SECRET'],
+ scope: 'profile', access_type: 'online', name: 'google'
+end
diff --git a/config/routes.rb b/config/routes.rb
index 4da8b4c6..81a13543 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -3,6 +3,8 @@ Rails.application.routes.draw do
get 'bbb/close'
get 'meeting(/:id)', to: 'landing#index'
+ get '/auth/:provider/callback', to: 'sessions#create'
+ get '/logout', to: 'sessions#destroy'
root to: 'landing#index'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
diff --git a/db/migrate/20161017160526_create_users.rb b/db/migrate/20161017160526_create_users.rb
new file mode 100644
index 00000000..c795a6ee
--- /dev/null
+++ b/db/migrate/20161017160526_create_users.rb
@@ -0,0 +1,15 @@
+class CreateUsers < ActiveRecord::Migration[5.0]
+ def change
+ create_table :users do |t|
+ t.string :provider, null: false
+ t.string :uid, null: false
+ t.string :name
+
+ t.timestamps
+ end
+
+ add_index :users, :provider
+ add_index :users, :uid
+ add_index :users, [:provider, :uid], unique: true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
new file mode 100644
index 00000000..1834e3e8
--- /dev/null
+++ b/db/schema.rb
@@ -0,0 +1,26 @@
+# 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.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended that you check this file into your version control system.
+
+ActiveRecord::Schema.define(version: 20161017160526) do
+
+ create_table "users", force: :cascade do |t|
+ t.string "provider", null: false
+ t.string "uid", null: false
+ t.string "name"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["provider", "uid"], name: "index_users_on_provider_and_uid", unique: true
+ t.index ["provider"], name: "index_users_on_provider"
+ t.index ["uid"], name: "index_users_on_uid"
+ end
+
+end
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 00000000..48f53d1c
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,24 @@
+version: '2'
+services:
+ web:
+ build: .
+ ports:
+ - '80:80'
+ volumes:
+ - '.:/usr/src/app'
+ - '~/.ssh:/root/.ssh/'
+ volumes_from:
+ - gem_cache
+ expose:
+ - '3001'
+ working_dir: '/usr/src/app'
+ stdin_open: true
+ tty: true
+ command: bundle exec rails s -p 80 -b '0.0.0.0'
+ depends_on:
+ - gem_cache
+ gem_cache:
+ image: ruby:2.3.1
+ command: bin/true
+ volumes:
+ - /usr/local/bundle
diff --git a/sample.env b/sample.env
index 132c23d3..3fb6542d 100644
--- a/sample.env
+++ b/sample.env
@@ -5,4 +5,10 @@ RAILS_ENV=development
# BigBlueButton
BIGBLUEBUTTON_ENDPOINT=http://test-install.blindsidenetworks.com/bigbluebutton/
-BIGBLUEBUTTON_SECRET=8cd8ef52e8e101574e400365b55e11a6
\ No newline at end of file
+BIGBLUEBUTTON_SECRET=8cd8ef52e8e101574e400365b55e11a6
+
+# OmniAuth
+TWITTER_ID=
+TWITTER_SECRET=
+GOOGLE_OAUTH2_ID=
+GOOGLE_OAUTH2_SECRET=
diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml
new file mode 100644
index 00000000..2f72a665
--- /dev/null
+++ b/test/fixtures/users.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ provider: MyString
+ uid: MyString
+ name: MyString
+
+two:
+ provider: MyString
+ uid: MyString
+ name: MyString
diff --git a/test/models/user_test.rb b/test/models/user_test.rb
new file mode 100644
index 00000000..82f61e01
--- /dev/null
+++ b/test/models/user_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class UserTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end