jobshop 0.0.4.1p4 → 0.0.4.2p4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 904a781e3363d2f512cf2a6f9af9cfb39ad9fd52
4
- data.tar.gz: 4b1aadcd942649c6ec69640273e8077830a30391
3
+ metadata.gz: ebd478bfbc679ef91271554cd5a9f8c0bd12475d
4
+ data.tar.gz: 81649a0c32fbfe838c26046da849bd94ad8d08db
5
5
  SHA512:
6
- metadata.gz: ee19af19af5f160dd8c6bd1ebd3ad75c7d933347bdbc0feba68143eb7e051f99dc736b28386230e3a1292d81c4a86f3080189ac40a733a80b4c47b9e413ba235
7
- data.tar.gz: da847d8e47e6398c55897835fcccc225cd8c80065a3e96746c31cd71a57027319e27495f32d6755fb875516014d7d4a62606cda15fa58eb389c558282d560993
6
+ metadata.gz: c1df82ba9a8337d6f4262bc3c3c093fc4581e0c402c7b15713b334d4b358214aa1bad765b0c5274c67ddfee9fe4131689d772e442a3002ebd2be9f91232cd6bf
7
+ data.tar.gz: 69071e78619c4e6d17d141cd00b89a7032a61d1201b915ed617071143d0337a281b6f6334cb750993c52f6a542ec6a5910313bad1e5ca83963dcd0512798523f
@@ -0,0 +1,25 @@
1
+ module RegistrationTokenValidation
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ before_action :validate_registration_token!
6
+ end
7
+
8
+ def validate_registration_token!
9
+ redirect_to new_user_session_path unless token_present_and_resolves?
10
+ end
11
+
12
+ def token_present_and_resolves?
13
+ params[:registration_token].present? && registration_token_resolves?
14
+ end
15
+
16
+ def registration_token_resolves?
17
+ encrypted_token = Devise.token_generator.digest(
18
+ Jobshop::Site, :registration_token, params[:registration_token])
19
+
20
+ configurable = Jobshop::Site.find_by(
21
+ id: params[:site_id], registration_token: encrypted_token)
22
+
23
+ configurable && configurable.registration_token_period_valid?
24
+ end
25
+ end
@@ -13,10 +13,5 @@ module Jobshop
13
13
  # flash[:alert] = "Please sign in."
14
14
  # redirect_to(request.referrer || main_app.root_path)
15
15
  # end
16
-
17
- def pundit_user
18
- # raise Jobshop::NoCurrentUserMethodError unless respond_to?(:current_user)
19
- # current_user
20
- end
21
16
  end
22
17
  end
@@ -0,0 +1,6 @@
1
+ require_dependency "jobshop/application_controller"
2
+
3
+ module Jobshop
4
+ class DashboardsController < ApplicationController
5
+ end
6
+ end
@@ -2,31 +2,22 @@ require_dependency "jobshop/application_controller"
2
2
 
3
3
  module Jobshop
4
4
  class Sites::RegistrationsController < ApplicationController
5
- before_action :authenticate_user!, unless: :configure_by_token?, only: :new
5
+ include RegistrationTokenValidation
6
6
 
7
7
  def new
8
- @site = Jobshop::Site.find(params[:site_id])
9
- authenticate_user! if @site.owner
10
8
  @registration = Jobshop::Registration.new(params)
9
+ authenticate_user! if @registration.site.owner
11
10
  end
12
11
 
13
- protected
14
-
15
- def configure_by_token?
16
- @configure_by_token ||= params[:configuration_token].present? &&
17
- configuration_token_valid?
18
- end
19
-
20
- def configuration_token_valid?
21
- @configuration_token_valid ||= begin
22
- encrypted_configuration_token = Devise.token_generator.digest(
23
- Jobshop::Site, :configuration_token, params[:configuration_token])
24
-
25
- configurable = Jobshop::Site.find_by(
26
- configuration_token: encrypted_configuration_token)
12
+ def create
13
+ @registration = Jobshop::Registration.new(params)
27
14
 
28
- configurable && configurable.configuration_token_period_valid?
15
+ if @registration.save
16
+ sign_in_and_redirect(@registration.user)
17
+ else
18
+ render(:new)
29
19
  end
30
20
  end
31
21
  end
32
22
  end
23
+
@@ -0,0 +1,37 @@
1
+ module Jobshop
2
+ class Registration < VirtualRecord
3
+ memo_attr(:user) { site.users.build(user_params) }
4
+ memo_attr(:site) {
5
+ record = Jobshop::Site.find(params[:site_id])
6
+ record.assign_attributes(site_params)
7
+ record
8
+ }
9
+
10
+ def save
11
+ return false unless valid?
12
+
13
+ result = ActiveRecord::Base.transaction do
14
+ user.save!
15
+ site.update!(owner: user)
16
+ end
17
+
18
+ result != false
19
+ end
20
+
21
+ private
22
+
23
+ def registration_params
24
+ params.fetch(:registration, ActionController::Parameters.new)
25
+ end
26
+
27
+ def site_params
28
+ registration_params.fetch(
29
+ :site, ActionController::Parameters.new).permit(:name)
30
+ end
31
+
32
+ def user_params
33
+ registration_params.fetch(:user, ActionController::Parameters.new).
34
+ permit(:email, :password, :password_confirmation)
35
+ end
36
+ end
37
+ end
@@ -3,19 +3,20 @@ module Jobshop
3
3
  belongs_to :owner, class_name: "Jobshop::User"
4
4
  has_many :users, class_name: "Jobshop::User"
5
5
 
6
- def generate_configuration_token
7
- raw, encrypted = Devise.token_generator.generate(self.class, :configuration_token)
6
+ def generate_registration_token
7
+ raw, encrypted = Devise.token_generator.generate(
8
+ self.class, :registration_token)
8
9
 
9
- self.configuration_token = encrypted
10
- self.configuration_token_sent_at = Time.now.utc
10
+ self.registration_token = encrypted
11
+ self.registration_token_sent_at = Time.now.utc
11
12
  self.save(validate: false)
12
13
 
13
14
  raw
14
15
  end
15
16
 
16
- def configuration_token_period_valid?
17
- configuration_token_sent_at &&
18
- configuration_token_sent_at.utc >= 30.minutes.ago.utc
17
+ def registration_token_period_valid?
18
+ registration_token_sent_at &&
19
+ registration_token_sent_at.utc >= 30.minutes.ago.utc
19
20
  end
20
21
  end
21
22
  end
@@ -5,5 +5,7 @@ module Jobshop
5
5
  devise :database_authenticatable, :recoverable, :rememberable, :validatable
6
6
 
7
7
  belongs_to :site
8
+
9
+ validates_uniqueness_of :email
8
10
  end
9
11
  end
@@ -1,7 +1,7 @@
1
1
  require "jobshop/support/memo_attr"
2
2
 
3
3
  module Jobshop
4
- class ApplicationResource
4
+ class VirtualRecord
5
5
  include ActiveModel::Model
6
6
  include MemoAttr
7
7
 
@@ -0,0 +1 @@
1
+ %h1 Welcome aboard!
@@ -5,12 +5,15 @@
5
5
  %section
6
6
  = form_for @registration, url: site_registration_path(@registration.site) do |f|
7
7
  .card-content
8
+ = hidden_field_tag(:registration_token, params[:registration_token])
8
9
  %h1.center Getting Started
9
10
 
10
- %br
11
+ - if @registration.errors.present?
12
+ %p.error try again
13
+
11
14
  = f.fields_for(@registration.site) do |site_f|
12
15
  %ul.input-field
13
- %li= site_f.label(:name, "Organization") + site_f.text_field(:name)
16
+ %li= site_f.label(:name, "Organization Name") + site_f.text_field(:name)
14
17
 
15
18
  = f.fields_for(@registration.user) do |user_f|
16
19
  %ul.input-field
data/config/routes.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  Jobshop::Engine.routes.draw do
2
2
  devise_for :users, class_name: "Jobshop::User", module: :devise
3
3
 
4
- resources :sites, only: [ :edit ] do
4
+ get "/dashboard", to: "dashboards#show", as: :user_root
5
+
6
+ resources :sites, only: [ ] do
5
7
  resource :registration, only: [ :new, :create ],
6
8
  controller: "sites/registrations"
7
9
  end
@@ -0,0 +1,9 @@
1
+ class RenameConfigurationTokenToRegistrationToken < ActiveRecord::Migration[5.0]
2
+ def change
3
+ rename_column :jobshop_sites, :configuration_token, :registration_token
4
+ rename_column :jobshop_sites, :configuration_token_sent_at,
5
+ :registration_token_sent_at
6
+
7
+ add_index :jobshop_sites, [ "registration_token" ], unique: true
8
+ end
9
+ end
@@ -22,10 +22,10 @@ module Jobshop
22
22
  end
23
23
 
24
24
  def generate_token
25
- @token = site.generate_configuration_token
25
+ @token = site.generate_registration_token
26
26
  end
27
27
 
28
- def generate_secure_configuration_link
28
+ def generate_secure_registration_link
29
29
  link_protocol = Rails.env.development? ? "http" : "https"
30
30
  link_host = Rails.env.development? ? "localhost:3000" : "YOUR-HOST-NAME"
31
31
  # TODO: Give environments besides development a decent host and
@@ -35,11 +35,11 @@ module Jobshop
35
35
  new_site_registration_url(@site,
36
36
  protocol: link_protocol,
37
37
  host: link_host,
38
- configuration_token: @token
38
+ registration_token: @token
39
39
  )
40
40
  end
41
41
 
42
- def print_secure_configuration_link
42
+ def print_secure_registration_link
43
43
  say <<-MESSAGE
44
44
  ### JOBSHOP - IMPORTANT INFORMATION ############################################
45
45
 
@@ -7,7 +7,7 @@ module Jobshop
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
9
  TINY = 4
10
- PRE = "1p4"
10
+ PRE = "2p4"
11
11
 
12
12
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jobshop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.1p4
4
+ version: 0.0.4.2p4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank J. Mattia
@@ -304,18 +304,21 @@ files:
304
304
  - app/assets/stylesheets/jobshop/generics.scss
305
305
  - app/assets/stylesheets/jobshop/material-icons.scss
306
306
  - app/assets/stylesheets/jobshop/site/configuration.scss
307
+ - app/controllers/concerns/registration_token_validation.rb
307
308
  - app/controllers/jobshop/application_controller.rb
309
+ - app/controllers/jobshop/dashboards_controller.rb
308
310
  - app/controllers/jobshop/pages_controller.rb
309
311
  - app/controllers/jobshop/sites/registrations_controller.rb
310
312
  - app/controllers/jobshop/sites_controller.rb
311
313
  - app/helpers/jobshop/application_helper.rb
312
314
  - app/jobs/jobshop/application_job.rb
313
- - app/models/application_record.rb
315
+ - app/models/jobshop/application_record.rb
316
+ - app/models/jobshop/registration.rb
314
317
  - app/models/jobshop/site.rb
315
318
  - app/models/jobshop/user.rb
319
+ - app/models/jobshop/virtual_record.rb
316
320
  - app/policies/jobshop/application_policy.rb
317
- - app/resources/jobshop/application_resource.rb
318
- - app/resources/jobshop/registration.rb
321
+ - app/views/jobshop/dashboards/show.html.haml
319
322
  - app/views/jobshop/pages/index.html.haml
320
323
  - app/views/jobshop/sites/registrations/new.html.haml
321
324
  - app/views/layouts/jobshop/application.html.haml
@@ -329,6 +332,7 @@ files:
329
332
  - db/migrate/20160321212058_add_site_id_to_users.rb
330
333
  - db/migrate/20160321213638_add_foreign_key_for_site.rb
331
334
  - db/migrate/20160322040604_add_owner_id_to_sites.rb
335
+ - db/migrate/20160323132658_rename_configuration_token_to_registration_token.rb
332
336
  - db/migrate/keep
333
337
  - lib/generators/jobshop/config/config_generator.rb
334
338
  - lib/generators/jobshop/config/templates/jobshop.rb.tt
@@ -1,26 +0,0 @@
1
- module Jobshop
2
- class Registration < Jobshop::ApplicationResource
3
- memo_attr(:user) { site.users.build(user_params) }
4
- memo_attr(:site) { Jobshop::Site.find(params[:site_id]) }
5
-
6
- def save
7
- return false unless valid?
8
-
9
- result = ActiveRecord::Base.transaction do
10
- user.save!
11
- site.update!(owner: user)
12
- end
13
-
14
- result != false
15
- end
16
-
17
- private
18
- def site_params
19
- params.fetch(:site, ActionController::Parameters.new).permit(:name)
20
- end
21
-
22
- def user_params
23
- params.fetch(:user, ActionController::Parameters.new).permit(:email, :password, :password_confirmation)
24
- end
25
- end
26
- end