simply_auth 0.4.0 → 0.5.0

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: 1708669fe57a25f6504a5453fa443ec069d89d43
4
- data.tar.gz: 8827d47aee99628c8af6f7ea66d60c114b4c7093
3
+ metadata.gz: 5d9ba7185d95620632bf2d1ab1e5ccf4f1af9a82
4
+ data.tar.gz: e1a34f65489e3a60e296b644e736ca3a920afa4a
5
5
  SHA512:
6
- metadata.gz: dde691af02f93c295f2d75317c070aa3f0d235e55e58b497ec5c0cbe8dd8a7791a4535ac3a77569e2c2766107f31bc85ad92194eb106689d8a8cb0110d5036cd
7
- data.tar.gz: 4e9c5e11b31351082c0fd70b882e08fe5414fcb90c25e19ce95d0648bec49f7d9916c0486beb653ac6d48fa8006719fc91999663b18a59860b4fb5bc8cf3417c
6
+ metadata.gz: d37ce6d128b3bfee0e692ddaddf27663fc22a5b99a51e2c806898e613862b4b8c0634d70f606d76afce78937fa81f148e3d068d7abe88436fe0cd833522c9470
7
+ data.tar.gz: 6157387c00a0d9e5cb76454e04c939d0f2b6942968ed7dd713abf49ab900f89412e008909b33b6eccfe208acbdfe191ead8cf1fc70f4d0b8e59a2acb9601b591
@@ -0,0 +1,47 @@
1
+ module SimplyAuth
2
+ class PasswordsController < ApplicationController
3
+ def new
4
+ @reset_password_token = SimplyAuth::ResetPasswordToken.new(permit_password_params)
5
+ end
6
+
7
+ def create
8
+ @reset_password_token = SimplyAuth::ResetPasswordToken.new(password_params)
9
+ if @reset_password_token.save
10
+ PasswordMailer.reset_password(@reset_password_token).deliver_now
11
+ flash[:notice] = "Please check your email for password reset instructions."
12
+ redirect_to new_session_path
13
+ else
14
+ render :new
15
+ end
16
+ end
17
+
18
+ def edit
19
+ @reset_password_token = SimplyAuth::ResetPasswordToken.find(params[:token])
20
+ @password_reset = SimplyAuth::PasswordReset.new(reset_password_token_id: params[:token])
21
+ end
22
+
23
+ def update
24
+ @password_reset = SimplyAuth::PasswordReset.new(password_reset_params)
25
+ @reset_password_token = SimplyAuth::ResetPasswordToken.find(@password_reset.reset_password_token_id)
26
+ if @password_reset.save
27
+ redirect_to new_session_path
28
+ else
29
+ render :edit
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def password_params
36
+ params.require(:reset_password_token).permit(:email)
37
+ end
38
+
39
+ def password_reset_params
40
+ params.require(:password_reset).permit(:reset_password_token_id, :password)
41
+ end
42
+
43
+ def permit_password_params
44
+ params.permit(:reset_password_token => :email)[:reset_password_token]
45
+ end
46
+ end
47
+ end
@@ -32,7 +32,7 @@ module SimplyAuth
32
32
  end
33
33
 
34
34
  def permit_session_params
35
- params.permit(:session => [:email, :password])[:session]
35
+ params.permit(:session => :email)[:session]
36
36
  end
37
37
  end
38
38
  end
@@ -0,0 +1,8 @@
1
+ module SimplyAuth
2
+ class PasswordMailer < ApplicationMailer
3
+ def reset_password(reset_password_token)
4
+ @reset_password_token = reset_password_token
5
+ mail(to: reset_password_token.user.email, subject: 'Reset your Password')
6
+ end
7
+ end
8
+ end
@@ -40,6 +40,7 @@ module SimplyAuth
40
40
 
41
41
  def save
42
42
  if valid?
43
+ attributes = self.attributes.deep_transform_keys{|k| k.to_s.camelize(:lower)}
43
44
  # Rails.logger.error([
44
45
  # persisted? ? :patch : :post,
45
46
  # "https://api.simplyauth.com#{persisted? ? instance_path : collection_path}",
@@ -55,8 +56,8 @@ module SimplyAuth
55
56
  content_type: :json
56
57
  )
57
58
  body = JSON.parse(response.body)[model_name.element.camelize(:lower)]
58
- body = body.deep_transform_keys { |key| key.to_s.underscore }
59
- self.attributes = self.class.new.attributes.merge(body)
59
+ body = body.deep_transform_keys { |key| key.to_s.underscore } if body
60
+ self.attributes = self.class.new.attributes.merge(body || {})
60
61
  changes_applied
61
62
  self.persisted = true
62
63
  true
@@ -0,0 +1,14 @@
1
+ module SimplyAuth
2
+ class PasswordReset < Model
3
+ attr_accessor :password, :reset_password_token_id, :user_pool_id
4
+ def attributes
5
+ super.merge(password: password, reset_password_token_id: reset_password_token_id, user_pool_id: user_pool_id)
6
+ end
7
+ def self.owner_class_name
8
+ "UserPool"
9
+ end
10
+ def owner_id
11
+ user_pool_id
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ module SimplyAuth
2
+ class ResetPasswordToken < Model
3
+ attr_accessor :email, :user_pool_id, :expires_at, :created_at, :user
4
+ validates :email, format: /[^@]+@[^@]+/
5
+ def attributes
6
+ super.merge(email: email)
7
+ end
8
+ def user
9
+ User.new(@user)
10
+ end
11
+
12
+ def self.owner_class_name
13
+ "UserPool"
14
+ end
15
+ def owner_id
16
+ user_pool_id
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ <p>Hey,<p>
2
+
3
+ <p>Someone asked to change your password. If you requested the change, click the link below.<p>
4
+
5
+ <p><%= link_to 'Change Password', edit_password_url(token: @reset_password_token.id) %>
6
+
7
+ <p>If you did not request that your password be changed, you may safely ignore this email. Your password will only be changed if you click the link and follow its instructions.</p>
8
+
9
+ <p>This link will expire in six hours, and can only be used once.</p>
10
+
@@ -0,0 +1,48 @@
1
+ <div class='container'>
2
+ <div class='d-flex flex-row'>
3
+ <h2 class='mr-auto'>Reset Password</h2>
4
+ <div>
5
+ <span class='mr-2'>Not a member?</span>
6
+ <%= link_to "Sign Up", new_registration_path, class: "btn btn-secondary" %>
7
+ </div>
8
+ </div>
9
+ <%= form_for @password_reset, url: :password, method: :patch, html: {class: "needs-validation", novalidate: true} do |f| %>
10
+ <%= f.hidden_field :reset_password_token_id %>
11
+ <div class='form-group'>
12
+ <%= f.label :password, "Password" %>
13
+ <%= f.password_field :password, class: "form-control #{"is-invalid" if @password_reset.errors[:password].any? }", required: true %>
14
+ <div class='invalid-feedback'>
15
+ <% if @password_reset.errors[:password].any? %>
16
+ <%= @password_reset.errors[:password].map{|m| "Password #{m}."}.join(" ") %>
17
+ <% else %>
18
+ Please choose a new password.
19
+ <% end %>
20
+ </div>
21
+ </div>
22
+ <%= f.submit "Reset my Password", class: "btn btn-primary mr-3" %>
23
+ <% end %>
24
+
25
+ <script>
26
+ (function() {
27
+ 'use strict';
28
+ window.addEventListener('load', function() {
29
+ var forms = document.getElementsByClassName('needs-validation');
30
+ var validation = Array.prototype.filter.call(forms, function(form) {
31
+ form.addEventListener('submit', function(event) {
32
+ if (form.checkValidity() === false) {
33
+ event.preventDefault();
34
+ event.stopPropagation();
35
+ }
36
+ form.classList.add('was-validated');
37
+ }, false);
38
+ });
39
+ }, false);
40
+ })();
41
+ </script>
42
+ <style>
43
+ .field_with_errors ~ .invalid-feedback,
44
+ .field_with_errors ~ .invalid-tooltip {
45
+ display: block;
46
+ }
47
+ </style>
48
+ </div>
@@ -0,0 +1,48 @@
1
+ <div class='container'>
2
+ <div class='d-flex flex-row'>
3
+ <h2 class='mr-auto'>Reset Password</h2>
4
+ <div>
5
+ <span class='mr-2'>Not a member?</span>
6
+ <%= link_to "Sign Up", new_registration_path, class: "btn btn-secondary" %>
7
+ </div>
8
+ </div>
9
+ <%= form_for @reset_password_token, url: :password, html: {class: "needs-validation", novalidate: true} do |f| %>
10
+ <div class='form-group'>
11
+ <%= f.label :email, "Email" %>
12
+ <%= f.text_field :email, class: "form-control #{"is-invalid" if @reset_password_token.errors[:email].any? }", required: true, type: :email %>
13
+ <div class='invalid-feedback'>
14
+ <% if @reset_password_token.errors[:email].any? %>
15
+ <%= @reset_password_token.errors[:email].map{|m| "Email #{m}."}.join(" ") %>
16
+ <% else %>
17
+ Please provide your email.
18
+ <% end %>
19
+ </div>
20
+ </div>
21
+ <%= f.submit "Reset my Password", class: "btn btn-primary mr-3" %>
22
+ <%= link_to "I remembered my password", new_session_path %>
23
+ <% end %>
24
+
25
+ <script>
26
+ (function() {
27
+ 'use strict';
28
+ window.addEventListener('load', function() {
29
+ var forms = document.getElementsByClassName('needs-validation');
30
+ var validation = Array.prototype.filter.call(forms, function(form) {
31
+ form.addEventListener('submit', function(event) {
32
+ if (form.checkValidity() === false) {
33
+ event.preventDefault();
34
+ event.stopPropagation();
35
+ }
36
+ form.classList.add('was-validated');
37
+ }, false);
38
+ });
39
+ }, false);
40
+ })();
41
+ </script>
42
+ <style>
43
+ .field_with_errors ~ .invalid-feedback,
44
+ .field_with_errors ~ .invalid-tooltip {
45
+ display: block;
46
+ }
47
+ </style>
48
+ </div>
@@ -29,7 +29,8 @@
29
29
  <% end %>
30
30
  </div>
31
31
  </div>
32
- <%= f.submit "Log In", class: "btn btn-primary"%>
32
+ <%= f.submit "Log In", class: "btn btn-primary mr-3" %>
33
+ <%= link_to "I forgot my password", new_password_path %>
33
34
  <% end %>
34
35
 
35
36
  <script>
data/config/routes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  SimplyAuth::Engine.routes.draw do
2
2
  resources :registrations
3
3
  resource :session
4
+ resource :password
4
5
  end
@@ -1,3 +1,3 @@
1
1
  module SimplyAuth
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simply_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Fogle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-04 00:00:00.000000000 Z
11
+ date: 2018-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,17 +66,24 @@ files:
66
66
  - app/assets/javascripts/simply_auth/application.js
67
67
  - app/assets/stylesheets/simply_auth/application.css
68
68
  - app/controllers/simply_auth/application_controller.rb
69
+ - app/controllers/simply_auth/passwords_controller.rb
69
70
  - app/controllers/simply_auth/registrations_controller.rb
70
71
  - app/controllers/simply_auth/sessions_controller.rb
71
72
  - app/helpers/simply_auth/application_helper.rb
72
73
  - app/jobs/simply_auth/application_job.rb
73
74
  - app/mailers/simply_auth/application_mailer.rb
75
+ - app/mailers/simply_auth/password_mailer.rb
74
76
  - app/models/simply_auth/config.rb
75
77
  - app/models/simply_auth/model.rb
78
+ - app/models/simply_auth/password_reset.rb
79
+ - app/models/simply_auth/reset_password_token.rb
76
80
  - app/models/simply_auth/session.rb
77
81
  - app/models/simply_auth/user.rb
78
82
  - app/models/simply_auth/user_pool.rb
79
83
  - app/views/layouts/simply_auth/application.html.erb
84
+ - app/views/simply_auth/password_mailer/reset_password.html.erb
85
+ - app/views/simply_auth/passwords/edit.html.erb
86
+ - app/views/simply_auth/passwords/new.html.erb
80
87
  - app/views/simply_auth/registrations/_additional_fields.html.erb
81
88
  - app/views/simply_auth/registrations/new.html.erb
82
89
  - app/views/simply_auth/sessions/new.html.erb