parent
5472067004
commit
7e07debc91
21 changed files with 143 additions and 146 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -16,4 +16,3 @@
|
||||||
!/log/.keep
|
!/log/.keep
|
||||||
/tmp
|
/tmp
|
||||||
coverage/
|
coverage/
|
||||||
.idea
|
|
||||||
|
|
8
Gemfile
8
Gemfile
|
@ -3,6 +3,8 @@ source 'https://rubygems.org'
|
||||||
|
|
||||||
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
||||||
gem 'rails', '4.2.4'
|
gem 'rails', '4.2.4'
|
||||||
|
# Use sqlite3 as the database for Active Record
|
||||||
|
gem 'sqlite3'
|
||||||
# Use SCSS for stylesheets
|
# Use SCSS for stylesheets
|
||||||
gem 'sass-rails', '~> 5.0'
|
gem 'sass-rails', '~> 5.0'
|
||||||
# Use Uglifier as compressor for JavaScript assets
|
# Use Uglifier as compressor for JavaScript assets
|
||||||
|
@ -14,7 +16,7 @@ gem 'coffee-rails', '~> 4.1.0'
|
||||||
|
|
||||||
# Authentication
|
# Authentication
|
||||||
gem 'devise'
|
gem 'devise'
|
||||||
gem 'devise_cas_authenticatable'
|
gem 'omniauth-oauth2'
|
||||||
|
|
||||||
# Authorisation
|
# Authorisation
|
||||||
gem 'cancancan'
|
gem 'cancancan'
|
||||||
|
@ -61,8 +63,6 @@ group :development, :test do
|
||||||
gem 'rspec-rails'
|
gem 'rspec-rails'
|
||||||
gem 'factory_girl_rails'
|
gem 'factory_girl_rails'
|
||||||
gem 'faker'
|
gem 'faker'
|
||||||
# Use sqlite3 as the database for Active Record
|
|
||||||
gem 'sqlite3'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
|
@ -86,7 +86,7 @@ group :test do
|
||||||
end
|
end
|
||||||
|
|
||||||
group :production do
|
group :production do
|
||||||
gem 'pg', '~> 0.20'
|
gem 'mysql2', '~> 0.3.0'
|
||||||
end
|
end
|
||||||
|
|
||||||
gem 'high_voltage', '~> 2.4.0'
|
gem 'high_voltage', '~> 2.4.0'
|
||||||
|
|
33
Gemfile.lock
33
Gemfile.lock
|
@ -98,9 +98,6 @@ GEM
|
||||||
responders
|
responders
|
||||||
thread_safe (~> 0.1)
|
thread_safe (~> 0.1)
|
||||||
warden (~> 1.2.3)
|
warden (~> 1.2.3)
|
||||||
devise_cas_authenticatable (1.10.3)
|
|
||||||
devise (>= 1.2.0)
|
|
||||||
rubycas-client (>= 2.2.1)
|
|
||||||
diff-lcs (1.2.5)
|
diff-lcs (1.2.5)
|
||||||
docile (1.1.5)
|
docile (1.1.5)
|
||||||
domain_name (0.5.24)
|
domain_name (0.5.24)
|
||||||
|
@ -114,6 +111,8 @@ GEM
|
||||||
railties (>= 3.0.0)
|
railties (>= 3.0.0)
|
||||||
faker (1.5.0)
|
faker (1.5.0)
|
||||||
i18n (~> 0.5)
|
i18n (~> 0.5)
|
||||||
|
faraday (0.9.1)
|
||||||
|
multipart-post (>= 1.2, < 3)
|
||||||
friendly_id (5.1.0)
|
friendly_id (5.1.0)
|
||||||
activerecord (>= 4.0.0)
|
activerecord (>= 4.0.0)
|
||||||
globalid (0.3.6)
|
globalid (0.3.6)
|
||||||
|
@ -126,6 +125,7 @@ GEM
|
||||||
haml (>= 4.0.6, < 5.0)
|
haml (>= 4.0.6, < 5.0)
|
||||||
html2haml (>= 1.0.1)
|
html2haml (>= 1.0.1)
|
||||||
railties (>= 4.0.1)
|
railties (>= 4.0.1)
|
||||||
|
hashie (3.4.2)
|
||||||
high_voltage (2.4.0)
|
high_voltage (2.4.0)
|
||||||
html2haml (2.0.0)
|
html2haml (2.0.0)
|
||||||
erubis (~> 2.7.0)
|
erubis (~> 2.7.0)
|
||||||
|
@ -148,6 +148,7 @@ GEM
|
||||||
railties (>= 4.2.0)
|
railties (>= 4.2.0)
|
||||||
thor (>= 0.14, < 2.0)
|
thor (>= 0.14, < 2.0)
|
||||||
json (1.8.3)
|
json (1.8.3)
|
||||||
|
jwt (1.5.1)
|
||||||
loofah (2.0.3)
|
loofah (2.0.3)
|
||||||
nokogiri (>= 1.5.9)
|
nokogiri (>= 1.5.9)
|
||||||
mail (2.6.3)
|
mail (2.6.3)
|
||||||
|
@ -156,14 +157,28 @@ GEM
|
||||||
mini_portile (0.6.2)
|
mini_portile (0.6.2)
|
||||||
minitest (5.8.0)
|
minitest (5.8.0)
|
||||||
multi_json (1.11.2)
|
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-scp (1.2.1)
|
||||||
net-ssh (>= 2.6.5)
|
net-ssh (>= 2.6.5)
|
||||||
net-ssh (2.9.2)
|
net-ssh (2.9.2)
|
||||||
netrc (0.10.3)
|
netrc (0.10.3)
|
||||||
nokogiri (1.6.6.2)
|
nokogiri (1.6.6.2)
|
||||||
mini_portile (~> 0.6.0)
|
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)
|
orm_adapter (0.5.0)
|
||||||
pg (0.21.0)
|
|
||||||
purecss-rails (0.6.0)
|
purecss-rails (0.6.0)
|
||||||
railties (>= 3.2.6, < 5)
|
railties (>= 3.2.6, < 5)
|
||||||
rack (1.6.4)
|
rack (1.6.4)
|
||||||
|
@ -194,7 +209,7 @@ GEM
|
||||||
rake (>= 0.8.7)
|
rake (>= 0.8.7)
|
||||||
thor (>= 0.18.1, < 2.0)
|
thor (>= 0.18.1, < 2.0)
|
||||||
rake (10.4.2)
|
rake (10.4.2)
|
||||||
rdoc (4.3.0)
|
rdoc (4.2.0)
|
||||||
react-rails (1.10.0)
|
react-rails (1.10.0)
|
||||||
babel-transpiler (>= 0.7.0)
|
babel-transpiler (>= 0.7.0)
|
||||||
coffee-script-source (~> 1.8)
|
coffee-script-source (~> 1.8)
|
||||||
|
@ -228,8 +243,6 @@ GEM
|
||||||
rspec-support (3.3.0)
|
rspec-support (3.3.0)
|
||||||
ruby_parser (3.7.1)
|
ruby_parser (3.7.1)
|
||||||
sexp_processor (~> 4.1)
|
sexp_processor (~> 4.1)
|
||||||
rubycas-client (2.3.9)
|
|
||||||
activesupport
|
|
||||||
sass (3.4.18)
|
sass (3.4.18)
|
||||||
sass-rails (5.0.4)
|
sass-rails (5.0.4)
|
||||||
railties (>= 4.0.0, < 5.0)
|
railties (>= 4.0.0, < 5.0)
|
||||||
|
@ -301,7 +314,6 @@ DEPENDENCIES
|
||||||
coffee-rails (~> 4.1.0)
|
coffee-rails (~> 4.1.0)
|
||||||
coveralls
|
coveralls
|
||||||
devise
|
devise
|
||||||
devise_cas_authenticatable
|
|
||||||
factory_girl_rails
|
factory_girl_rails
|
||||||
faker
|
faker
|
||||||
friendly_id (~> 5.1.0)
|
friendly_id (~> 5.1.0)
|
||||||
|
@ -310,7 +322,8 @@ DEPENDENCIES
|
||||||
jbuilder (~> 2.0)
|
jbuilder (~> 2.0)
|
||||||
jquery-datatables-rails
|
jquery-datatables-rails
|
||||||
jquery-rails
|
jquery-rails
|
||||||
pg (~> 0.20)
|
mysql2 (~> 0.3.0)
|
||||||
|
omniauth-oauth2
|
||||||
purecss-rails
|
purecss-rails
|
||||||
rails (= 4.2.4)
|
rails (= 4.2.4)
|
||||||
react-rails
|
react-rails
|
||||||
|
@ -326,4 +339,4 @@ DEPENDENCIES
|
||||||
web-console (~> 2.0)
|
web-console (~> 2.0)
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
1.16.1
|
1.13.7
|
||||||
|
|
|
@ -41,22 +41,16 @@ Amount = React.createFactory React.createClass
|
||||||
}
|
}
|
||||||
|
|
||||||
Peer = React.createFactory React.createClass
|
Peer = React.createFactory React.createClass
|
||||||
extractName: (peer) ->
|
|
||||||
if peer && typeof peer == 'object'
|
|
||||||
return peer.name
|
|
||||||
return peer;
|
|
||||||
|
|
||||||
onChange: (ref) ->
|
onChange: (ref) ->
|
||||||
@props.setPeer ref.target.value
|
@props.setPeer ref.target.value
|
||||||
options: ->
|
options: ->
|
||||||
{ peer, peers } = @props
|
{ peer, peers } = @props
|
||||||
peerName = @extractName(peer)
|
if peer == '' or peers.includes(peer)
|
||||||
if peer == '' or peers.filter((t) -> t.name == peerName ).length > 0
|
|
||||||
[]
|
[]
|
||||||
else
|
else
|
||||||
re = new RegExp peerName
|
re = new RegExp peer
|
||||||
peers.filter (s) ->
|
peers.filter (s) ->
|
||||||
s.name.match(re) != null
|
s.match(re) != null
|
||||||
inputClass: (n) ->
|
inputClass: (n) ->
|
||||||
c = ['form-control', 'input-lg']
|
c = ['form-control', 'input-lg']
|
||||||
c.push 'active' if n > 0
|
c.push 'active' if n > 0
|
||||||
|
@ -72,15 +66,15 @@ Peer = React.createFactory React.createClass
|
||||||
input {
|
input {
|
||||||
className: @inputClass(options.length),
|
className: @inputClass(options.length),
|
||||||
onChange: @onChange,
|
onChange: @onChange,
|
||||||
placeholder: 'WiNA member',
|
placeholder: 'Zeus member',
|
||||||
type: 'text',
|
type: 'text',
|
||||||
value: (@extractName(@props.peer) || '')
|
value: (@props.peer || '')
|
||||||
}
|
}
|
||||||
if options.length != 0
|
if options.length != 0
|
||||||
div className: 'suggestions',
|
div className: 'suggestions',
|
||||||
@options().map (s, i) =>
|
@options().map (s, i) =>
|
||||||
div className: 'suggestion', key: i, onClick: @setPeer(s),
|
div className: 'suggestion', key: i, onClick: @setPeer(s),
|
||||||
s.name
|
s
|
||||||
|
|
||||||
Message = React.createFactory React.createClass
|
Message = React.createFactory React.createClass
|
||||||
onChange: (ref) ->
|
onChange: (ref) ->
|
||||||
|
@ -147,11 +141,11 @@ Step = React.createFactory React.createClass
|
||||||
return
|
return
|
||||||
|
|
||||||
if giving
|
if giving
|
||||||
debtor = user.username
|
debtor = user.name
|
||||||
creditor = peer.username
|
creditor = peer
|
||||||
else
|
else
|
||||||
debtor = peer.username
|
debtor = peer
|
||||||
creditor = user.username
|
creditor = user.name
|
||||||
|
|
||||||
$('<input />')
|
$('<input />')
|
||||||
.attr('name', 'transaction[debtor]')
|
.attr('name', 'transaction[debtor]')
|
||||||
|
@ -181,7 +175,7 @@ Step = React.createFactory React.createClass
|
||||||
unless message && message != ""
|
unless message && message != ""
|
||||||
errors['message'] = 'Please fill in a 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['peer'] = 'Please select a valid Zeus member.'
|
||||||
|
|
||||||
errors
|
errors
|
||||||
|
|
10
app/controllers/callbacks_controller.rb
Normal file
10
app/controllers/callbacks_controller.rb
Normal file
|
@ -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
|
|
@ -6,7 +6,7 @@ class TransactionsQuery
|
||||||
@transactions = Arel::Table.new(:transactions)
|
@transactions = Arel::Table.new(:transactions)
|
||||||
@perspectived = Arel::Table.new(:perspectived_transactions)
|
@perspectived = Arel::Table.new(:perspectived_transactions)
|
||||||
@peers = Arel::Table.new(:users).alias('peers')
|
@peers = Arel::Table.new(:users).alias('peers')
|
||||||
@arel_table = Arel::Table.new("#{@user.username}_transactions")
|
@arel_table = Arel::Table.new("#{@user.name}_transactions")
|
||||||
end
|
end
|
||||||
|
|
||||||
def query
|
def query
|
||||||
|
@ -16,7 +16,7 @@ class TransactionsQuery
|
||||||
|
|
||||||
def arel
|
def arel
|
||||||
Arel::Nodes::TableAlias.new(
|
Arel::Nodes::TableAlias.new(
|
||||||
issued_by(User),
|
issued_by(User).union(:all, issued_by(Client)),
|
||||||
arel_table.name
|
arel_table.name
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,8 +36,8 @@ class TransactionsController < ApplicationController
|
||||||
.permit(:debtor, :creditor, :message, :euros, :cents, :id_at_client)
|
.permit(:debtor, :creditor, :message, :euros, :cents, :id_at_client)
|
||||||
|
|
||||||
{
|
{
|
||||||
debtor: t[:debtor] ? User.find_by(username: t[:debtor]) : User.wina,
|
debtor: t[:debtor] ? User.find_or_create_by(name: t[:debtor]) : User.zeus,
|
||||||
creditor: t[:creditor] ? User.find_by(username: t[:creditor]) : User.wina,
|
creditor: t[:creditor] ? User.find_or_create_by(name: t[:creditor]) : User.zeus,
|
||||||
issuer: current_client || current_user,
|
issuer: current_client || current_user,
|
||||||
amount: (t[:euros].to_f * 100 + t[:cents].to_f).to_i,
|
amount: (t[:euros].to_f * 100 + t[:cents].to_f).to_i,
|
||||||
message: t[:message],
|
message: t[:message],
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Client < ActiveRecord::Base
|
||||||
has_many :issued_transactions, as: :issuer, class_name: 'Transaction'
|
has_many :issued_transactions, as: :issuer, class_name: 'Transaction'
|
||||||
before_create :generate_key
|
before_create :generate_key
|
||||||
|
|
||||||
validates :username, presence: true, uniqueness: true
|
validates :name, presence: true, uniqueness: true
|
||||||
|
|
||||||
private
|
private
|
||||||
def generate_key
|
def generate_key
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
include FriendlyId
|
include FriendlyId
|
||||||
friendly_id :name, use: :finders
|
friendly_id :name, use: :finders
|
||||||
devise :cas_authenticatable
|
devise :timeoutable, :omniauthable, :omniauth_providers => [:zeuswpi]
|
||||||
has_many :incoming_transactions,
|
has_many :incoming_transactions,
|
||||||
class_name: 'Transaction', foreign_key: 'creditor_id'
|
class_name: 'Transaction', foreign_key: 'creditor_id'
|
||||||
has_many :outgoing_transactions,
|
has_many :outgoing_transactions,
|
||||||
|
@ -28,7 +28,7 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
validates :name, presence: true, uniqueness: true
|
validates :name, presence: true, uniqueness: true
|
||||||
|
|
||||||
scope :humans, -> { where.not(id: self.wina) }
|
scope :humans, -> { where.not(id: self.zeus) }
|
||||||
|
|
||||||
def transactions
|
def transactions
|
||||||
Transaction.where("creditor_id = ? OR debtor_id = ?", id, id)
|
Transaction.where("creditor_id = ? OR debtor_id = ?", id, id)
|
||||||
|
@ -40,13 +40,14 @@ class User < ActiveRecord::Base
|
||||||
self.update_attribute :balance, balance
|
self.update_attribute :balance, balance
|
||||||
end
|
end
|
||||||
|
|
||||||
def cas_extra_attributes=(extra_attributes)
|
def self.from_omniauth(auth)
|
||||||
self.name = extra_attributes['display_name']
|
where(name: auth.uid).first_or_create do |user|
|
||||||
self.debt_allowed = extra_attributes['permissions'].include? 'HAVE_SCHULDEN'
|
user.name = auth.uid
|
||||||
self.penning = extra_attributes['permissions'].include? 'MANAGE_SCHULDEN'
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.wina
|
def self.zeus
|
||||||
@@wina ||= find_or_create_by name: 'WiNA', username: :WiNA
|
@@zeus ||= find_or_create_by name: 'Zeus'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
.card-wrapper
|
.card-wrapper
|
||||||
.card.padded
|
.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)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
.pure-u-1.pure-u-md-1-2
|
.pure-u-1.pure-u-md-1-2
|
||||||
%h2 Authentication
|
%h2 Authentication
|
||||||
%p Log een keer in en betaal uw schulden!
|
%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
|
.pure-u-1.pure-u-md-1-2
|
||||||
%h2 Pie of Shame
|
%h2 Pie of Shame
|
||||||
= pie_chart @statistics.shamehash
|
= pie_chart @statistics.shamehash
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
= render 'partials/form_errors', object: @transaction
|
= render 'partials/form_errors', object: @transaction
|
||||||
|
|
||||||
= form_for @transaction, remote: true, html: { class: "pure-form form-inline" } do |f|
|
= 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,
|
= 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 },
|
{ include_blank: true },
|
||||||
{ class: 'select2-selector', required: true, data: { placeholder: "Creditor", width: 150 } }
|
{ class: 'select2-selector', required: true, data: { placeholder: "Creditor", width: 150 } }
|
||||||
= f.text_field :message, placeholder: "Message", size: 75, class: "form-control", required: true
|
= f.text_field :message, placeholder: "Message", size: 75, class: "form-control", required: true
|
||||||
|
|
|
@ -42,13 +42,13 @@
|
||||||
.row
|
.row
|
||||||
.col-md-4
|
.col-md-4
|
||||||
.input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Issuer' }
|
.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 },
|
{ include_blank: true },
|
||||||
{ data: { placeholder: "Filter on Issuer", width: 265 }, class: "select2-selector form-control value-thing" }
|
{ data: { placeholder: "Filter on Issuer", width: 265 }, class: "select2-selector form-control value-thing" }
|
||||||
.col-md-4
|
.col-md-4
|
||||||
.input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Peer' }
|
.input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Peer' }
|
||||||
= select_tag nil,
|
= 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 }
|
include_blank: true, class: "select2-selector form-control value-thing", data: { placeholder: "Filter on Peer", width: 265 }
|
||||||
.col-md-4
|
.col-md-4
|
||||||
.input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Message' }
|
.input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Message' }
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
begin
|
||||||
|
load File.expand_path("../spring", __FILE__)
|
||||||
|
rescue LoadError
|
||||||
|
end
|
||||||
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
||||||
require_relative '../config/boot'
|
require_relative '../config/boot'
|
||||||
require 'rails/commands'
|
require 'rails/commands'
|
||||||
|
|
4
bin/rake
4
bin/rake
|
@ -1,4 +1,8 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
begin
|
||||||
|
load File.expand_path("../spring", __FILE__)
|
||||||
|
rescue LoadError
|
||||||
|
end
|
||||||
require_relative '../config/boot'
|
require_relative '../config/boot'
|
||||||
require 'rake'
|
require 'rake'
|
||||||
Rake.application.run
|
Rake.application.run
|
||||||
|
|
|
@ -4,9 +4,9 @@ Devise.setup do |config|
|
||||||
# The secret key used by Devise. Devise uses this key to generate
|
# The secret key used by Devise. Devise uses this key to generate
|
||||||
# random tokens. Changing this key will render invalid all existing
|
# random tokens. Changing this key will render invalid all existing
|
||||||
# confirmation, reset password and unlock tokens in the database.
|
# 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.
|
# by default. You can change it below and use your own secret key.
|
||||||
# config.secret_key = 'a53f0fd5c5917bd1c1453a26597c4b8767ec02ae7e716f2c5513c389b5441a2a5fdd3ed82561f29579f05c6d2242979cbc7836d63bb1f38e1ab6f2c2d8ccc934'
|
# config.secret_key = 'db9dcc69d4370aba9151d435032f8263c40b2536a288267af3878a16df4b9d9f8e509f7671a39c534d0ac663f6fb9d3a879cdea867dc73053c97b36406e0a9e9'
|
||||||
|
|
||||||
# ==> Mailer Configuration
|
# ==> Mailer Configuration
|
||||||
# Configure the e-mail address which will be shown in Devise::Mailer,
|
# 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.
|
# Configure the class responsible to send e-mails.
|
||||||
# config.mailer = 'Devise::Mailer'
|
# config.mailer = 'Devise::Mailer'
|
||||||
|
|
||||||
# Configure the parent class responsible to send e-mails.
|
|
||||||
# config.parent_mailer = 'ActionMailer::Base'
|
|
||||||
|
|
||||||
# ==> ORM configuration
|
# ==> ORM configuration
|
||||||
# Load and configure the ORM. Supports :active_record (default) and
|
# Load and configure the ORM. Supports :active_record (default) and
|
||||||
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
# :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.
|
# from the server. You can disable this option at your own risk.
|
||||||
# config.clean_up_csrf_token_on_authentication = true
|
# 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
|
# ==> Configuration for :database_authenticatable
|
||||||
# For bcrypt, this is the cost for hashing the password and defaults to 11. If
|
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
||||||
# using other algorithms, it sets how many times you want the password to be hashed.
|
# 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
|
# 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
|
# 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
|
# 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).
|
# 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.
|
# Setup a pepper to generate the encrypted password.
|
||||||
# config.pepper = 'c664e685c6d19495baa24a50ea811daca5acc07987f86748699ccc1f31dcae70b39744352188041ea10428d923ef58228fb93c829672e2065be91784909dd2d5'
|
# config.pepper = '6246d8fa4efd376623925a6d8600b268d11ce906a667d550663fe069dbe249bd11c0f26329c1d61f58fa9a615ee738d5b0feba189b6fdc390662e45b7a39c476'
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# ==> Configuration for :confirmable
|
# ==> Configuration for :confirmable
|
||||||
# A period that the user is allowed to access the website even without
|
# A period that the user is allowed to access the website even without
|
||||||
|
@ -157,12 +142,12 @@ Devise.setup do |config|
|
||||||
|
|
||||||
# ==> Configuration for :validatable
|
# ==> Configuration for :validatable
|
||||||
# Range for password length.
|
# 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
|
# Email regex used to validate email formats. It simply asserts that
|
||||||
# one (and only one) @ exists in the given string. This is mainly
|
# one (and only one) @ exists in the given string. This is mainly
|
||||||
# to give user feedback and not to assert the e-mail validity.
|
# 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
|
# ==> Configuration for :timeoutable
|
||||||
# The time you want to timeout the user session without activity. After this
|
# 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
|
# config.sign_in_after_reset_password = true
|
||||||
|
|
||||||
# ==> Configuration for :encryptable
|
# ==> Configuration for :encryptable
|
||||||
# Allow you to use another hashing or encryption algorithm besides bcrypt (default).
|
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
||||||
# You can use :sha1, :sha512 or algorithms from others authentication tools as
|
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
||||||
# :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
|
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
|
||||||
# for default behavior) and :restful_authentication_sha1 (then you should set
|
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
|
||||||
# stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
|
# REST_AUTH_SITE_KEY to pepper).
|
||||||
#
|
#
|
||||||
# Require the `devise-encryptable` gem when using anything other than bcrypt
|
# Require the `devise-encryptable` gem when using anything other than bcrypt
|
||||||
# config.encryptor = :sha512
|
# config.encryptor = :sha512
|
||||||
|
@ -250,7 +235,7 @@ Devise.setup do |config|
|
||||||
# ==> OmniAuth
|
# ==> OmniAuth
|
||||||
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
||||||
# up on your models and hooks.
|
# 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
|
# ==> Warden configuration
|
||||||
# If you want to use other strategies, that are not supported by Devise, or
|
# 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,
|
# When using OmniAuth, Devise cannot automatically set OmniAuth path,
|
||||||
# so you need to do it manually. For the users scope, it would be:
|
# so you need to do it manually. For the users scope, it would be:
|
||||||
# config.omniauth_path_prefix = '/my_engine/users/auth'
|
# 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
|
end
|
||||||
|
|
38
config/initializers/zeuswpi.rb
Normal file
38
config/initializers/zeuswpi.rb
Normal file
|
@ -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
|
|
@ -1,5 +1,7 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
devise_for :users
|
devise_for :users, controllers: {
|
||||||
|
omniauth_callbacks: 'callbacks'
|
||||||
|
}
|
||||||
|
|
||||||
devise_scope :user do
|
devise_scope :user do
|
||||||
delete '/sign_out', to: 'devise/sessions#destroy'
|
delete '/sign_out', to: 'devise/sessions#destroy'
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
class DeviseCreateUsers < ActiveRecord::Migration
|
class DeviseCreateUsers < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
create_table(:users) do |t|
|
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.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.boolean :penning, null: false, default: false
|
||||||
|
|
||||||
t.timestamps null: false
|
t.timestamps null: false
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class CreateClients < ActiveRecord::Migration
|
class CreateClients < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
create_table :clients do |t|
|
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.string :key, null: false, index: true, unique: true
|
||||||
|
|
||||||
t.timestamps null: false
|
t.timestamps null: false
|
||||||
|
|
18
db/schema.rb
18
db/schema.rb
|
@ -14,14 +14,14 @@
|
||||||
ActiveRecord::Schema.define(version: 20170123151219) do
|
ActiveRecord::Schema.define(version: 20170123151219) do
|
||||||
|
|
||||||
create_table "clients", force: :cascade do |t|
|
create_table "clients", force: :cascade do |t|
|
||||||
t.string "username", null: false
|
t.string "name", null: false
|
||||||
t.string "key", null: false
|
t.string "key", null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "clients", ["key"], name: "index_clients_on_key"
|
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|
|
create_table "clients_roles", id: false, force: :cascade do |t|
|
||||||
t.integer "client_id"
|
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"
|
add_index "transactions", ["issuer_type", "issuer_id"], name: "index_transactions_on_issuer_type_and_issuer_id"
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "username"
|
t.string "name"
|
||||||
t.integer "balance", default: 0, null: false
|
t.integer "balance", default: 0, null: false
|
||||||
t.string "name", null: false
|
t.boolean "penning", default: false, null: false
|
||||||
t.boolean "debt_allowed", default: false, null: false
|
t.datetime "created_at", null: false
|
||||||
t.boolean "penning", default: false, null: false
|
t.datetime "updated_at", null: false
|
||||||
t.datetime "created_at", null: false
|
|
||||||
t.datetime "updated_at", null: false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "users", ["balance"], name: "index_users_on_balance"
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue