diff --git a/.gitignore b/.gitignore index bab620de..e4089d81 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ /tmp/* !/log/.keep !/tmp/.keep +.env # Ignore Byebug command history file. .byebug_history 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 00c79238..afc9399f 100644 --- a/Gemfile +++ b/Gemfile @@ -33,6 +33,7 @@ gem 'jbuilder', '~> 2.5' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri + gem 'dotenv-rails' end group :development do @@ -47,5 +48,7 @@ end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem 'omniauth' +gem 'omniauth-twitter' +gem 'omniauth-google-oauth2' gem 'bigbluebutton-api-ruby' - diff --git a/Gemfile.lock b/Gemfile.lock index 3aa0a317..aa954982 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,11 +52,18 @@ GEM coffee-script-source (1.10.0) concurrent-ruby (1.0.2) debug_inspector (0.0.2) + dotenv (2.1.1) + dotenv-rails (2.1.1) + dotenv (= 2.1.1) + railties (>= 4.0, < 5.1) erubis (2.7.0) execjs (2.7.0) + faraday (0.9.2) + multipart-post (>= 1.2, < 3) ffi (1.9.14) globalid (0.3.7) activesupport (>= 4.1.0) + hashie (3.4.6) i18n (0.7.0) jbuilder (2.6.0) activesupport (>= 3.0.0, < 5.1) @@ -65,6 +72,8 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + json (1.8.3) + jwt (1.5.6) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -79,9 +88,35 @@ GEM mini_portile2 (2.1.0) minitest (5.9.1) multi_json (1.12.1) + multi_xml (0.5.5) + multipart-post (2.0.0) nio4r (1.2.1) nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) + oauth (0.5.1) + oauth2 (1.2.0) + faraday (>= 0.8, < 0.10) + jwt (~> 1.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (>= 1.2, < 3) + omniauth (1.3.1) + hashie (>= 1.2, < 4) + rack (>= 1.0, < 3) + omniauth-google-oauth2 (0.4.1) + jwt (~> 1.5.2) + multi_json (~> 1.3) + omniauth (>= 1.1.1) + omniauth-oauth2 (>= 1.3.1) + omniauth-oauth (1.1.0) + oauth + omniauth (~> 1.0) + omniauth-oauth2 (1.4.0) + oauth2 (~> 1.0) + omniauth (~> 1.2) + omniauth-twitter (1.2.1) + json (~> 1.3) + omniauth-oauth (~> 1.1) puma (3.6.0) rack (2.0.1) rack-test (0.6.3) @@ -160,9 +195,13 @@ DEPENDENCIES bigbluebutton-api-ruby byebug coffee-rails (~> 4.2) + dotenv-rails jbuilder (~> 2.5) jquery-rails listen (~> 3.0.5) + omniauth + omniauth-google-oauth2 + omniauth-twitter puma (~> 3.0) rails (~> 5.0.0, >= 5.0.0.1) sass-rails (~> 5.0) @@ -175,4 +214,4 @@ DEPENDENCIES web-console BUNDLED WITH - 1.13.2 + 1.13.4 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1c07694e..5e1257af 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,8 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception + + 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/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 fed5c740..935f565a 100644 --- a/app/views/landing/index.html.erb +++ b/app/views/landing/index.html.erb @@ -33,3 +33,13 @@
+ +<% if current_user.nil? %> +