nyauth 0.0.3 → 0.1.0
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 +4 -4
- data/README.md +19 -20
- data/app/controllers/nyauth/{new_password_requests_controller.rb → reset_password_requests_controller.rb} +5 -5
- data/app/controllers/nyauth/{new_passwords_controller.rb → reset_passwords_controller.rb} +4 -4
- data/app/mailers/nyauth/request_mailer.rb +1 -1
- data/app/models/concerns/nyauth/password_digest_ability.rb +1 -2
- data/app/models/concerns/nyauth/reset_password_ability.rb +35 -0
- data/app/views/nyauth/request_mailer/request_reset_password.html.slim +2 -0
- data/app/views/nyauth/request_mailer/request_reset_password.text.erb +3 -0
- data/app/views/nyauth/reset_password_requests/new.html.slim +5 -0
- data/app/views/nyauth/{new_passwords → reset_passwords}/edit.html.slim +1 -1
- data/config/locales/en.yml +3 -3
- data/config/routes.rb +2 -2
- data/lib/nyauth/configuration.rb +9 -5
- data/lib/nyauth/version.rb +1 -1
- data/spec/dummy/app/models/user.rb +1 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20150303135922_create_users.rb +2 -2
- data/spec/dummy/db/production.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +7 -7
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +51 -0
- data/spec/dummy/log/test.log +5193 -0
- data/spec/factories/users.rb +3 -3
- data/spec/featrues/nyauth/{new_password_requests_spec.rb → reset_password_requests_spec.rb} +9 -9
- data/spec/helpers/nyauth/application_helper_spec.rb +10 -10
- data/spec/mailers/nyauth/request_mailer_spec.rb +3 -3
- data/spec/models/user_spec.rb +1 -1
- data/spec/support/models/nyauth/reset_password_ability.rb +13 -0
- metadata +15 -13
- data/app/models/concerns/nyauth/new_password_ability.rb +0 -35
- data/app/views/nyauth/new_password_requests/new.html.slim +0 -5
- data/app/views/nyauth/request_mailer/request_new_password.html.slim +0 -2
- data/app/views/nyauth/request_mailer/request_new_password.text.erb +0 -3
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7aa459a7489bcf471b35e7d148e1f76c6f9fbc0c
|
4
|
+
data.tar.gz: 5814355e8fc532c97fb10e3d31cdc971170cddd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 :
|
25
|
-
t.datetime :
|
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::
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
new_confirmation_request GET /confirmation_requests/new(.:format)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
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.
|
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.
|
15
|
-
respond_with(@client, location: Nyauth.configuration.
|
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.
|
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
|
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.
|
14
|
-
respond_with(@client, location: Nyauth.configuration.
|
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!(
|
20
|
+
@client = client_class.find_by!(reset_password_key: params[:reset_password_key])
|
21
21
|
end
|
22
22
|
|
23
23
|
def client_params
|
@@ -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
|
-
|
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,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:
|
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?
|
data/config/locales/en.yml
CHANGED
@@ -9,7 +9,7 @@ en:
|
|
9
9
|
edit: 'Edit Profiles'
|
10
10
|
confirmation_requests:
|
11
11
|
new: 'Re send confirmation request'
|
12
|
-
|
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
|
-
|
38
|
+
reset_password_requests:
|
39
39
|
create:
|
40
40
|
notice: 'sent mail'
|
41
|
-
|
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 :
|
8
|
-
resources :
|
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
|
data/lib/nyauth/configuration.rb
CHANGED
@@ -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
|
-
:
|
10
|
-
:
|
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
|
-
@
|
21
|
-
@
|
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
|
|
data/lib/nyauth/version.rb
CHANGED
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 :
|
12
|
-
t.datetime :
|
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
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -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",
|
28
|
-
t.string "password_digest",
|
29
|
-
t.string "password_salt",
|
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 "
|
35
|
-
t.datetime "
|
36
|
-
t.datetime "created_at",
|
37
|
-
t.datetime "updated_at",
|
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
|
data/spec/dummy/db/test.sqlite3
CHANGED
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
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.4ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
3570
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
3571
|
+
[1m[36m (0.1ms)[0m [1m 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
|
+
[0m
|
3579
|
+
[1m[35m (0.1ms)[0m 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
|
+
[1m[36m (2.2ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
3588
|
+
[1m[35m (0.3ms)[0m select sqlite_version(*)
|
3589
|
+
[1m[36m (0.7ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
3590
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
3591
|
+
Migrating to CreateUsers (20150303135922)
|
3592
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
3593
|
+
[1m[35m (0.3ms)[0m 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
|
+
[1m[36m (0.3ms)[0m [1mCREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email")[0m
|
3595
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20150303135922"]]
|
3596
|
+
[1m[36m (0.8ms)[0m [1mcommit transaction[0m
|
3597
|
+
Migrating to CreateAdmins (20150317141956)
|
3598
|
+
[1m[35m (0.0ms)[0m begin transaction
|
3599
|
+
[1m[36m (0.3ms)[0m [1mCREATE 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) [0m
|
3600
|
+
[1m[35m (0.3ms)[0m CREATE UNIQUE INDEX "index_admins_on_email" ON "admins" ("email")
|
3601
|
+
[1m[36mSQL (0.1ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES (?)[0m [["version", "20150317141956"]]
|
3602
|
+
[1m[35m (0.7ms)[0m commit transaction
|
3603
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
3604
|
+
[1m[35m (0.1ms)[0m 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
|
+
[1m[36m (0.1ms)[0m [1m 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
|
+
[0m
|