diff --git a/Gemfile b/Gemfile index 170b1a2..26435ea 100644 --- a/Gemfile +++ b/Gemfile @@ -75,4 +75,4 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] gem 'coveralls', require: false -gem 'omniauth' +gem 'omniauth-oauth2' diff --git a/Gemfile.lock b/Gemfile.lock index 4c7f373..fb566ce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -108,6 +108,8 @@ GEM execjs (2.3.0) faker (1.4.2) i18n (~> 0.5) + faraday (0.9.1) + multipart-post (>= 1.2, < 3) ffi (1.9.6-x64-mingw32) globalid (0.3.2) activesupport (>= 4.1.0) @@ -122,6 +124,7 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (1.8.2) + jwt (1.4.1) launchy (2.4.3) addressable (~> 2.3) loofah (2.0.1) @@ -132,6 +135,8 @@ GEM mini_portile (0.6.2) minitest (5.5.1) multi_json (1.10.1) + multi_xml (0.5.5) + multipart-post (2.0.0) mysql2 (0.3.17) net-scp (1.2.1) net-ssh (>= 2.6.5) @@ -141,9 +146,20 @@ GEM mini_portile (~> 0.6.0) nokogiri (1.6.6.2-x64-mingw32) mini_portile (~> 0.6.0) + oauth2 (1.0.0) + faraday (>= 0.8, < 0.10) + jwt (~> 1.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (~> 1.2) omniauth (1.2.2) hashie (>= 1.2, < 4) rack (~> 1.0) + omniauth-oauth2 (1.2.0) + faraday (>= 0.8, < 0.10) + multi_json (~> 1.3) + oauth2 (~> 1.0) + omniauth (~> 1.2) orm_adapter (0.5.0) paper_trail (4.0.0.beta2) activerecord (>= 3.0, < 6.0) @@ -267,7 +283,7 @@ DEPENDENCIES jquery-rails launchy mysql2 - omniauth + omniauth-oauth2 paper_trail (~> 4.0.0.beta) paperclip rails (= 4.2) diff --git a/app/assets/javascripts/callbacks.js.coffee b/app/assets/javascripts/callbacks.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/callbacks.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/callbacks.css.scss b/app/assets/stylesheets/callbacks.css.scss new file mode 100644 index 0000000..e4c4d53 --- /dev/null +++ b/app/assets/stylesheets/callbacks.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the callbacks controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/callbacks_controller.rb b/app/controllers/callbacks_controller.rb new file mode 100644 index 0000000..bbab5e8 --- /dev/null +++ b/app/controllers/callbacks_controller.rb @@ -0,0 +1,7 @@ +class CallbacksController < Devise::OmniauthCallbacksController + def zeuswpi + @user = User.from_omniauth(request.env["omniauth.auth"]) + @user.save + sign_in_and_redirect @user + end +end diff --git a/app/helpers/callbacks_helper.rb b/app/helpers/callbacks_helper.rb new file mode 100644 index 0000000..6c9550c --- /dev/null +++ b/app/helpers/callbacks_helper.rb @@ -0,0 +1,2 @@ +module CallbacksHelper +end diff --git a/app/models/user.rb b/app/models/user.rb index bd7ace0..6a4a158 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -27,7 +27,7 @@ # class User < ActiveRecord::Base - devise :database_authenticatable, :registerable, :rememberable, :trackable, :validatable + devise :database_authenticatable, :registerable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:zeuswpi] has_paper_trail only: [:debt_cents, :admin, :orders_count, :koelkast] @@ -44,6 +44,13 @@ class User < ActiveRecord::Base scope :members, -> { where koelkast: false } + def self.from_omniauth(auth) + where(provider: auth.provider, uid: auth.uid).first_or_create do |user| + user.provider = auth.provider + user.uid = auth.uid + end + end + def debt self.debt_cents / 100.0 end diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 7f01101..222f8a5 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -14,5 +14,4 @@ <% end %> - <%= render "devise/shared/links" %> diff --git a/app/views/orders/overview.html.erb b/app/views/orders/overview.html.erb index c9239e8..95aa1bb 100644 --- a/app/views/orders/overview.html.erb +++ b/app/views/orders/overview.html.erb @@ -1,5 +1,4 @@ <%= render partial: 'flash' %> -<%= text_field_tag :search %>