nyauth 0.0.2 → 0.0.3

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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -6
  3. data/app/controllers/concerns/nyauth/application_concern.rb +10 -0
  4. data/app/controllers/concerns/nyauth/client_concern.rb +31 -0
  5. data/app/controllers/nyauth/confirmation_requests_controller.rb +10 -8
  6. data/app/controllers/nyauth/confirmations_controller.rb +8 -6
  7. data/app/controllers/nyauth/new_password_requests_controller.rb +10 -8
  8. data/app/controllers/nyauth/new_passwords_controller.rb +10 -8
  9. data/app/controllers/nyauth/passwords_controller.rb +11 -9
  10. data/app/controllers/nyauth/registrations_controller.rb +10 -8
  11. data/app/controllers/nyauth/sessions_controller.rb +6 -4
  12. data/app/helpers/nyauth/application_helper.rb +38 -1
  13. data/app/mailers/nyauth/request_mailer.rb +15 -0
  14. data/app/views/nyauth/confirmation_requests/new.html.slim +1 -1
  15. data/app/views/nyauth/confirmations/edit.html.slim +2 -2
  16. data/app/views/nyauth/new_password_requests/new.html.slim +1 -1
  17. data/app/views/nyauth/new_passwords/edit.html.slim +3 -3
  18. data/app/views/nyauth/passwords/edit.html.slim +3 -3
  19. data/app/views/nyauth/registrations/new.html.slim +3 -3
  20. data/app/views/nyauth/request_mailer/request_confirmation.html.slim +2 -0
  21. data/app/views/nyauth/request_mailer/request_confirmation.text.erb +3 -0
  22. data/app/views/nyauth/request_mailer/request_new_password.html.slim +2 -0
  23. data/app/views/nyauth/request_mailer/request_new_password.text.erb +3 -0
  24. data/app/views/nyauth/sessions/new.html.slim +1 -5
  25. data/config/routes.rb +1 -1
  26. data/lib/generators/nyauth/install_generator.rb +11 -0
  27. data/lib/generators/nyauth/templates/nyauth_install_initializer.rb +7 -0
  28. data/lib/nyauth/configuration.rb +40 -0
  29. data/lib/nyauth/engine.rb +2 -0
  30. data/lib/nyauth/version.rb +1 -1
  31. data/lib/nyauth.rb +10 -0
  32. data/spec/dummy/app/controllers/pages_controller.rb +4 -0
  33. data/spec/dummy/app/controllers/posts_controller.rb +5 -0
  34. data/spec/dummy/app/models/admin.rb +3 -0
  35. data/spec/dummy/app/views/layouts/application.html.erb +2 -1
  36. data/spec/dummy/config/routes.rb +7 -1
  37. data/spec/dummy/db/development.sqlite3 +0 -0
  38. data/spec/dummy/db/migrate/20150317141956_create_admins.rb +12 -0
  39. data/spec/dummy/db/schema.rb +11 -1
  40. data/spec/dummy/db/test.sqlite3 +0 -0
  41. data/spec/dummy/log/development.log +1662 -0
  42. data/spec/dummy/log/test.log +36831 -0
  43. data/spec/dummy/tmp/capybara/capybara-201503142131285774508896.html +1 -0
  44. data/spec/dummy/tmp/capybara/capybara-201503142131502672526321.html +1 -0
  45. data/spec/dummy/tmp/capybara/capybara-201503142132597161072575.html +16 -0
  46. data/spec/dummy/tmp/capybara/capybara-201503142147454003977122.html +16 -0
  47. data/spec/dummy/tmp/capybara/capybara-201503150030597512321952.html +1 -0
  48. data/spec/dummy/tmp/capybara/capybara-201503172332094559831059.html +15 -0
  49. data/spec/dummy/tmp/capybara/capybara-201503172332489943616503.html +15 -0
  50. data/spec/dummy/tmp/capybara/capybara-201503172333245353296202.html +15 -0
  51. data/spec/dummy/tmp/capybara/capybara-201503172335156567049015.html +15 -0
  52. data/spec/dummy/tmp/capybara/capybara-201503172339176031196898.html +15 -0
  53. data/spec/dummy/tmp/capybara/capybara-201503172340144947026095.html +15 -0
  54. data/spec/dummy/tmp/capybara/capybara-201503172341585213923875.html +15 -0
  55. data/spec/dummy/tmp/capybara/capybara-201503172342188836603353.html +15 -0
  56. data/spec/dummy/tmp/capybara/capybara-201503172344586782457691.html +15 -0
  57. data/spec/dummy/tmp/capybara/capybara-201503172346495241516033.html +15 -0
  58. data/spec/dummy/tmp/capybara/capybara-201503172354248621830336.html +15 -0
  59. data/spec/dummy/tmp/capybara/capybara-20150623002226753539811.html +15 -0
  60. data/spec/dummy/tmp/pids/server.pid +1 -0
  61. data/spec/factories/admins.rb +6 -0
  62. data/spec/featrues/nyauth/registrations_spec.rb +1 -0
  63. data/spec/featrues/nyauth/sessions_spec.rb +54 -19
  64. data/spec/featrues/url_helper_on_application_spec.rb +10 -0
  65. data/spec/helpers/nyauth/application_helper_spec.rb +145 -0
  66. data/spec/lib/generators/nyauth/install_generator_spec.rb +19 -0
  67. data/spec/lib/generators/nyauth/tmp/config/initializers/nyauth.rb +7 -0
  68. data/spec/lib/nyauth/configuration_spec.rb +23 -0
  69. data/spec/mailers/nyauth/{user_mailer_spec.rb → request_mailer_spec.rb} +3 -3
  70. metadata +72 -13
  71. data/app/controllers/nyauth/base_controller.rb +0 -5
  72. data/app/mailers/nyauth/user_mailer.rb +0 -15
  73. data/app/views/nyauth/group_requests/new.html.slim +0 -14
  74. data/app/views/nyauth/groups/show.html.slim +0 -0
  75. data/app/views/nyauth/user_mailer/request_confirmation.html.slim +0 -2
  76. data/app/views/nyauth/user_mailer/request_confirmation.text.erb +0 -3
  77. data/app/views/nyauth/user_mailer/request_new_password.html.slim +0 -2
  78. data/app/views/nyauth/user_mailer/request_new_password.text.erb +0 -3
  79. /data/{app/views/nyauth/group_requests/edit.html.slim → spec/dummy/app/views/pages/index.html.slim} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa665b789065b1cb2ce9a772c824d6f2d03c158a
4
- data.tar.gz: e6fc77b3c1d8804ee127efb05b2c62f7ad898b43
3
+ metadata.gz: fd6e65944c1dc06e5b03ed7744365a09f3611cb5
4
+ data.tar.gz: 91ae82f9fd0543b01abb601a2a8f780e54dd92ad
5
5
  SHA512:
6
- metadata.gz: de301bc13261d9feae6f717b4787de4aac4840ccc2fb48b4853c592c014b34516d35add7db2dd6a9fd013ae62886fb8759cecb14148a10c7825ab4d398cbee34
7
- data.tar.gz: 551c3947db51fdc8e5761711654f9c61c053fb0d4be9080f825e8923a861d74c6ef8aa08a1fb827acf03a08c30a011985b9e6d564a48c162f49d64b30f02fd01
6
+ metadata.gz: 2ac0d0c2c4a60a97a29f42a03cc71800d74a046944e3ed64e5ebb82a07d4d6f30a2b3d96228c4a3e67e5f21be4013dd5495f21ff383510322b173b4778b72627
7
+ data.tar.gz: 2deefd3ca405a7686c3e1a5c6eccdfc3e12f27c48bf09279fff447167f258e1968ae69ea9fd7441afca7f4404d64c14ab6f8a97c9bb50befcb908ed9998849d6
data/README.md CHANGED
@@ -1,13 +1,16 @@
1
1
  # Nyauth
2
2
 
3
- ```application_controller
3
+ ### application_controller.rb
4
+
5
+ ```ruby
4
6
  class ApplicationController < ActionController::Base
5
7
  include Nyauth::SessionConcern
6
- self.responder = Nyauth::AppResponder
7
8
  end
8
9
  ```
9
10
 
10
- ```schema
11
+ ### migration
12
+
13
+ ```ruby
11
14
  class CreateUsers < ActiveRecord::Migration
12
15
  def change
13
16
  create_table :users do |t|
@@ -28,7 +31,9 @@ class CreateUsers < ActiveRecord::Migration
28
31
  end
29
32
  ```
30
33
 
31
- ```model
34
+ ### model
35
+
36
+ ```ruby
32
37
  class User < ActiveRecord::Base
33
38
  include Nyauth::Authenticatable
34
39
  include Nyauth::Confirmable
@@ -36,8 +41,16 @@ class User < ActiveRecord::Base
36
41
  end
37
42
  ```
38
43
 
39
- ```routes
44
+ ### config/routes.rb
45
+
46
+ ```ruby
40
47
  Rails.application.routes.draw do
48
+ # for admin
49
+ namespace :nyauth, path: :admin, as: :admin do
50
+ resource :session, only: %i(new create destory)
51
+ end
52
+
53
+ # for user
41
54
  mount Nyauth::Engine => "/"
42
55
  end
43
56
  ```
@@ -46,7 +59,7 @@ end
46
59
  rake routes
47
60
  ```
48
61
 
49
- ```
62
+ ```ruby
50
63
  Prefix Verb URI Pattern Controller#Action
51
64
  nyauth /nyauth Nyauth::Engine
52
65
 
@@ -69,3 +82,8 @@ new_new_password_request GET /new_password_requests/new(.:format)
69
82
  PUT /new_passwords/:new_password_key(.:format) nyauth/new_passwords#update
70
83
  root GET / nyauth/sessions#new
71
84
  ```
85
+
86
+ ```
87
+ new_session_path_for(:user) # /session/new
88
+ new_session_path_for(:admin) # /admin/session/new
89
+ ```
@@ -0,0 +1,10 @@
1
+ module Nyauth
2
+ module ApplicationConcern
3
+ extend ActiveSupport::Concern
4
+ include Nyauth::ApplicationHelper
5
+
6
+ included do
7
+ helper Nyauth::ApplicationHelper
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,31 @@
1
+ module Nyauth
2
+ module ClientConcern
3
+ extend ActiveSupport::Concern
4
+ included do |base|
5
+ helper_method :client_class
6
+ helper_method :client_name
7
+ end
8
+
9
+ def initialize
10
+ @client_classes = {}
11
+ super
12
+ end
13
+
14
+ private
15
+
16
+ def mounted_path
17
+ request.script_name.presence || "/#{request.path.split('/').try(:second)}"
18
+ end
19
+
20
+ # specify client class from mounted_path
21
+ def client_class
22
+ @client_classes[mounted_path] ||= mounted_path[1..-1].classify.constantize
23
+ rescue
24
+ @client_classes[mounted_path] = User
25
+ end
26
+
27
+ def client_name
28
+ client_class.name.underscore.to_sym
29
+ end
30
+ end
31
+ end
@@ -1,28 +1,30 @@
1
1
  module Nyauth
2
- class ConfirmationRequestsController < Nyauth::BaseController
2
+ class ConfirmationRequestsController < ApplicationController
3
+ include Nyauth::ApplicationConcern
4
+ include Nyauth::ClientConcern
3
5
  allow_everyone
4
6
  respond_to :html, :json
5
- before_action :set_user, only: [:create]
6
- after_action :send_mail, only: [:create], if: -> { @user.confirmation_key.present? }
7
+ before_action :set_client, only: [:create]
8
+ after_action :send_mail, only: [:create], if: -> { @client.confirmation_key.present? }
7
9
 
8
10
  def new
9
11
  end
10
12
 
11
13
  def create
12
- @user.request_confirmation
13
- respond_with(@user, location: root_path)
14
+ @client.request_confirmation
15
+ respond_with(@client, location: Nyauth.configuration.redirect_path_after_create_request_confirmation || main_app.root_path)
14
16
  end
15
17
 
16
18
  private
17
19
 
18
- def set_user
19
- @user = User.find_by!(email: params[:user][:email])
20
+ def set_client
21
+ @client = client_class.find_by!(email: params[client_name][:email])
20
22
  rescue ActiveRecord::RecordNotFound
21
23
  render :new
22
24
  end
23
25
 
24
26
  def send_mail
25
- Nyauth::UserMailer.request_confirmation(@user).deliver_now
27
+ Nyauth::RequestMailer.request_confirmation(@client).deliver_now
26
28
  end
27
29
  end
28
30
  end
@@ -1,19 +1,21 @@
1
1
  module Nyauth
2
- class ConfirmationsController < Nyauth::BaseController
2
+ class ConfirmationsController < ApplicationController
3
+ include Nyauth::ApplicationConcern
4
+ include Nyauth::ClientConcern
3
5
  allow_everyone
4
6
  self.responder = ConfirmationResponder
5
7
  respond_to :html, :json
6
- before_action :set_user
8
+ before_action :set_client
7
9
 
8
10
  def update
9
- @user.confirm
10
- respond_with(@user, location: root_path)
11
+ @client.confirm
12
+ respond_with(@client, location: Nyauth.configuration.redirect_path_after_update_confirmation || main_app.root_path)
11
13
  end
12
14
 
13
15
  private
14
16
 
15
- def set_user
16
- @user = User.find_by!(confirmation_key: params[:confirmation_key])
17
+ def set_client
18
+ @client = client_class.find_by!(confirmation_key: params[:confirmation_key])
17
19
  end
18
20
  end
19
21
  end
@@ -1,28 +1,30 @@
1
1
  module Nyauth
2
- class NewPasswordRequestsController < Nyauth::BaseController
2
+ class NewPasswordRequestsController < ApplicationController
3
+ include Nyauth::ApplicationConcern
4
+ include Nyauth::ClientConcern
3
5
  allow_everyone
4
6
  respond_to :html, :json
5
- before_action :set_user, only: [:create]
6
- after_action :send_mail, only: [:create], if: -> { @user.new_password_key.present? }
7
+ before_action :set_client, only: [:create]
8
+ after_action :send_mail, only: [:create], if: -> { @client.new_password_key.present? }
7
9
 
8
10
  def new
9
11
  end
10
12
 
11
13
  def create
12
- @user.request_new_password
13
- respond_with(@user, location: root_path)
14
+ @client.request_new_password
15
+ respond_with(@client, location: Nyauth.configuration.redirect_path_after_new_password_request || main_app.root_path)
14
16
  end
15
17
 
16
18
  private
17
19
 
18
- def set_user
19
- @user = User.find_by!(email: params[:user][:email])
20
+ def set_client
21
+ @client = client_class.find_by!(email: params[client_name][:email])
20
22
  rescue ActiveRecord::RecordNotFound
21
23
  render :new
22
24
  end
23
25
 
24
26
  def send_mail
25
- Nyauth::UserMailer.request_new_password(@user).deliver_now
27
+ Nyauth::RequestMailer.request_new_password(@client).deliver_now
26
28
  end
27
29
  end
28
30
  end
@@ -1,25 +1,27 @@
1
1
  module Nyauth
2
- class NewPasswordsController < Nyauth::BaseController
2
+ class NewPasswordsController < ApplicationController
3
+ include Nyauth::ApplicationConcern
4
+ include Nyauth::ClientConcern
3
5
  allow_everyone
4
6
  respond_to :html, :json
5
- before_action :set_user
7
+ before_action :set_client
6
8
 
7
9
  def edit
8
10
  end
9
11
 
10
12
  def update
11
- @user.update_new_password(user_params)
12
- respond_with(@user, location: nyauth.new_session_path)
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
15
  end
14
16
 
15
17
  private
16
18
 
17
- def set_user
18
- @user = User.find_by!(new_password_key: params[:new_password_key])
19
+ def set_client
20
+ @client = client_class.find_by!(new_password_key: params[:new_password_key])
19
21
  end
20
22
 
21
- def user_params
22
- params.fetch(:user, {})
23
+ def client_params
24
+ params.fetch(client_name, {})
23
25
  .permit(:password, :password_confirmation)
24
26
  end
25
27
  end
@@ -1,25 +1,27 @@
1
1
  module Nyauth
2
- class PasswordsController < Nyauth::BaseController
2
+ class PasswordsController < ApplicationController
3
+ include Nyauth::ApplicationConcern
4
+ include Nyauth::ClientConcern
3
5
  respond_to :html, :json
4
- before_action :set_user
6
+ before_action :set_client
5
7
 
6
8
  def edit
7
9
  end
8
10
 
9
11
  def update
10
- @user.attributes = user_params
11
- @user.save(context: :update_password)
12
- respond_with(@user, location: root_path)
12
+ @client.attributes = client_params
13
+ @client.save(context: :update_password)
14
+ respond_with(@client, location: Nyauth.configuration.redirect_path_after_update_password || main_app.root_path)
13
15
  end
14
16
 
15
17
  private
16
18
 
17
- def set_user
18
- @user = User.find(current_authenticated.id)
19
+ def set_client
20
+ @client = client_class.find(current_authenticated.id)
19
21
  end
20
22
 
21
- def user_params
22
- params.fetch(:user, {})
23
+ def client_params
24
+ params.fetch(client_name, {})
23
25
  .permit(:password, :password_confirmation)
24
26
  end
25
27
  end
@@ -1,25 +1,27 @@
1
1
  module Nyauth
2
- class RegistrationsController < Nyauth::BaseController
2
+ class RegistrationsController < ApplicationController
3
+ include Nyauth::ApplicationConcern
4
+ include Nyauth::ClientConcern
3
5
  allow_everyone
4
6
  respond_to :html, :json
5
- before_action :set_user
7
+ before_action :set_client
6
8
 
7
9
  def new
8
10
  end
9
11
 
10
12
  def create
11
- sign_in(@user) if @user.save
12
- respond_with(@user, location: root_path)
13
+ sign_in(@client) if @client.save
14
+ respond_with(@client, location: Nyauth.configuration.redirect_path_after_registration || main_app.root_path)
13
15
  end
14
16
 
15
17
  private
16
18
 
17
- def set_user
18
- @user = User.new(user_params)
19
+ def set_client
20
+ @client = client_class.new(client_params)
19
21
  end
20
22
 
21
- def user_params
22
- params.fetch(:user, {})
23
+ def client_params
24
+ params.fetch(client_name, {})
23
25
  .permit(:email, :password, :password_confirmation)
24
26
  end
25
27
  end
@@ -1,5 +1,7 @@
1
1
  module Nyauth
2
- class SessionsController < Nyauth::BaseController
2
+ class SessionsController < ApplicationController
3
+ include Nyauth::ApplicationConcern
4
+ include Nyauth::ClientConcern
3
5
  allow_everyone only: [:new, :create]
4
6
  respond_to :html, :json
5
7
  before_action :set_session_service
@@ -8,13 +10,13 @@ module Nyauth
8
10
  end
9
11
 
10
12
  def create
11
- sign_in(@session_service.client) if @session_service.save
12
- respond_with @session_service, location: root_path
13
+ sign_in(@session_service.client) if @session_service.save(as: client_name)
14
+ respond_with @session_service, location: Nyauth.configuration.redirect_path_after_sign_in || main_app.root_path
13
15
  end
14
16
 
15
17
  def destroy
16
18
  sign_out
17
- respond_with @session_service, location: root_path
19
+ respond_with @session_service, location: Nyauth.configuration.redirect_path_after_sign_out || new_session_path
18
20
  end
19
21
 
20
22
  private
@@ -1,11 +1,48 @@
1
1
  module Nyauth
2
2
  module ApplicationHelper
3
3
  def method_missing method, *args, &block
4
- if method =~ /(_url|_path)\z/
4
+ if method =~ /(.+)_path_for\z/
5
+ detect_url_helper($1, *args)
6
+ elsif method =~ /(_url|_path)\z/
5
7
  main_app.send(method, *args)
6
8
  else
7
9
  super
8
10
  end
9
11
  end
12
+
13
+ # OPTIMEZE: :(
14
+ def detect_url_helper(feature, client_name, *args)
15
+ @__methods ||= Nyauth::Engine.routes.url_helpers.instance_methods + Rails.application.routes.url_helpers.instance_methods
16
+ @__candidates ||= @__methods.reject{|m| m =~ /\A(:?rails_|_)/}.map(&:to_s)
17
+ if client_name.to_sym == :user
18
+ detect_url_helper_for_nyauth(feature, *args)
19
+ else
20
+ detect_url_helper_for_app(feature, client_name, *args)
21
+ end
22
+ end
23
+
24
+ def detect_url_helper_for_nyauth(feature, *args)
25
+ path = @__candidates.grep(/\A#{feature}_path\z/).first
26
+ return nil unless path
27
+ nyauth.__send__(path, *args)
28
+ end
29
+
30
+ def detect_url_helper_for_app(feature, client_name, *args)
31
+ if feature =~ /new_(.+)/
32
+ path = @__candidates.grep(/\Anew_#{client_name}_#{$1}_path\z/).first
33
+ else
34
+ path = @__candidates.grep(/\A#{client_name}_#{feature}_path\z/).first
35
+ end
36
+ return nil unless path
37
+ __send__(path, *args)
38
+ end
39
+
40
+ def root_path
41
+ if main_app.respond_to?(:root_path)
42
+ main_app.__send__(:root_path)
43
+ else
44
+ '/'
45
+ end
46
+ end
10
47
  end
11
48
  end
@@ -0,0 +1,15 @@
1
+ module Nyauth
2
+ class RequestMailer < ActionMailer::Base
3
+ default from: "from@example.com"
4
+ layout 'nyauth/mailer'
5
+ def request_confirmation(client)
6
+ @client = client
7
+ mail to: client.email
8
+ end
9
+
10
+ def request_new_password(client)
11
+ @client = client
12
+ mail to: client.email
13
+ end
14
+ end
15
+ end
@@ -1,4 +1,4 @@
1
- = form_for(User.new, url: confirmation_requests_path, mehotd: :post, html: { class: 'pure-form' }) do |f|
1
+ = form_for(client_class.new, url: confirmation_requests_path_for(client_name), mehotd: :post, html: { class: 'pure-form' }) do |f|
2
2
  fieldset
3
3
  legend= t 'nav.confirmation_requests.new'
4
4
  = f.text_field(:email, placeholder: :email)
@@ -1,5 +1,5 @@
1
- - if @user.errors.present?
1
+ - if @client.errors.present?
2
2
  h2 errors
3
3
  ul.errors
4
- - @user.errors.full_messages.each do |e|
4
+ - @client.errors.full_messages.each do |e|
5
5
  li #{e}
@@ -1,4 +1,4 @@
1
- = form_for(User.new, url: new_password_requests_path, mehotd: :post, html: { class: 'pure-form' }) do |f|
1
+ = form_for(client_class.new, url: new_password_requests_path_for(client_name), mehotd: :post, html: { class: 'pure-form' }) do |f|
2
2
  fieldset
3
3
  legend= t 'nav.new_password_requests.new'
4
4
  = f.text_field(:email, placeholder: :email)
@@ -1,10 +1,10 @@
1
- = form_for(@user, url: new_password_path(params[:new_password_key]), html: { class: 'pure-form pure-form-stacked' }) do |f|
1
+ = form_for(@client, url: new_password_path_for(client_name, params[:new_password_key]), html: { class: 'pure-form pure-form-stacked' }) do |f|
2
2
  fieldset
3
3
  legend
4
- - if @user.errors.present?
4
+ - if @client.errors.present?
5
5
  h2 errors
6
6
  ul.errors
7
- - @user.errors.full_messages.each do |e|
7
+ - @client.errors.full_messages.each do |e|
8
8
  li #{e}
9
9
  = f.password_field :password, placeholder: :password
10
10
  = f.password_field :password_confirmation, placeholder: :confirmation
@@ -1,10 +1,10 @@
1
- = form_for(@user, url: password_path, html: { class: 'pure-form pure-form-stacked' }) do |f|
1
+ = form_for(@client, url: password_path_for(client_name), html: { class: 'pure-form pure-form-stacked' }) do |f|
2
2
  fieldset
3
3
  legend
4
- - if @user.errors.present?
4
+ - if @client.errors.present?
5
5
  h2 errors
6
6
  ul.errors
7
- - @user.errors.full_messages.each do |e|
7
+ - @client.errors.full_messages.each do |e|
8
8
  li #{e}
9
9
  = f.password_field :password, placeholder: :password
10
10
  = f.password_field :password_confirmation, placeholder: :confirmation
@@ -1,10 +1,10 @@
1
- = form_for @user, url: registration_path, html: { class: 'pure-form pure-form-stacked' } do |f|
1
+ = form_for @client, url: registration_path_for(client_name), html: { class: 'pure-form pure-form-stacked' } do |f|
2
2
  fieldset
3
3
  legend= t 'nav.registrations.new'
4
- - if @user.errors.present?
4
+ - if @client.errors.present?
5
5
  h2 errors
6
6
  ul.errors
7
- - @user.errors.full_messages.each do |e|
7
+ - @client.errors.full_messages.each do |e|
8
8
  li #{e}
9
9
  = f.text_field :email, placeholder: :email
10
10
  = f.password_field :password, placeholder: :password
@@ -0,0 +1,2 @@
1
+ p Plese confirm your email
2
+ p = link_to 'confirm', confirmation_url(@client.confirmation_key)
@@ -0,0 +1,3 @@
1
+ Plese confirm your email
2
+
3
+ <%= confirmation_url(@client.confirmation_key) %>
@@ -0,0 +1,2 @@
1
+ p Plese set your new password
2
+ p = link_to 'set new password', edit_new_password_url(@client.new_password_key)
@@ -0,0 +1,3 @@
1
+ Plese set your new password
2
+
3
+ <%= edit_new_password_url(@client.new_password_key) %>
@@ -1,4 +1,4 @@
1
- = form_for @session_service, url: session_path, html: { class: 'pure-form' } do |f|
1
+ = form_for @session_service, url: session_path_for(client_name), html: { class: 'pure-form' } do |f|
2
2
  fieldset
3
3
  legend= t 'nav.sessions.new'
4
4
  - if @session_service.errors.present?
@@ -9,7 +9,3 @@
9
9
  = f.email_field :email, placeholder: :email
10
10
  = f.password_field :password, placeholder: :password
11
11
  = f.submit 'Sign in', data: { disable_with: '...' }, class: 'pure-button pure-button-primary'
12
-
13
- ul
14
- li= link_to 'sign up', new_registration_path
15
- li= link_to 'request new password', new_new_password_request_path
data/config/routes.rb CHANGED
@@ -6,5 +6,5 @@ Nyauth::Engine.routes.draw do
6
6
  get '/confirmations/:confirmation_key' => 'confirmations#update', as: :confirmation
7
7
  resources :new_password_requests, only: %i(new create)
8
8
  resources :new_passwords, param: :new_password_key, only: %i(edit update)
9
- root 'sessions#new'
9
+ Nyauth.configuration.setup_redirect_path
10
10
  end
@@ -0,0 +1,11 @@
1
+ module Nyauth
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("../templates", __FILE__)
4
+ desc "Creates Nyauth initializer for your application"
5
+
6
+ def copy_initializer
7
+ template "nyauth_install_initializer.rb", "config/initializers/nyauth.rb"
8
+ puts "Install complete"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ Nyauth.configure do |config|
2
+ config.redirect_path do |urls|
3
+ # config.redirect_path_after_sign_in = urls.admin_secret_notes_path
4
+ # config.redirect_path_after_sign_out = urls.root_path
5
+ # config.redirect_path_after_registration = urls.root_path
6
+ end
7
+ end
@@ -0,0 +1,40 @@
1
+ module Nyauth
2
+ class Configuration
3
+ attr_accessor :redirect_path_block,
4
+ :redirect_path_after_sign_in,
5
+ :redirect_path_after_sign_out,
6
+ :redirect_path_after_registration,
7
+ :redirect_path_after_create_request_confirmation,
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
12
+
13
+
14
+ def initialize
15
+ @redirect_path_after_sign_in = nil
16
+ @redirect_path_after_sign_out = nil
17
+ @redirect_path_after_registration = nil
18
+ @redirect_path_after_create_request_confirmation = nil
19
+ @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_update_password = nil
23
+ @redirect_path_block = Proc.new {}
24
+ end
25
+
26
+ def redirect_path(&block)
27
+ @redirect_path_block = block
28
+ end
29
+
30
+ def setup_redirect_path
31
+ UrlHelper.class_eval do
32
+ include Rails.application.routes.url_helpers
33
+ end
34
+ @redirect_path_block.call(UrlHelper.new)
35
+ end
36
+ end
37
+
38
+ class UrlHelper
39
+ end
40
+ end
data/lib/nyauth/engine.rb CHANGED
@@ -10,6 +10,8 @@ module Nyauth
10
10
  class Engine < ::Rails::Engine
11
11
  isolate_namespace Nyauth
12
12
 
13
+ config.nyauth = ActiveSupport::OrderedOptions.new
14
+ config.nyauth.admin = 'admin'
13
15
  config.i18n.load_path += Dir[Engine.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
14
16
  config.generators do |g|
15
17
  g.test_framework :rspec, fixture: false
@@ -1,3 +1,3 @@
1
1
  module Nyauth
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/nyauth.rb CHANGED
@@ -1,5 +1,15 @@
1
1
  require 'nyauth/engine'
2
2
  require 'nyauth/encryptor'
3
+ require 'nyauth/configuration'
3
4
 
4
5
  module Nyauth
6
+ class << self
7
+ attr_accessor :configuration
8
+ end
9
+
10
+ def self.configure
11
+ self.configuration ||= Configuration.new
12
+ yield(configuration)
13
+ end
5
14
  end
15
+ Nyauth.configure {}
@@ -0,0 +1,4 @@
1
+ class PagesController < ApplicationController
2
+ def index
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ class PostsController < ApplicationController
2
+ def index
3
+ head :ok
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ class Admin < ActiveRecord::Base
2
+ include Nyauth::Authenticatable
3
+ end