thincloud-authentication 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -82,6 +82,16 @@ Thincloud::Authentication.configure do |config|
82
82
  end
83
83
  ```
84
84
 
85
+ ### Cookies
86
+
87
+ Set the `cookie_options` option to customize the options that get passed to the authentication cookies:
88
+
89
+ ```ruby
90
+ Thincloud::Authentication.configure do |config|
91
+ config.cookie_options = { secure: true, domain: :all }
92
+ end
93
+ ```
94
+
85
95
 
86
96
  ### Additional provider strategies
87
97
 
@@ -146,10 +156,20 @@ You can customize the paths used to redirect users after login, logout, registra
146
156
  * `after_logout_path` is used after the user logs out.
147
157
  * `after_registration_path` is used after the user registers.
148
158
  * `after_verification_path` is used after the user verifies their email.
159
+ * `after_password_update_path` is used after the user updates their password.
160
+
161
+ ### Working with Identities
162
+
163
+ Thincloud Authentication provides a few service objects to assist with creating and updating Identities:
164
+
165
+ * `CreateInvitationForUser.call(user, name: "Test Name", email: "test@test.com")` is used to create a new Identity for a user and send an email with an invitation URL which allows the user to choose a password.
166
+ * `UpdateIdentityPassword.call(identity, password: "s3kr1tz!", password_confirmation: "s3kr1tz!")` is used to update the password for an existing Identity.
167
+
168
+ Both of the methods above will return `true` or `false`.
169
+
149
170
 
150
171
  ## TODO
151
172
 
152
- * Add "forgot password" functionality
153
173
  * Add multiple, configurable strategy options
154
174
  * Add a configuration option to customize the mailers
155
175
 
@@ -0,0 +1,12 @@
1
+ module Thincloud::Authentication
2
+ # Public: Email methods for sending invitations
3
+ class InvitationsMailer < ActionMailer::Base
4
+ default from: Thincloud::Authentication.configuration.mailer_sender
5
+
6
+ # New invitation notification
7
+ def new_invitation(identity_id)
8
+ @identity = Identity.find(identity_id)
9
+ mail to: @identity.email, subject: "New account invitation"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ module Thincloud::Authentication
2
+ # Public: Execute the workflow steps to create and identity and send an
3
+ # invitation email
4
+ class CreateInvitationForUser
5
+
6
+ def self.call(user, params)
7
+ identity = Identity.create!(user: user, name: params[:name],
8
+ email: params[:email], password_digest: 0)
9
+ Identity.verify!(identity.verification_token)
10
+ identity.generate_password_token!
11
+ InvitationsMailer.new_invitation(identity.id).deliver
12
+ true
13
+ rescue ActiveRecord::RecordInvalid
14
+ false
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ To accept the invitation and choose a password, click the URL below.
2
+
3
+ <%= invitation_url(@identity.password_reset_token) %>
data/config/routes.rb CHANGED
@@ -11,6 +11,7 @@ Thincloud::Authentication::Engine.routes.draw do
11
11
  get "verify/:token", to: "registrations#verify", as: "verify_token"
12
12
 
13
13
  resources :passwords, only: [:new, :edit, :create, :update]
14
+ get "invitations/:id", to: "passwords#edit", as: "invitation"
14
15
 
15
16
  root to: "sessions#new"
16
17
  end
@@ -52,7 +52,7 @@ module Thincloud
52
52
  value: user.id,
53
53
  secure: request.ssl?,
54
54
  httponly: true
55
- }
55
+ }.merge(Thincloud::Authentication.configuration.cookie_options)
56
56
  end
57
57
 
58
58
  # Protected: Clear the session of an authenticated user.
@@ -11,12 +11,13 @@ module Thincloud
11
11
 
12
12
  # Public: Configuration options for the Thincloud::Authentication module
13
13
  class Configuration
14
- attr_accessor :layout, :providers, :mailer_sender
14
+ attr_accessor :layout, :providers, :mailer_sender, :cookie_options
15
15
 
16
16
  def initialize
17
17
  @layout = "application"
18
18
  @providers = {}
19
19
  @mailer_sender = "app@example.com"
20
+ @cookie_options = {}
20
21
  end
21
22
  end
22
23
  end
@@ -1,5 +1,5 @@
1
1
  module Thincloud
2
2
  module Authentication
3
- VERSION = "0.5.1"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thincloud-authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-05-06 00:00:00.000000000 Z
13
+ date: 2013-05-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -106,11 +106,14 @@ files:
106
106
  - app/controllers/thincloud/authentication/registrations_controller.rb
107
107
  - app/controllers/thincloud/authentication/sessions_controller.rb
108
108
  - app/helpers/thincloud/authentication/registrations_helper.rb
109
+ - app/mailers/thincloud/authentication/invitations_mailer.rb
109
110
  - app/mailers/thincloud/authentication/passwords_mailer.rb
110
111
  - app/mailers/thincloud/authentication/registrations_mailer.rb
111
112
  - app/models/thincloud/authentication/identity.rb
113
+ - app/services/thincloud/authentication/create_invitation_for_user.rb
112
114
  - app/services/thincloud/authentication/password_reset_workflow.rb
113
115
  - app/services/thincloud/authentication/update_identity_password.rb
116
+ - app/views/thincloud/authentication/invitations_mailer/new_invitation.html.erb
114
117
  - app/views/thincloud/authentication/layouts/application.html.erb
115
118
  - app/views/thincloud/authentication/passwords/edit.html.erb
116
119
  - app/views/thincloud/authentication/passwords/new.html.erb
@@ -147,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
150
  version: '0'
148
151
  segments:
149
152
  - 0
150
- hash: 3741516582425724511
153
+ hash: 2368003791290441844
151
154
  required_rubygems_version: !ruby/object:Gem::Requirement
152
155
  none: false
153
156
  requirements:
@@ -156,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
159
  version: '0'
157
160
  segments:
158
161
  - 0
159
- hash: 3741516582425724511
162
+ hash: 2368003791290441844
160
163
  requirements: []
161
164
  rubyforge_project:
162
165
  rubygems_version: 1.8.23