jobshop 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eda45d633fbb49843d85a4afec86b54c411fba69
4
- data.tar.gz: 1ca319d1f6b37819a8fb7587498accfa45b819a7
3
+ metadata.gz: b40482d948a58938955b3133971e53032caa54fb
4
+ data.tar.gz: fadf4c7b7f987f810b732a1eeded4ca4edaf2be7
5
5
  SHA512:
6
- metadata.gz: 7f68c57b8e7808d56eb8e9c52885f73da50cf483a3922b8b012dd45c86133eb421f6a283296bc5f71acd440e7149dffd3d5812be50bdcaa73f62b84a0b883679
7
- data.tar.gz: 97d5080e9c135d8cc52f2b7752d2316b96d4bbecdf7bd0969df3829c77e201d3f51e47c57851d6c0d46261c13873b1d4dcf984db56f6ebc57d4904ca40e7b914
6
+ metadata.gz: ca99cbcb216815970ea4111c708c74450f49942c536ff14953c6f7c78f2d465dbb9bb4c6e1163823a1fe4aa81ee1fe482743d2539eeb3605c84d919e4ea0c5cf
7
+ data.tar.gz: 550c1aa4d0e8ac61a9e38b2c5742200f49d1ba819b8f9750f805941036b0f18ebb2914b879d8d1cd0e4c9c7e520e93ce7ae3ff05712a407b6753e1f38445d247
@@ -10,8 +10,8 @@ html, body {
10
10
  font-family: "Roboto", "Helvetica", sans-serif;
11
11
  }
12
12
 
13
- html { height: 100% }
14
- body { min-height: 100%; }
13
+ html { height: 100%; }
14
+ body { min-height: 100%; margin: 0 auto; }
15
15
 
16
16
  main {
17
17
  display: flex;
@@ -22,7 +22,6 @@ main {
22
22
  #register {
23
23
  @extend .mdl-shadow--2dp;
24
24
 
25
- margin: 1rem;
26
25
  width: 100%;
27
26
 
28
27
  @include tablet-up {
@@ -1,3 +1,7 @@
1
+ # Parts of this class borrowed from:
2
+ # https://gist.github.com/josevalim/fb706b1e933ef01e4fb6
3
+ # Thank you Jose Valim!
4
+
1
5
  module Jobshop
2
6
  class ApplicationController < ActionController::Base
3
7
  include Pundit
@@ -6,10 +10,25 @@ module Jobshop
6
10
 
7
11
  protect_from_forgery
8
12
 
13
+ before_action :authenticate_user_from_email!
9
14
  before_action :authenticate_user!
10
15
 
11
- # after_action :verify_authorized, except: :index
12
- # after_action :verify_policy_scoped, :only => :index
16
+ # after_action :verify_authorized, except: :index
17
+ # after_action :verify_policy_scoped, :only => :index
18
+
19
+ private
20
+
21
+ def authenticate_user_from_email!
22
+ token = EmailAuthenticationToken.new(
23
+ params.fetch(:user_email, nil),
24
+ params.fetch(:email_authentication_token, nil)
25
+ )
26
+
27
+ if token.valid?
28
+ sign_in token.user
29
+ token.destroy
30
+ end
31
+ end
13
32
 
14
33
  def layout_for_application
15
34
  if devise_controller? && controller_name == "sessions" ||
@@ -20,5 +39,46 @@ module Jobshop
20
39
  "jobshop/application"
21
40
  end
22
41
  end
42
+
43
+ class EmailAuthenticationToken
44
+ attr_reader :token
45
+
46
+ def initialize(email, token)
47
+ @email = email
48
+ @token = token
49
+ end
50
+
51
+ def valid?
52
+ user && token && !expired? && secure_compare
53
+ end
54
+
55
+ def user
56
+ @user ||= Jobshop::User.where(email: @email)
57
+ .where.not(email_authentication_token_sent_at: nil).first
58
+ end
59
+
60
+ def destroy
61
+ user.update({
62
+ email_authentication_token: nil,
63
+ email_authentication_token_sent_at: nil
64
+ })
65
+ end
66
+
67
+ def secure_compare
68
+ # Notice how we use Devise.secure_compare to compare the token in the
69
+ # database with the token given in the params, mitigating timing
70
+ # attacks.
71
+ Devise.secure_compare(user.email_authentication_token, token)
72
+ end
73
+
74
+ def expired?
75
+ @expired ||= Time.now >= expires_on
76
+ end
77
+
78
+ def expires_on
79
+ # TODO: Make token expiration configurable in initializers/jobshop.rb.
80
+ @expires_on ||= user.email_authentication_token_sent_at + 6.hours
81
+ end
82
+ end
23
83
  end
24
84
  end
@@ -9,7 +9,20 @@ module Jobshop
9
9
  end
10
10
 
11
11
  def create
12
- # noop
12
+ email_addresses = params[:user][:email].split(",").map(&:strip).take(5)
13
+
14
+ @lookup = Jobshop::User
15
+ .where(email: email_addresses)
16
+ .joins(:team)
17
+ .select("jobshop_users.id AS id",
18
+ "email",
19
+ "jobshop_teams.name AS team_name")
20
+ .group_by(&:email)
21
+
22
+ @lookup.each_pair do |email, teams|
23
+ Jobshop::TeamsMailer.found_teams(email, teams).deliver_later
24
+ end
25
+
13
26
  redirect_to new_user_session_path
14
27
  end
15
28
  end
@@ -0,0 +1,8 @@
1
+ module Jobshop
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: "jobshop-teams-lookup@example.com"
4
+
5
+ layout "jobshop/mailer"
6
+ end
7
+ end
8
+
@@ -0,0 +1,10 @@
1
+ module Jobshop
2
+ class TeamsMailer < ApplicationMailer
3
+ def found_teams(email, teams)
4
+ @email = email
5
+ @teams = teams
6
+
7
+ mail(to: @email, subject: "We found your Jobshop Teams!")
8
+ end
9
+ end
10
+ end
@@ -2,11 +2,18 @@ module Jobshop
2
2
  class User < ApplicationRecord
3
3
  # Include default devise modules. Others available are:
4
4
  # :confirmable, :lockable, :timeoutable and :omniauthable
5
- devise :database_authenticatable, :recoverable, :rememberable, :validatable
5
+ devise :database_authenticatable, :recoverable, :rememberable
6
6
 
7
7
  belongs_to :team, optional: true
8
8
  has_one :default_dashboard, class_name: "Jobshop::Dashboard", through: :team
9
9
 
10
- validates_uniqueness_of :email
10
+ private
11
+
12
+ def generate_email_authentication_token
13
+ loop do
14
+ token = Devise.friendly_token
15
+ break token unless Jobshop::User.where(email_authentication_token: token).first
16
+ end
17
+ end
11
18
  end
12
19
  end
@@ -0,0 +1,7 @@
1
+ Hi <%= @email %>,
2
+
3
+ We found the following teams linked to your email address:
4
+
5
+ <% @teams.each do |team| %>
6
+ You belong to: <%= team.team_name %>
7
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -1,7 +1,7 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
3
  # Version of your assets, change this if you want to expire all your assets.
4
- Rails.application.config.assets.version = '3.0'
4
+ Rails.application.config.assets.version = "4"
5
5
 
6
6
  # Add additional assets to the asset load path
7
7
  # Rails.application.config.assets.paths << Emoji.images_path
@@ -0,0 +1,6 @@
1
+ class ReindexJobshopUsersByEmailAndTeamId < ActiveRecord::Migration[5.0]
2
+ def change
3
+ remove_index :jobshop_users, :email
4
+ add_index :jobshop_users, [ :email, :team_id ], unique: true
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ class AddAuthenticationTokenToJobshopUsers < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :jobshop_users, :email_authentication_token, :string
4
+ add_column :jobshop_users, :email_authentication_token_sent_at, :datetime
5
+ end
6
+ end
@@ -22,6 +22,14 @@ unless Dir.exist?("db/migrate")
22
22
  Dir.mkdir("db/migrate")
23
23
  end
24
24
 
25
+ # Mailer previews don't really play nice with Engines so in the dummy app we
26
+ # create an initializer to expose them properly.
27
+ initializer "expose_mailer_previews.rb", <<-INITIALIZER.strip_heredoc
28
+ Rails.application.configure do
29
+ config.action_mailer.preview_path = "#{Jobshop::Engine.root}/spec/mailers"
30
+ end
31
+ INITIALIZER
32
+
25
33
  route "mount Jobshop::Engine => \"/\""
26
34
 
27
35
  rake "db:create"
@@ -6,7 +6,7 @@ module Jobshop
6
6
  module VERSION
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
- TINY = 14
9
+ TINY = 15
10
10
  PRE = nil
11
11
 
12
12
  CODE_NAME = "bump it up".freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jobshop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank J. Mattia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-13 00:00:00.000000000 Z
11
+ date: 2016-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coffee-rails
@@ -328,6 +328,8 @@ files:
328
328
  - app/controllers/jobshop/teams_controller.rb
329
329
  - app/helpers/jobshop/application_helper.rb
330
330
  - app/jobs/jobshop/application_job.rb
331
+ - app/mailers/jobshop/application_mailer.rb
332
+ - app/mailers/jobshop/teams_mailer.rb
331
333
  - app/models/jobshop/application_record.rb
332
334
  - app/models/jobshop/dashboard.rb
333
335
  - app/models/jobshop/registration.rb
@@ -350,7 +352,9 @@ files:
350
352
  - app/views/jobshop/dashboards/show.html.haml
351
353
  - app/views/jobshop/teams/lookups/show.html.haml
352
354
  - app/views/jobshop/teams/registrations/new.html.haml
355
+ - app/views/jobshop/teams_mailer/found_teams.text.erb
353
356
  - app/views/layouts/jobshop/application.html.haml
357
+ - app/views/layouts/jobshop/mailer.text.erb
354
358
  - app/views/layouts/jobshop/unauthenticated.html.haml
355
359
  - config/initializers/assets.rb
356
360
  - config/initializers/devise.rb
@@ -365,6 +369,8 @@ files:
365
369
  - db/migrate/20160323132658_rename_configuration_token_to_registration_token.rb
366
370
  - db/migrate/20160417210218_create_jobshop_dashboards.rb
367
371
  - db/migrate/20160425062447_rename_site_to_team.rb
372
+ - db/migrate/20160718130211_reindex_jobshop_users_by_email_and_team_id.rb
373
+ - db/migrate/20160720201947_add_authentication_token_to_jobshop_users.rb
368
374
  - db/migrate/keep
369
375
  - lib/generators/jobshop/config/config_generator.rb
370
376
  - lib/generators/jobshop/config/templates/jobshop.rb.tt