From 7e07debc91ec19aee40a6e788f21d3e3f4cd7eb5 Mon Sep 17 00:00:00 2001 From: David Vandorpe Date: Wed, 21 Mar 2018 19:40:03 +0100 Subject: [PATCH] Revert "Fix for WiNA" This reverts commit eae4a3e99c2ff203002426d4c77ca961211d098a. --- .gitignore | 1 - Gemfile | 8 +- Gemfile.lock | 33 +++++-- .../components/transaction_form.jsx.coffee | 28 +++--- app/controllers/callbacks_controller.rb | 10 ++ .../concerns/transactions_query.rb | 4 +- app/controllers/transactions_controller.rb | 4 +- app/models/client.rb | 2 +- app/models/user.rb | 17 ++-- app/views/pages/_transaction_form.html.haml | 2 +- app/views/pages/sign_in_page.html.haml | 2 +- app/views/transactions/_new.html.haml | 4 +- app/views/users/show.html.haml | 4 +- bin/rails | 4 + bin/rake | 4 + config/initializers/devise.rb | 94 ++++--------------- config/initializers/zeuswpi.rb | 38 ++++++++ config/routes.rb | 4 +- .../20150908091028_devise_create_users.rb | 6 +- db/migrate/20150908092731_create_clients.rb | 2 +- db/schema.rb | 18 ++-- 21 files changed, 143 insertions(+), 146 deletions(-) create mode 100644 app/controllers/callbacks_controller.rb create mode 100644 config/initializers/zeuswpi.rb diff --git a/.gitignore b/.gitignore index f0c20bc..354eb8e 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,3 @@ !/log/.keep /tmp coverage/ -.idea diff --git a/Gemfile b/Gemfile index 7804386..d31482b 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,8 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.4' +# Use sqlite3 as the database for Active Record +gem 'sqlite3' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets @@ -14,7 +16,7 @@ gem 'coffee-rails', '~> 4.1.0' # Authentication gem 'devise' -gem 'devise_cas_authenticatable' +gem 'omniauth-oauth2' # Authorisation gem 'cancancan' @@ -61,8 +63,6 @@ group :development, :test do gem 'rspec-rails' gem 'factory_girl_rails' gem 'faker' - # Use sqlite3 as the database for Active Record - gem 'sqlite3' end group :development do @@ -86,7 +86,7 @@ group :test do end group :production do - gem 'pg', '~> 0.20' + gem 'mysql2', '~> 0.3.0' end gem 'high_voltage', '~> 2.4.0' diff --git a/Gemfile.lock b/Gemfile.lock index bba8fc6..2f608c8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -98,9 +98,6 @@ GEM responders thread_safe (~> 0.1) warden (~> 1.2.3) - devise_cas_authenticatable (1.10.3) - devise (>= 1.2.0) - rubycas-client (>= 2.2.1) diff-lcs (1.2.5) docile (1.1.5) domain_name (0.5.24) @@ -114,6 +111,8 @@ GEM railties (>= 3.0.0) faker (1.5.0) i18n (~> 0.5) + faraday (0.9.1) + multipart-post (>= 1.2, < 3) friendly_id (5.1.0) activerecord (>= 4.0.0) globalid (0.3.6) @@ -126,6 +125,7 @@ GEM haml (>= 4.0.6, < 5.0) html2haml (>= 1.0.1) railties (>= 4.0.1) + hashie (3.4.2) high_voltage (2.4.0) html2haml (2.0.0) erubis (~> 2.7.0) @@ -148,6 +148,7 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (1.8.3) + jwt (1.5.1) loofah (2.0.3) nokogiri (>= 1.5.9) mail (2.6.3) @@ -156,14 +157,28 @@ GEM mini_portile (0.6.2) minitest (5.8.0) multi_json (1.11.2) + multi_xml (0.5.5) + multipart-post (2.0.0) + mysql2 (0.3.20) net-scp (1.2.1) net-ssh (>= 2.6.5) net-ssh (2.9.2) netrc (0.10.3) nokogiri (1.6.6.2) 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.3.1) + oauth2 (~> 1.0) + omniauth (~> 1.2) orm_adapter (0.5.0) - pg (0.21.0) purecss-rails (0.6.0) railties (>= 3.2.6, < 5) rack (1.6.4) @@ -194,7 +209,7 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.4.2) - rdoc (4.3.0) + rdoc (4.2.0) react-rails (1.10.0) babel-transpiler (>= 0.7.0) coffee-script-source (~> 1.8) @@ -228,8 +243,6 @@ GEM rspec-support (3.3.0) ruby_parser (3.7.1) sexp_processor (~> 4.1) - rubycas-client (2.3.9) - activesupport sass (3.4.18) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -301,7 +314,6 @@ DEPENDENCIES coffee-rails (~> 4.1.0) coveralls devise - devise_cas_authenticatable factory_girl_rails faker friendly_id (~> 5.1.0) @@ -310,7 +322,8 @@ DEPENDENCIES jbuilder (~> 2.0) jquery-datatables-rails jquery-rails - pg (~> 0.20) + mysql2 (~> 0.3.0) + omniauth-oauth2 purecss-rails rails (= 4.2.4) react-rails @@ -326,4 +339,4 @@ DEPENDENCIES web-console (~> 2.0) BUNDLED WITH - 1.16.1 + 1.13.7 diff --git a/app/assets/javascripts/components/transaction_form.jsx.coffee b/app/assets/javascripts/components/transaction_form.jsx.coffee index 2959aeb..bd12297 100644 --- a/app/assets/javascripts/components/transaction_form.jsx.coffee +++ b/app/assets/javascripts/components/transaction_form.jsx.coffee @@ -41,22 +41,16 @@ Amount = React.createFactory React.createClass } Peer = React.createFactory React.createClass - extractName: (peer) -> - if peer && typeof peer == 'object' - return peer.name - return peer; - onChange: (ref) -> @props.setPeer ref.target.value options: -> { peer, peers } = @props - peerName = @extractName(peer) - if peer == '' or peers.filter((t) -> t.name == peerName ).length > 0 + if peer == '' or peers.includes(peer) [] else - re = new RegExp peerName + re = new RegExp peer peers.filter (s) -> - s.name.match(re) != null + s.match(re) != null inputClass: (n) -> c = ['form-control', 'input-lg'] c.push 'active' if n > 0 @@ -72,15 +66,15 @@ Peer = React.createFactory React.createClass input { className: @inputClass(options.length), onChange: @onChange, - placeholder: 'WiNA member', + placeholder: 'Zeus member', type: 'text', - value: (@extractName(@props.peer) || '') + value: (@props.peer || '') } if options.length != 0 div className: 'suggestions', @options().map (s, i) => div className: 'suggestion', key: i, onClick: @setPeer(s), - s.name + s Message = React.createFactory React.createClass onChange: (ref) -> @@ -147,11 +141,11 @@ Step = React.createFactory React.createClass return if giving - debtor = user.username - creditor = peer.username + debtor = user.name + creditor = peer else - debtor = peer.username - creditor = user.username + debtor = peer + creditor = user.name $('') .attr('name', 'transaction[debtor]') @@ -181,7 +175,7 @@ Step = React.createFactory React.createClass unless message && message != "" errors['message'] = 'Please fill in a message.' - unless peer && peers.filter((t) -> t.name == peer.name ).length > 0 && peer != user + unless peer && peers.includes(peer) && peer != user errors['peer'] = 'Please select a valid Zeus member.' errors diff --git a/app/controllers/callbacks_controller.rb b/app/controllers/callbacks_controller.rb new file mode 100644 index 0000000..dcd8663 --- /dev/null +++ b/app/controllers/callbacks_controller.rb @@ -0,0 +1,10 @@ +class CallbacksController < Devise::OmniauthCallbacksController + def zeuswpi + @user = User.from_omniauth(request.env["omniauth.auth"]) + sign_in_and_redirect @user + end + + def after_omniauth_failure_path_for(scope) + root_path + end +end diff --git a/app/controllers/concerns/transactions_query.rb b/app/controllers/concerns/transactions_query.rb index f762a0b..2311809 100644 --- a/app/controllers/concerns/transactions_query.rb +++ b/app/controllers/concerns/transactions_query.rb @@ -6,7 +6,7 @@ class TransactionsQuery @transactions = Arel::Table.new(:transactions) @perspectived = Arel::Table.new(:perspectived_transactions) @peers = Arel::Table.new(:users).alias('peers') - @arel_table = Arel::Table.new("#{@user.username}_transactions") + @arel_table = Arel::Table.new("#{@user.name}_transactions") end def query @@ -16,7 +16,7 @@ class TransactionsQuery def arel Arel::Nodes::TableAlias.new( - issued_by(User), + issued_by(User).union(:all, issued_by(Client)), arel_table.name ) end diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb index dd91723..4227c7e 100644 --- a/app/controllers/transactions_controller.rb +++ b/app/controllers/transactions_controller.rb @@ -36,8 +36,8 @@ class TransactionsController < ApplicationController .permit(:debtor, :creditor, :message, :euros, :cents, :id_at_client) { - debtor: t[:debtor] ? User.find_by(username: t[:debtor]) : User.wina, - creditor: t[:creditor] ? User.find_by(username: t[:creditor]) : User.wina, + debtor: t[:debtor] ? User.find_or_create_by(name: t[:debtor]) : User.zeus, + creditor: t[:creditor] ? User.find_or_create_by(name: t[:creditor]) : User.zeus, issuer: current_client || current_user, amount: (t[:euros].to_f * 100 + t[:cents].to_f).to_i, message: t[:message], diff --git a/app/models/client.rb b/app/models/client.rb index a5644e8..c3f4762 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -14,7 +14,7 @@ class Client < ActiveRecord::Base has_many :issued_transactions, as: :issuer, class_name: 'Transaction' before_create :generate_key - validates :username, presence: true, uniqueness: true + validates :name, presence: true, uniqueness: true private def generate_key diff --git a/app/models/user.rb b/app/models/user.rb index 6cb9c48..a60aceb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,7 +13,7 @@ class User < ActiveRecord::Base include FriendlyId friendly_id :name, use: :finders - devise :cas_authenticatable + devise :timeoutable, :omniauthable, :omniauth_providers => [:zeuswpi] has_many :incoming_transactions, class_name: 'Transaction', foreign_key: 'creditor_id' has_many :outgoing_transactions, @@ -28,7 +28,7 @@ class User < ActiveRecord::Base validates :name, presence: true, uniqueness: true - scope :humans, -> { where.not(id: self.wina) } + scope :humans, -> { where.not(id: self.zeus) } def transactions Transaction.where("creditor_id = ? OR debtor_id = ?", id, id) @@ -40,13 +40,14 @@ class User < ActiveRecord::Base self.update_attribute :balance, balance end - def cas_extra_attributes=(extra_attributes) - self.name = extra_attributes['display_name'] - self.debt_allowed = extra_attributes['permissions'].include? 'HAVE_SCHULDEN' - self.penning = extra_attributes['permissions'].include? 'MANAGE_SCHULDEN' + def self.from_omniauth(auth) + where(name: auth.uid).first_or_create do |user| + user.name = auth.uid + end end - def self.wina - @@wina ||= find_or_create_by name: 'WiNA', username: :WiNA + def self.zeus + @@zeus ||= find_or_create_by name: 'Zeus' end + end diff --git a/app/views/pages/_transaction_form.html.haml b/app/views/pages/_transaction_form.html.haml index aaee407..2da34ad 100644 --- a/app/views/pages/_transaction_form.html.haml +++ b/app/views/pages/_transaction_form.html.haml @@ -1,3 +1,3 @@ .card-wrapper .card.padded - = react_component 'TransactionForm', user: current_user, peers: User.all.order(:name) + = react_component 'TransactionForm', user: current_user, peers: User.all.order(:name).pluck(:name) diff --git a/app/views/pages/sign_in_page.html.haml b/app/views/pages/sign_in_page.html.haml index 86f1641..2795a68 100644 --- a/app/views/pages/sign_in_page.html.haml +++ b/app/views/pages/sign_in_page.html.haml @@ -4,7 +4,7 @@ .pure-u-1.pure-u-md-1-2 %h2 Authentication %p Log een keer in en betaal uw schulden! - %p= link_to "Log in met WiNA CAS", new_user_session_path, class: "pure-button pure-button-primary login-button" + %p= link_to "Log in met Zeus WPI", user_omniauth_authorize_path(:zeuswpi), class: "pure-button pure-button-primary login-button" .pure-u-1.pure-u-md-1-2 %h2 Pie of Shame = pie_chart @statistics.shamehash diff --git a/app/views/transactions/_new.html.haml b/app/views/transactions/_new.html.haml index b3c317f..9b2a6db 100644 --- a/app/views/transactions/_new.html.haml +++ b/app/views/transactions/_new.html.haml @@ -3,9 +3,9 @@ = render 'partials/form_errors', object: @transaction = form_for @transaction, remote: true, html: { class: "pure-form form-inline" } do |f| - = f.hidden_field :debtor, value: @user.username + = f.hidden_field :debtor, value: @user.name = f.select :creditor, - options_from_collection_for_select(User.all.order(:name), :username, :name), + options_from_collection_for_select(User.all.order(:name), :name, :name), { include_blank: true }, { class: 'select2-selector', required: true, data: { placeholder: "Creditor", width: 150 } } = f.text_field :message, placeholder: "Message", size: 75, class: "form-control", required: true diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 53be424..5260746 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -42,13 +42,13 @@ .row .col-md-4 .input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Issuer' } - = grouped_collection_select nil, nil, [User, Client], :all, :name, :username, :name, + = grouped_collection_select nil, nil, [User, Client], :all, :name, :name, :name, { include_blank: true }, { data: { placeholder: "Filter on Issuer", width: 265 }, class: "select2-selector form-control value-thing" } .col-md-4 .input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Peer' } = select_tag nil, - options_from_collection_for_select(User.all.order(:name), :username, :name), + options_from_collection_for_select(User.all.order(:name), :name, :name), include_blank: true, class: "select2-selector form-control value-thing", data: { placeholder: "Filter on Peer", width: 265 } .col-md-4 .input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Message' } diff --git a/bin/rails b/bin/rails index 5191e69..4d608ed 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,8 @@ #!/usr/bin/env ruby +begin + load File.expand_path("../spring", __FILE__) +rescue LoadError +end APP_PATH = File.expand_path('../../config/application', __FILE__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/rake b/bin/rake index 1724048..8017a02 100755 --- a/bin/rake +++ b/bin/rake @@ -1,4 +1,8 @@ #!/usr/bin/env ruby +begin + load File.expand_path("../spring", __FILE__) +rescue LoadError +end require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index cdc63a1..15aa283 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -4,9 +4,9 @@ Devise.setup do |config| # The secret key used by Devise. Devise uses this key to generate # random tokens. Changing this key will render invalid all existing # confirmation, reset password and unlock tokens in the database. - # Devise will use the `secret_key_base` as its `secret_key` + # Devise will use the `secret_key_base` on Rails 4+ applications as its `secret_key` # by default. You can change it below and use your own secret key. - # config.secret_key = 'a53f0fd5c5917bd1c1453a26597c4b8767ec02ae7e716f2c5513c389b5441a2a5fdd3ed82561f29579f05c6d2242979cbc7836d63bb1f38e1ab6f2c2d8ccc934' + # config.secret_key = 'db9dcc69d4370aba9151d435032f8263c40b2536a288267af3878a16df4b9d9f8e509f7671a39c534d0ac663f6fb9d3a879cdea867dc73053c97b36406e0a9e9' # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, @@ -17,9 +17,6 @@ Devise.setup do |config| # Configure the class responsible to send e-mails. # config.mailer = 'Devise::Mailer' - # Configure the parent class responsible to send e-mails. - # config.parent_mailer = 'ActionMailer::Base' - # ==> ORM configuration # Load and configure the ORM. Supports :active_record (default) and # :mongoid (bson_ext recommended) by default. Other ORMs may be @@ -90,31 +87,19 @@ Devise.setup do |config| # from the server. You can disable this option at your own risk. # config.clean_up_csrf_token_on_authentication = true - # When false, Devise will not attempt to reload routes on eager load. - # This can reduce the time taken to boot the app but if your application - # requires the Devise mappings to be loaded during boot time the application - # won't boot properly. - # config.reload_routes = true - # ==> Configuration for :database_authenticatable - # For bcrypt, this is the cost for hashing the password and defaults to 11. If - # using other algorithms, it sets how many times you want the password to be hashed. + # For bcrypt, this is the cost for hashing the password and defaults to 10. If + # using other encryptors, it sets how many times you want the password re-encrypted. # # Limiting the stretches to just one in testing will increase the performance of # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use # a value less than 10 in other environments. Note that, for bcrypt (the default - # algorithm), the cost increases exponentially with the number of stretches (e.g. + # encryptor), the cost increases exponentially with the number of stretches (e.g. # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). - config.stretches = Rails.env.test? ? 1 : 11 + config.stretches = Rails.env.test? ? 1 : 10 - # Set up a pepper to generate the hashed password. - # config.pepper = 'c664e685c6d19495baa24a50ea811daca5acc07987f86748699ccc1f31dcae70b39744352188041ea10428d923ef58228fb93c829672e2065be91784909dd2d5' - - # Send a notification to the original email when the user's email is changed. - # config.send_email_changed_notification = false - - # Send a notification email when the user's password is changed. - # config.send_password_change_notification = false + # Setup a pepper to generate the encrypted password. + # config.pepper = '6246d8fa4efd376623925a6d8600b268d11ce906a667d550663fe069dbe249bd11c0f26329c1d61f58fa9a615ee738d5b0feba189b6fdc390662e45b7a39c476' # ==> Configuration for :confirmable # A period that the user is allowed to access the website even without @@ -157,12 +142,12 @@ Devise.setup do |config| # ==> Configuration for :validatable # Range for password length. - config.password_length = 6..128 + config.password_length = 8..72 # Email regex used to validate email formats. It simply asserts that # one (and only one) @ exists in the given string. This is mainly # to give user feedback and not to assert the e-mail validity. - config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ + # config.email_regexp = /\A[^@]+@[^@]+\z/ # ==> Configuration for :timeoutable # The time you want to timeout the user session without activity. After this @@ -210,11 +195,11 @@ Devise.setup do |config| # config.sign_in_after_reset_password = true # ==> Configuration for :encryptable - # Allow you to use another hashing or encryption algorithm besides bcrypt (default). - # You can use :sha1, :sha512 or algorithms from others authentication tools as - # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 - # for default behavior) and :restful_authentication_sha1 (then you should set - # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). + # Allow you to use another encryption algorithm besides bcrypt (default). You can use + # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, + # :authlogic_sha512 (then you should set stretches above to 20 for default behavior) + # and :restful_authentication_sha1 (then you should set stretches to 10, and copy + # REST_AUTH_SITE_KEY to pepper). # # Require the `devise-encryptable` gem when using anything other than bcrypt # config.encryptor = :sha512 @@ -250,7 +235,7 @@ Devise.setup do |config| # ==> OmniAuth # Add a new OmniAuth provider. Check the wiki for more information on setting # up on your models and hooks. - # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + config.omniauth :zeuswpi, Rails.application.secrets.omniauth_client_id, Rails.application.secrets.omniauth_client_secret # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or @@ -274,51 +259,4 @@ Devise.setup do |config| # When using OmniAuth, Devise cannot automatically set OmniAuth path, # so you need to do it manually. For the users scope, it would be: # config.omniauth_path_prefix = '/my_engine/users/auth' - - config.cas_base_url = 'https://login.wina-gent.be/cas' - - # you can override these if you need to, but cas_base_url is usually enough - # config.cas_login_url = "https://cas.myorganization.com/login" - # config.cas_logout_url = "https://cas.myorganization.com/logout" - # config.cas_validate_url = "https://cas.myorganization.com/serviceValidate" - - # The CAS specification allows for the passing of a follow URL to be displayed when - # a user logs out on the CAS server. RubyCAS-Server also supports redirecting to a - # URL via the destination param. Set either of these urls and specify either nil, - # 'destination' or 'follow' as the logout_url_param. If the urls are blank but - # logout_url_param is set, a default will be detected for the service. - # config.cas_destination_url = 'https://cas.myorganization.com' - # config.cas_follow_url = 'https://cas.myorganization.com' - # config.cas_logout_url_param = nil - - # You can specify the name of the destination argument with the following option. - # e.g. the following option will change it from 'destination' to 'url' - # config.cas_destination_logout_param_name = 'url' - - # By default, devise_cas_authenticatable will create users. If you would rather - # require user records to already exist locally before they can authenticate via - # CAS, uncomment the following line. - # config.cas_create_user = false - - # You can enable Single Sign Out, which by default is disabled. - # config.cas_enable_single_sign_out = true - - # If you don't want to use the username returned from your CAS server as the unique - # identifier, but some other field passed in cas_extra_attributes, you can specify - # the field name here. - # config.cas_user_identifier = nil - - # If you want to use the Devise Timeoutable module with single sign out, - # uncommenting this will redirect timeouts to the logout url, so that the CAS can - # take care of signing out the other serviced applocations. Note that each - # application manages timeouts independently, so one application timing out will - # kill the session on all applications serviced by the CAS. - # config.warden do |manager| - # manager.failure_app = DeviseCasAuthenticatable::SingleSignOut::WardenFailureApp - # end - - # If you need to specify some extra configs for rubycas-client, you can do this via: - # config.cas_client_config_options = { - # logger: Rails.logger - # } end diff --git a/config/initializers/zeuswpi.rb b/config/initializers/zeuswpi.rb new file mode 100644 index 0000000..52f167f --- /dev/null +++ b/config/initializers/zeuswpi.rb @@ -0,0 +1,38 @@ +require 'omniauth-oauth2' + +module OmniAuth + module Strategies + class Zeuswpi < OmniAuth::Strategies::OAuth2 + + option :provider_ignores_state, true + + # Give your strategy a name. + option :name, 'zeuswpi' + + # This is where you pass the options you would pass when + # initializing your consumer from the OAuth gem. + option :client_options, { + site: 'https://adams.ugent.be', + authorize_url: '/oauth/oauth2/authorize/', + token_url: '/oauth/oauth2/token/', + } + + # These are called after authentication has succeeded. If + # possible, you should try to set the UID without making + # additional calls (if the user id is returned with the token + # or as a URI parameter). This may not be possible with all + # providers. + uid{ raw_info['username'] } + + extra do + { + 'raw_info' => raw_info + } + end + + def raw_info + @raw_info ||= access_token.get('/oauth/api/current_user/').parsed + end + end + end +end diff --git a/config/routes.rb b/config/routes.rb index e465b0c..bf1b9d5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,7 @@ Rails.application.routes.draw do - devise_for :users + devise_for :users, controllers: { + omniauth_callbacks: 'callbacks' + } devise_scope :user do delete '/sign_out', to: 'devise/sessions#destroy' diff --git a/db/migrate/20150908091028_devise_create_users.rb b/db/migrate/20150908091028_devise_create_users.rb index 32b41e8..2d83040 100644 --- a/db/migrate/20150908091028_devise_create_users.rb +++ b/db/migrate/20150908091028_devise_create_users.rb @@ -1,12 +1,8 @@ class DeviseCreateUsers < ActiveRecord::Migration def change create_table(:users) do |t| - t.string :username, index: true, unique: true - + t.string :name, index: true, unique: true t.integer :balance, null: false, default: 0, index: true - - t.string :name, null: false - t.boolean :debt_allowed, null: false, default: false t.boolean :penning, null: false, default: false t.timestamps null: false diff --git a/db/migrate/20150908092731_create_clients.rb b/db/migrate/20150908092731_create_clients.rb index a820e6c..8e1edff 100644 --- a/db/migrate/20150908092731_create_clients.rb +++ b/db/migrate/20150908092731_create_clients.rb @@ -1,7 +1,7 @@ class CreateClients < ActiveRecord::Migration def change create_table :clients do |t| - t.string :username, null: false, index: true, unique: true + t.string :name, null: false, index: true, unique: true t.string :key, null: false, index: true, unique: true t.timestamps null: false diff --git a/db/schema.rb b/db/schema.rb index 8e6189a..1ba8749 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -14,14 +14,14 @@ ActiveRecord::Schema.define(version: 20170123151219) do create_table "clients", force: :cascade do |t| - t.string "username", null: false + t.string "name", null: false t.string "key", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end add_index "clients", ["key"], name: "index_clients_on_key" - add_index "clients", ["username"], name: "index_clients_on_username" + add_index "clients", ["name"], name: "index_clients_on_name" create_table "clients_roles", id: false, force: :cascade do |t| t.integer "client_id" @@ -85,16 +85,14 @@ ActiveRecord::Schema.define(version: 20170123151219) do add_index "transactions", ["issuer_type", "issuer_id"], name: "index_transactions_on_issuer_type_and_issuer_id" create_table "users", force: :cascade do |t| - t.string "username" - t.integer "balance", default: 0, null: false - t.string "name", null: false - t.boolean "debt_allowed", default: false, null: false - t.boolean "penning", default: false, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "name" + t.integer "balance", default: 0, null: false + t.boolean "penning", default: false, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "users", ["balance"], name: "index_users_on_balance" - add_index "users", ["username"], name: "index_users_on_username" + add_index "users", ["name"], name: "index_users_on_name" end