spree_auth_disabler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,93 @@
1
+ = SpreeAuthDisabler extension
2
+
3
+ This extension aims to extend the spree auth logic by options for disabling:
4
+
5
+ * Client singup
6
+ * Password recovery
7
+ * Client login
8
+
9
+ Since the extension included in your Gemfile all listed features will be
10
+ disabled by default.
11
+
12
+ Use Spree::Auth::Disabler::Config (spree_auth_disabler:app/models/spree_auth_disabler_configuration.rb)
13
+ for switch this preferences:
14
+
15
+ * :client_signup_enabled, :default => false
16
+ * :password_recoverty_enabled, :default => false
17
+ * :client_login_enabled, :default => false
18
+
19
+ NOTE: it is recomended to enable client login if client signup enabled, lest
20
+ clients will get 'Authorization failed' after signup (but the user and the session
21
+ will be created). See issues below.
22
+
23
+ == Installing
24
+
25
+ ==== Add into your Gemfile
26
+
27
+ gem 'spree_auth_disabler'
28
+
29
+ or
30
+
31
+ gem 'spree_auth_disabler', :git => 'git://github.com/x2es/spree_auth_disabler.git'
32
+
33
+ NOTE: this extension overrides several views. Loading order does matter. You should place
34
+ this gem above an your theme, at least.
35
+ If other your extensions overrides an auth-views you should decide right loading order.
36
+ You may find useful the gem 'painless_partials' for inspecting the usage roadmap of views.
37
+
38
+ ==== Setup your Spree::Auth::Disabler::Config propertly (see bellow).
39
+
40
+ == Configuration ways
41
+
42
+ You can use the Spree::Auth::Disabler::Config in such manner as the Spree::Config or Spreee::Auth::Config
43
+
44
+ Spree::Auth::Disabler::Config[:client_login_enabled] # Returns the foo preference
45
+ Spree::Auth::Disabler::Config[] # Returns a Hash with all the preferences
46
+ Spree::Auth::Disabler::Config.instance # Returns the configuration object
47
+ Spree::Auth::Disabler::Config.set(:client_login_enabled => true) # Set the spree auth preferences as especified in +preference_hash+
48
+
49
+ Default values initialized in spree_auth_disabler:app/models/spree_auth_disabler_configuration.rb
50
+
51
+ TODO: two words about overriding preferences class facilities
52
+
53
+ See the guide http://edgeguides.spreecommerce.com/preferences.html for more details
54
+
55
+ == Configuration explanation
56
+
57
+ * unless :client_signup_enabled
58
+
59
+ * signup actions will be disabled (new and create), the user will be redirected to root_url, flash[:error] will be supplied
60
+ * link to signup from login form will be hidden
61
+
62
+ * unless :password_recoverty_enabled
63
+
64
+ * password recovery actions will be disabled (new and create), redirect and flash[:error] are same as above
65
+ * link to password recovery from login form will be hidden
66
+
67
+ * unless :client_login_enabled
68
+
69
+ * login actions will deny client login (only create), redirect and flash[:error] are same as above
70
+ * link to login form will be hidden
71
+
72
+ NOTE:
73
+ If you have overrided layouts/spree_application.html.erb, you may want to remove the <li> tag
74
+ surrond the <%= render 'shared/login_bar' %> since an <li> alerady exists in this partial
75
+
76
+ == Extensions collisions
77
+
78
+ This extension overrides some views. If you already overrided views, which overrided in this extension too,
79
+ you may want to checkout differences and apply some changes to your views.
80
+
81
+ = TODO
82
+
83
+ * Specs!
84
+
85
+ == Issues
86
+
87
+ * 'Autorization failed' ISSUE, when client login disabled, but client signup enabled (after signup)
88
+
89
+ = Help me
90
+
91
+ * to fix English grammar in this text (now I am tring to setup articles, but I am not feel yet this aspect to do this job propertly)
92
+
93
+
@@ -0,0 +1,14 @@
1
+ PasswordResetsController.class_eval do
2
+ before_filter :password_reset_disabler, :only => [:new, :create]
3
+
4
+ private
5
+
6
+ def password_reset_disabler
7
+ unless Spree::Auth::Disabler::Config[:password_recovery_enabled]
8
+ # TODO: workaround wariants
9
+ flash[:error] = t('spree_auth_disabler.password_recovery_disabled')
10
+ redirect_to root_url
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,17 @@
1
+ UserSessionsController.class_eval do
2
+ before_filter :client_login_disabler, :only => :create
3
+
4
+ private
5
+
6
+ # TODO: to create specs for this
7
+ def client_login_disabler
8
+ unless Spree::Auth::Disabler::Config[:client_login_enabled]
9
+ # TODO: add variants of workaround (404 and so on)
10
+ if (user = User.find_by_email(params[:user_session]['login'])) && (!user.has_role? :admin)
11
+ flash[:error] = t('spree_auth_disabler.client_login_disabled')
12
+ redirect_to root_url
13
+ end
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,16 @@
1
+ UsersController.class_eval do
2
+
3
+ before_filter :signup_disabler, :only => [:new, :create]
4
+
5
+ private
6
+
7
+ # TODO: to create specs for this
8
+ def signup_disabler
9
+ unless Spree::Auth::Disabler::Config[:client_signup_enabled]
10
+ # TODO: create variants of workaround (root redirect, 404 and so on)
11
+ flash[:error] = t('spree_auth_disabler.client_signup_disabled')
12
+ redirect_to root_url
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,14 @@
1
+ class SpreeAuthDisablerConfiguration < Configuration
2
+
3
+ # Usage
4
+ # Spree::Auth::Disabler::Config[:client_signup_enabled]
5
+ # Spree::Auth::Disabler::Config.set :client_signup_enabled => true/false
6
+ # ...
7
+ # (see lib/spree_auth_disable_config.rb)
8
+ #
9
+ # or you may override this class such as regular spree configurations
10
+
11
+ preference :client_signup_enabled, :boolean, :default => false
12
+ preference :password_recovery_enabled, :boolean, :default => false
13
+ preference :client_login_enabled, :boolean, :default => false
14
+ end
@@ -0,0 +1,6 @@
1
+ <% if current_user %>
2
+ <li><%= link_to t('my_account'), account_path %></li>
3
+ <li><%= link_to t('logout'), logout_path %></li>
4
+ <% elsif Spree::Auth::Disabler::Config[:client_login_enabled] %>
5
+ <li><%= link_to t('log_in'), login_path %></li>
6
+ <% end %>
@@ -0,0 +1,17 @@
1
+ <% @body_id = 'login' %>
2
+ <div id="existing-customer">
3
+ <h2><%= t("login_as_existing") %></h2>
4
+ <%= hook :login do %>
5
+ <%= render :partial => 'shared/login' %>
6
+ <%=
7
+ account_links = []
8
+ account_links << link_to(t("create_a_new_account"), signup_path) if Spree::Auth::Disabler::Config[:client_signup_enabled]
9
+ account_links << link_to(t("forgot_password"), new_password_reset_path) if Spree::Auth::Disabler::Config[:password_recovery_enabled]
10
+
11
+ if account_links.any?
12
+ "#{t('or')} #{account_links.join(' | ')}".html_safe
13
+ end
14
+ %>
15
+ <% end %>
16
+ </div>
17
+
@@ -0,0 +1,8 @@
1
+ ---
2
+ en:
3
+ spree_auth_disabler:
4
+ client_signup_disabled: 'Signup disallowed'
5
+ password_recovery_disabled: 'Password recovery disabled'
6
+ client_login_disabled: 'Client login disallowed'
7
+
8
+
@@ -0,0 +1,8 @@
1
+ ---
2
+ ru-RU:
3
+ spree_auth_disabler:
4
+ client_signup_disabled: 'Регистрация не возможна'
5
+ password_recovery_disabled: 'Восстановление пароля отключено'
6
+ client_login_disabled: 'Личный кабинет пользователей отключен'
7
+
8
+
@@ -0,0 +1,18 @@
1
+ require 'spree_core'
2
+ require 'spree_auth_disabler_hooks'
3
+ require 'spree_auth_disabler_config'
4
+
5
+ module SpreeAuthDisabler
6
+ class Engine < Rails::Engine
7
+
8
+ config.autoload_paths += %W(#{config.root}/lib)
9
+
10
+ def self.activate
11
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
12
+ Rails.env.production? ? require(c) : load(c)
13
+ end
14
+ end
15
+
16
+ config.to_prepare &method(:activate).to_proc
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ module Spree
2
+ module Auth
3
+ module Disabler
4
+ # Singleton class to access the shipping configuration object and it's preferences (this seems like spree_auth:/lib/spree/auth/config.rb).
5
+ #
6
+ # Usage:
7
+ # Spree::Auth::Disabler::Config[:foo] # Returns the foo preference
8
+ # Spree::Auth::Disabler::Config[] # Returns a Hash with all the preferences
9
+ # Spree::Auth::Disabler::Config.instance # Returns the configuration object
10
+ # Spree::Auth::Disabler::Config.set(preferences_hash) # Set the spree auth preferences as especified in +preference_hash+
11
+ class Config
12
+ include Singleton
13
+ include Spree::PreferenceAccess
14
+
15
+ class << self
16
+ def instance
17
+ return nil unless ActiveRecord::Base.connection.tables.include?('configurations')
18
+ SpreeAuthDisablerConfiguration.find_or_create_by_name("spree_auth_disabler")
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ class SpreeAuthDisablerHooks < Spree::ThemeSupport::HookListener
2
+ # custom hooks go here
3
+ end
@@ -0,0 +1,26 @@
1
+ namespace :spree_auth_disabler do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_auth_disabler:install:migrations'].invoke
5
+ Rake::Task['spree_auth_disabler:install:assets'].invoke
6
+ end
7
+
8
+ namespace :install do
9
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
10
+ task :migrations do
11
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
12
+ destination = File.join(Rails.root, 'db')
13
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
14
+ Spree::FileUtilz.mirror_files(source, destination)
15
+ end
16
+
17
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
18
+ task :assets do
19
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
20
+ destination = File.join(Rails.root, 'public')
21
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
22
+ Spree::FileUtilz.mirror_files(source, destination)
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_auth_disabler
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - x@ES
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-15 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: spree_core
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 30
31
+ - 1
32
+ version: 0.30.1
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: "[Spree-0.30+] extension for disabling client signup/auth features. See details in README on github."
36
+ email: KEIvanov@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - README.rdoc
45
+ - lib/spree_auth_disabler_hooks.rb
46
+ - lib/spree_auth_disabler.rb
47
+ - lib/spree_auth_disabler_config.rb
48
+ - lib/tasks/install.rake
49
+ - lib/tasks/spree_auth_disabler.rake
50
+ - config/locales/en.yml
51
+ - config/locales/ru-RU.yml
52
+ - app/views/shared/_login_bar.html.erb
53
+ - app/views/user_sessions/new.html.erb
54
+ - app/controllers/password_resets_controller_decorator.rb
55
+ - app/controllers/users_controller_decorator.rb
56
+ - app/controllers/user_sessions_controller_decorator.rb
57
+ - app/models/spree_auth_disabler_configuration.rb
58
+ has_rdoc: true
59
+ homepage: https://github.com/x2es/spree_auth_disabler
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 1
74
+ - 8
75
+ - 7
76
+ version: 1.8.7
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements:
86
+ - none
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.7
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: "[Spree-0.30+] extension for disabling client signup/auth features. See details in README on github."
92
+ test_files: []
93
+