nyauth 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -20
  3. data/app/controllers/nyauth/{new_password_requests_controller.rb → reset_password_requests_controller.rb} +5 -5
  4. data/app/controllers/nyauth/{new_passwords_controller.rb → reset_passwords_controller.rb} +4 -4
  5. data/app/mailers/nyauth/request_mailer.rb +1 -1
  6. data/app/models/concerns/nyauth/password_digest_ability.rb +1 -2
  7. data/app/models/concerns/nyauth/reset_password_ability.rb +35 -0
  8. data/app/views/nyauth/request_mailer/request_reset_password.html.slim +2 -0
  9. data/app/views/nyauth/request_mailer/request_reset_password.text.erb +3 -0
  10. data/app/views/nyauth/reset_password_requests/new.html.slim +5 -0
  11. data/app/views/nyauth/{new_passwords → reset_passwords}/edit.html.slim +1 -1
  12. data/config/locales/en.yml +3 -3
  13. data/config/routes.rb +2 -2
  14. data/lib/nyauth/configuration.rb +9 -5
  15. data/lib/nyauth/version.rb +1 -1
  16. data/spec/dummy/app/models/user.rb +1 -1
  17. data/spec/dummy/db/development.sqlite3 +0 -0
  18. data/spec/dummy/db/migrate/20150303135922_create_users.rb +2 -2
  19. data/spec/dummy/db/production.sqlite3 +0 -0
  20. data/spec/dummy/db/schema.rb +7 -7
  21. data/spec/dummy/db/test.sqlite3 +0 -0
  22. data/spec/dummy/log/development.log +51 -0
  23. data/spec/dummy/log/test.log +5193 -0
  24. data/spec/factories/users.rb +3 -3
  25. data/spec/featrues/nyauth/{new_password_requests_spec.rb → reset_password_requests_spec.rb} +9 -9
  26. data/spec/helpers/nyauth/application_helper_spec.rb +10 -10
  27. data/spec/mailers/nyauth/request_mailer_spec.rb +3 -3
  28. data/spec/models/user_spec.rb +1 -1
  29. data/spec/support/models/nyauth/reset_password_ability.rb +13 -0
  30. metadata +15 -13
  31. data/app/models/concerns/nyauth/new_password_ability.rb +0 -35
  32. data/app/views/nyauth/new_password_requests/new.html.slim +0 -5
  33. data/app/views/nyauth/request_mailer/request_new_password.html.slim +0 -2
  34. data/app/views/nyauth/request_mailer/request_new_password.text.erb +0 -3
  35. data/spec/support/models/nyauth/new_password_ability.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd6e65944c1dc06e5b03ed7744365a09f3611cb5
4
- data.tar.gz: 91ae82f9fd0543b01abb601a2a8f780e54dd92ad
3
+ metadata.gz: 7aa459a7489bcf471b35e7d148e1f76c6f9fbc0c
4
+ data.tar.gz: 5814355e8fc532c97fb10e3d31cdc971170cddd0
5
5
  SHA512:
6
- metadata.gz: 2ac0d0c2c4a60a97a29f42a03cc71800d74a046944e3ed64e5ebb82a07d4d6f30a2b3d96228c4a3e67e5f21be4013dd5495f21ff383510322b173b4778b72627
7
- data.tar.gz: 2deefd3ca405a7686c3e1a5c6eccdfc3e12f27c48bf09279fff447167f258e1968ae69ea9fd7441afca7f4404d64c14ab6f8a97c9bb50befcb908ed9998849d6
6
+ metadata.gz: 2e1afbec3759f152cbfb0aa08dbe73a1d31586cf760c15b81ec7443c69800ecff3eb3b821b64e366c7a721427554d5003a72f9fa73f1a2beb7c3ea05823279c5
7
+ data.tar.gz: 7cfa5125de5e68bd175e0ee00daea93865a1e18b66972d27dcd5ca9b270db811798a5431a45145662398ac5fa2d7cf159c0db1444e47fdca080e7204e1c4cebe
data/README.md CHANGED
@@ -21,8 +21,8 @@ class CreateUsers < ActiveRecord::Migration
21
21
  t.datetime :confirmed_at
22
22
  t.string :confirmation_key
23
23
  t.datetime :confirmation_key_expired_at
24
- t.string :new_password_key
25
- t.datetime :new_password_key_expired_at
24
+ t.string :reset_password_key
25
+ t.datetime :reset_password_key_expired_at
26
26
 
27
27
  t.timestamps null: false
28
28
  end
@@ -37,7 +37,7 @@ end
37
37
  class User < ActiveRecord::Base
38
38
  include Nyauth::Authenticatable
39
39
  include Nyauth::Confirmable
40
- include Nyauth::NewPasswordAbility
40
+ include Nyauth::ResetPasswordAbility
41
41
  end
42
42
  ```
43
43
 
@@ -64,23 +64,22 @@ Prefix Verb URI Pattern Controller#Action
64
64
  nyauth /nyauth Nyauth::Engine
65
65
 
66
66
  Routes for Nyauth::Engine:
67
- registration POST /registration(.:format) nyauth/registrations#create
68
- new_registration GET /registration/new(.:format) nyauth/registrations#new
69
- session POST /session(.:format) nyauth/sessions#create
70
- new_session GET /session/new(.:format) nyauth/sessions#new
71
- DELETE /session(.:format) nyauth/sessions#destroy
72
- edit_password GET /password/edit(.:format) nyauth/passwords#edit
73
- password PATCH /password(.:format) nyauth/passwords#update
74
- PUT /password(.:format) nyauth/passwords#update
75
- confirmation_requests POST /confirmation_requests(.:format) nyauth/confirmation_requests#create
76
- new_confirmation_request GET /confirmation_requests/new(.:format) nyauth/confirmation_requests#new
77
- confirmation GET /confirmations/:confirmation_key(.:format) nyauth/confirmations#update
78
- new_password_requests POST /new_password_requests(.:format) nyauth/new_password_requests#create
79
- new_new_password_request GET /new_password_requests/new(.:format) nyauth/new_password_requests#new
80
- edit_new_password GET /new_passwords/:new_password_key/edit(.:format) nyauth/new_passwords#edit
81
- new_password PATCH /new_passwords/:new_password_key(.:format) nyauth/new_passwords#update
82
- PUT /new_passwords/:new_password_key(.:format) nyauth/new_passwords#update
83
- root GET / nyauth/sessions#new
67
+ registration POST /registration(.:format) nyauth/registrations#create
68
+ new_registration GET /registration/new(.:format) nyauth/registrations#new
69
+ session POST /session(.:format) nyauth/sessions#create
70
+ new_session GET /session/new(.:format) nyauth/sessions#new
71
+ DELETE /session(.:format) nyauth/sessions#destroy
72
+ edit_password GET /password/edit(.:format) nyauth/passwords#edit
73
+ password PATCH /password(.:format) nyauth/passwords#update
74
+ PUT /password(.:format) nyauth/passwords#update
75
+ confirmation_requests POST /confirmation_requests(.:format) nyauth/confirmation_requests#create
76
+ new_confirmation_request GET /confirmation_requests/new(.:format) nyauth/confirmation_requests#new
77
+ confirmation GET /confirmations/:confirmation_key(.:format) nyauth/confirmations#update
78
+ reset_password_requests POST /reset_password_requests(.:format) nyauth/reset_password_requests#create
79
+ new_reset_password_request GET /reset_password_requests/new(.:format) nyauth/reset_password_requests#new
80
+ edit_reset_password GET /reset_passwords/:reset_password_key/edit(.:format) nyauth/reset_passwords#edit
81
+ reset_password PATCH /reset_passwords/:reset_password_key(.:format) nyauth/reset_passwords#update
82
+ PUT /reset_passwords/:reset_password_key(.:format) nyauth/reset_passwords#update
84
83
  ```
85
84
 
86
85
  ```
@@ -1,18 +1,18 @@
1
1
  module Nyauth
2
- class NewPasswordRequestsController < ApplicationController
2
+ class ResetPasswordRequestsController < ApplicationController
3
3
  include Nyauth::ApplicationConcern
4
4
  include Nyauth::ClientConcern
5
5
  allow_everyone
6
6
  respond_to :html, :json
7
7
  before_action :set_client, only: [:create]
8
- after_action :send_mail, only: [:create], if: -> { @client.new_password_key.present? }
8
+ after_action :send_mail, only: [:create], if: -> { @client.reset_password_key.present? }
9
9
 
10
10
  def new
11
11
  end
12
12
 
13
13
  def create
14
- @client.request_new_password
15
- respond_with(@client, location: Nyauth.configuration.redirect_path_after_new_password_request || main_app.root_path)
14
+ @client.request_reset_password
15
+ respond_with(@client, location: Nyauth.configuration.redirect_path_after_reset_password_request || main_app.root_path)
16
16
  end
17
17
 
18
18
  private
@@ -24,7 +24,7 @@ module Nyauth
24
24
  end
25
25
 
26
26
  def send_mail
27
- Nyauth::RequestMailer.request_new_password(@client).deliver_now
27
+ Nyauth::RequestMailer.request_reset_password(@client).deliver_now
28
28
  end
29
29
  end
30
30
  end
@@ -1,5 +1,5 @@
1
1
  module Nyauth
2
- class NewPasswordsController < ApplicationController
2
+ class ResetPasswordsController < ApplicationController
3
3
  include Nyauth::ApplicationConcern
4
4
  include Nyauth::ClientConcern
5
5
  allow_everyone
@@ -10,14 +10,14 @@ module Nyauth
10
10
  end
11
11
 
12
12
  def update
13
- @client.update_new_password(client_params)
14
- respond_with(@client, location: Nyauth.configuration.redirect_path_after_update_new_password || new_session_path_for(client_name))
13
+ @client.reset_password(client_params)
14
+ respond_with(@client, location: Nyauth.configuration.redirect_path_after_reset_password || new_session_path_for(client_name))
15
15
  end
16
16
 
17
17
  private
18
18
 
19
19
  def set_client
20
- @client = client_class.find_by!(new_password_key: params[:new_password_key])
20
+ @client = client_class.find_by!(reset_password_key: params[:reset_password_key])
21
21
  end
22
22
 
23
23
  def client_params
@@ -7,7 +7,7 @@ module Nyauth
7
7
  mail to: client.email
8
8
  end
9
9
 
10
- def request_new_password(client)
10
+ def request_reset_password(client)
11
11
  @client = client
12
12
  mail to: client.email
13
13
  end
@@ -1,7 +1,6 @@
1
1
  module Nyauth
2
2
  module PasswordDigestAbility
3
3
  extend ActiveSupport::Concern
4
- DIGEST_STRETCHES = 1000
5
4
 
6
5
  included do
7
6
  attr_accessor :password, :password_confirmation
@@ -19,7 +18,7 @@ module Nyauth
19
18
  private
20
19
 
21
20
  def generate_password_digest(password)
22
- DIGEST_STRETCHES.times do
21
+ Nyauth.configuration.password_digest_stretches.times do
23
22
  password = Digest::SHA256.hexdigest("#{password}#{password_salt}")
24
23
  end
25
24
  password
@@ -0,0 +1,35 @@
1
+ module Nyauth
2
+ module ResetPasswordAbility
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_validation :check_reset_password_key, on: :reset_password
7
+ validates :email, email: { strict_mode: false }
8
+ validates :password, presence: true,
9
+ length: { minimum: Nyauth.configuration.password_minium },
10
+ on: [:create, :update_password, :reset_password]
11
+ validates :password, confirmation: true
12
+ end
13
+
14
+ def reset_password(params)
15
+ self.attributes = params
16
+ self.save(context: :reset_password)
17
+ end
18
+
19
+ def request_reset_password
20
+ self.reset_password_key = SecureRandom.hex(32)
21
+ self.reset_password_key_expired_at = Time.current + 1.hour
22
+ save
23
+ end
24
+
25
+ private
26
+
27
+ def check_reset_password_key
28
+ if reset_password_key_expired_at.past?
29
+ errors.add(:reset_password_key, :expired)
30
+ else
31
+ self.reset_password_key = nil
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,2 @@
1
+ p Plese set your new password
2
+ p = link_to 'set new password', edit_reset_password_url(@client.reset_password_key)
@@ -0,0 +1,3 @@
1
+ Plese set your new password
2
+
3
+ <%= edit_reset_password_url(@client.reset_password_key) %>
@@ -0,0 +1,5 @@
1
+ = form_for(client_class.new, url: reset_password_requests_path_for(client_name), mehotd: :post, html: { class: 'pure-form' }) do |f|
2
+ fieldset
3
+ legend= t 'nav.reset_password_requests.new'
4
+ = f.text_field(:email, placeholder: :email)
5
+ = f.submit 'reset password', data: { disable_with: '...' }, class: 'pure-button pure-button-primary'
@@ -1,4 +1,4 @@
1
- = form_for(@client, url: new_password_path_for(client_name, params[:new_password_key]), html: { class: 'pure-form pure-form-stacked' }) do |f|
1
+ = form_for(@client, url: reset_password_path_for(client_name, params[:reset_password_key]), html: { class: 'pure-form pure-form-stacked' }) do |f|
2
2
  fieldset
3
3
  legend
4
4
  - if @client.errors.present?
@@ -9,7 +9,7 @@ en:
9
9
  edit: 'Edit Profiles'
10
10
  confirmation_requests:
11
11
  new: 'Re send confirmation request'
12
- new_password_requests:
12
+ reset_password_requests:
13
13
  new: 'New password request'
14
14
  profiles:
15
15
  edit: 'Profiles'
@@ -35,10 +35,10 @@ en:
35
35
  confirmation_requests:
36
36
  create:
37
37
  notice: 'sent mail'
38
- new_password_requests:
38
+ reset_password_requests:
39
39
  create:
40
40
  notice: 'sent mail'
41
- new_passwords:
41
+ reset_passwords:
42
42
  update:
43
43
  notice: 'updated password'
44
44
  group_requests:
data/config/routes.rb CHANGED
@@ -4,7 +4,7 @@ Nyauth::Engine.routes.draw do
4
4
  resource :password, only: %i(edit update)
5
5
  resources :confirmation_requests, only: %i(new create)
6
6
  get '/confirmations/:confirmation_key' => 'confirmations#update', as: :confirmation
7
- resources :new_password_requests, only: %i(new create)
8
- resources :new_passwords, param: :new_password_key, only: %i(edit update)
7
+ resources :reset_password_requests, only: %i(new create)
8
+ resources :reset_passwords, param: :reset_password_key, only: %i(edit update)
9
9
  Nyauth.configuration.setup_redirect_path
10
10
  end
@@ -6,9 +6,11 @@ module Nyauth
6
6
  :redirect_path_after_registration,
7
7
  :redirect_path_after_create_request_confirmation,
8
8
  :redirect_path_after_update_confirmation,
9
- :redirect_path_after_new_password_request,
10
- :redirect_path_after_update_new_password,
11
- :redirect_path_after_update_password
9
+ :redirect_path_after_reset_password_request,
10
+ :redirect_path_after_reset_password,
11
+ :redirect_path_after_update_password,
12
+ :password_minium,
13
+ :password_digest_stretches
12
14
 
13
15
 
14
16
  def initialize
@@ -17,9 +19,11 @@ module Nyauth
17
19
  @redirect_path_after_registration = nil
18
20
  @redirect_path_after_create_request_confirmation = nil
19
21
  @redirect_path_after_update_confirmation = nil
20
- @redirect_path_after_new_password_request = nil
21
- @redirect_path_after_update_new_password = nil
22
+ @redirect_path_after_reset_password_request = nil
23
+ @redirect_path_after_reset_password = nil
22
24
  @redirect_path_after_update_password = nil
25
+ @password_minium = 8
26
+ @password_digest_stretches = 1000
23
27
  @redirect_path_block = Proc.new {}
24
28
  end
25
29
 
@@ -1,3 +1,3 @@
1
1
  module Nyauth
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  class User < ActiveRecord::Base
2
2
  include Nyauth::Authenticatable
3
3
  include Nyauth::Confirmable
4
- include Nyauth::NewPasswordAbility
4
+ include Nyauth::ResetPasswordAbility
5
5
  end
Binary file
@@ -8,8 +8,8 @@ class CreateUsers < ActiveRecord::Migration
8
8
  t.datetime :confirmed_at
9
9
  t.string :confirmation_key
10
10
  t.datetime :confirmation_key_expired_at
11
- t.string :new_password_key
12
- t.datetime :new_password_key_expired_at
11
+ t.string :reset_password_key
12
+ t.datetime :reset_password_key_expired_at
13
13
 
14
14
  t.timestamps null: false
15
15
  end
File without changes
@@ -24,17 +24,17 @@ ActiveRecord::Schema.define(version: 20150317141956) do
24
24
  add_index "admins", ["email"], name: "index_admins_on_email", unique: true
25
25
 
26
26
  create_table "users", force: :cascade do |t|
27
- t.string "email", null: false
28
- t.string "password_digest", null: false
29
- t.string "password_salt", null: false
27
+ t.string "email", null: false
28
+ t.string "password_digest", null: false
29
+ t.string "password_salt", null: false
30
30
  t.string "nickname"
31
31
  t.datetime "confirmed_at"
32
32
  t.string "confirmation_key"
33
33
  t.datetime "confirmation_key_expired_at"
34
- t.string "new_password_key"
35
- t.datetime "new_password_key_expired_at"
36
- t.datetime "created_at", null: false
37
- t.datetime "updated_at", null: false
34
+ t.string "reset_password_key"
35
+ t.datetime "reset_password_key_expired_at"
36
+ t.datetime "created_at", null: false
37
+ t.datetime "updated_at", null: false
38
38
  end
39
39
 
40
40
  add_index "users", ["email"], name: "index_users_on_email", unique: true
Binary file
@@ -3566,3 +3566,54 @@ Started GET "/" for 127.0.0.1 at 2015-06-23 00:15:35 +0900
3566
3566
  Processing by PagesController#index as HTML
3567
3567
  Rendered pages/index.html.slim within layouts/application (0.1ms)
3568
3568
  Completed 200 OK in 20ms (Views: 19.5ms | ActiveRecord: 0.0ms)
3569
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
3570
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
3571
+  (0.1ms)  SELECT sql
3572
+ FROM sqlite_master
3573
+ WHERE name='index_admins_on_email' AND type='index'
3574
+ UNION ALL
3575
+ SELECT sql
3576
+ FROM sqlite_temp_master
3577
+ WHERE name='index_admins_on_email' AND type='index'
3578
+ 
3579
+  (0.1ms) SELECT sql
3580
+ FROM sqlite_master
3581
+ WHERE name='index_users_on_email' AND type='index'
3582
+ UNION ALL
3583
+ SELECT sql
3584
+ FROM sqlite_temp_master
3585
+ WHERE name='index_users_on_email' AND type='index'
3586
+
3587
+  (2.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
3588
+  (0.3ms) select sqlite_version(*)
3589
+  (0.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
3590
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
3591
+ Migrating to CreateUsers (20150303135922)
3592
+  (0.0ms) begin transaction
3593
+  (0.3ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar NOT NULL, "password_digest" varchar NOT NULL, "password_salt" varchar NOT NULL, "nickname" varchar, "confirmed_at" datetime, "confirmation_key" varchar, "confirmation_key_expired_at" datetime, "reset_password_key" varchar, "reset_password_key_expired_at" datetime, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
3594
+  (0.3ms) CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email")
3595
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20150303135922"]]
3596
+  (0.8ms) commit transaction
3597
+ Migrating to CreateAdmins (20150317141956)
3598
+  (0.0ms) begin transaction
3599
+  (0.3ms) CREATE TABLE "admins" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar NOT NULL, "password_digest" varchar NOT NULL, "password_salt" varchar NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 
3600
+  (0.3ms) CREATE UNIQUE INDEX "index_admins_on_email" ON "admins" ("email")
3601
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20150317141956"]]
3602
+  (0.7ms) commit transaction
3603
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
3604
+  (0.1ms) SELECT sql
3605
+ FROM sqlite_master
3606
+ WHERE name='index_admins_on_email' AND type='index'
3607
+ UNION ALL
3608
+ SELECT sql
3609
+ FROM sqlite_temp_master
3610
+ WHERE name='index_admins_on_email' AND type='index'
3611
+
3612
+  (0.1ms)  SELECT sql
3613
+ FROM sqlite_master
3614
+ WHERE name='index_users_on_email' AND type='index'
3615
+ UNION ALL
3616
+ SELECT sql
3617
+ FROM sqlite_temp_master
3618
+ WHERE name='index_users_on_email' AND type='index'
3619
+