super_simple_admin 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/Changelog +0 -0
  2. data/LICENSE +16 -0
  3. data/README +87 -0
  4. data/lib/super_simple_admin.rb +78 -0
  5. metadata +70 -0
data/Changelog ADDED
File without changes
data/LICENSE ADDED
@@ -0,0 +1,16 @@
1
+ Super Simple Admin
2
+ Basic authentication system al a Ryan Bates screen cast on super simple authentication
3
+ Copyright (C) 2010 Christopher Small
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
data/README ADDED
@@ -0,0 +1,87 @@
1
+ h1. Super Simple Admin README
2
+
3
+ Super Simple Authentication is a gem which makes it super easy to encapsulate the behavior of the Ryan Bates screen cast on super simple authentication.
4
+
5
+ This is still a work in progress, so don't expect too detailed instructions just yet. I'll update as things move forward.
6
+
7
+ h2. Basic Usage
8
+
9
+ In your ApplicationController do
10
+
11
+ bc. class ApplicationController
12
+ include SuperSimpleAdmin::ApplicationController
13
+ end
14
+
15
+ Create a sessions controller that looks like this
16
+
17
+ bc. class SessionsController
18
+ include SuperSimpleAdmin::SessionsController
19
+ end
20
+
21
+ Now create a app/views/sessions/new.html.haml file (you are using haml, aren't you?) that looks something like this
22
+
23
+ bc. #login_form
24
+ %p
25
+ - form_tag sessions_path do
26
+ = label_tag :password, "Password:"
27
+ = password_field_tag :password
28
+ = submit_tag "Submit"
29
+
30
+ You can now use the @admin?@ helper method in any of your views to change what website users see based on whether they are logged in and also use @authorize@ in before filters in your controllers to restrict access as you see fit.
31
+
32
+ And that's it!
33
+
34
+ h2. Customization, configuration and defaults
35
+
36
+ So you're probably wondering how to customize this bugger. There are two easy ways to do this, and both are perfectly acceptable are interoperable. However, there are defaults for everything so that you can get up and running without having to think. You'll obviously at least want to set your own password once in production though.
37
+
38
+ h3. Hash access
39
+
40
+ The innards of this gem refer to the @SuperSimpleAdmin.config@ hash for all of the configurable settings. As such (by way of example), you can specify or access settings like this
41
+
42
+ bc. SuperSimpleAdmin.config[:password] = "verysecret"
43
+ SuperSimpleAdmin.config[:password] == params[:password]
44
+
45
+ Cake right?
46
+
47
+ h3. Configuration file
48
+
49
+ When the parent SuperSimpleAdmin module is loaded it looks to see if there is a admin_config.yml file in your config directory and if there is loads it up for you. Anything set here will override gem defaults. This is only loaded once though, which means you can still use hash access later on in your code to modify config parameters (as above).
50
+
51
+ Environment independent settings are specified within all_environments, while environment specific setting are set within @RAILS_ENV@ as below
52
+
53
+ bc. all_environments:
54
+ password: somewhatsecret
55
+ unauthorization_message: "You are not authorized to view this page"
56
+ production:
57
+ password: verysecret
58
+
59
+
60
+ h3. Defaults
61
+
62
+ The default options are as follows
63
+
64
+ bc. SuperSimpleAdmin.config = {
65
+ :password => "secret",
66
+ :unauthorized_message => "Unauthorized access",
67
+ :unauthorized_redirect => "/",
68
+ :login_success_message => "Successfully logged in",
69
+ :login_success_redirect => "/",
70
+ :login_failure_message => "Incorrect password",
71
+ :login_failures_redirect => "sessions/new",
72
+ :logout_message => "Logout successful",
73
+ :logout_redirect => "/"
74
+ }
75
+
76
+ h2. TODO
77
+
78
+ These are the ideas I have for improvements. If you feel inspired to help with any of them, fork and send a request. I'd especially appreciate help with speccing, as I have no experience speccing gems (even a shove in the right direction here would be great).
79
+
80
+ * Want to have a generator for the new sessions page.
81
+ * Consider if there is a way to be more supportive of gems like cancan
82
+ * Auto setup of login and logout routes
83
+ * Specs
84
+
85
+ h3. Fixes
86
+
87
+ * Add @helper_method :admin@ to ApplicationController
@@ -0,0 +1,78 @@
1
+ # Parent Module. Right now just contains the ApplicationController and
2
+ # SessionsController submodules.
3
+ module SuperSimpleAdmin
4
+ # This sets default configuration parameters for the gem and
5
+ # makes them accessible in the application through the
6
+ # SuperSimpleAdmin.config hash
7
+ class << self; attr_accessor :config end
8
+ @config = {
9
+ :password => "secret",
10
+ :unauthorized_message => "Unauthorized access",
11
+ :unauthorized_redirect => "/",
12
+ :login_success_message => "Successfully logged in",
13
+ :login_success_redirect => "/",
14
+ :login_failure_message => "Incorrect password",
15
+ :login_failure_redirect => "/sessions/new",
16
+ :logout_message => "Logout successful",
17
+ :logout_redirect => "/"
18
+ }
19
+ # This sets the Admin variables based off of the values set in the
20
+ # admin_config.yml file if there is one and overrides any default
21
+ # values set above
22
+ begin
23
+ raw_config = File.read(RAILS_ROOT + "/config/admin_config.yml")
24
+ yml = YAML.load(raw_config)
25
+ @config.merge yml["all_environments"].symbolize_keys
26
+ @config.merge yml[RAILS_ENV].symbolize_keys
27
+ rescue Errno::ENOENT
28
+ end
29
+
30
+ # Load this module into your application controller
31
+ module ApplicationController
32
+ # Sets up the admin? helper method for use in views
33
+ def self.included(controller)
34
+ controller.send :helper_method, :admin?
35
+ end
36
+ protected
37
+ # This method can be used in before
38
+ # filters in other controllers to restrict access.
39
+ # May update this later to be operable with
40
+ # CanCan or AuthLogic.
41
+ def authorize
42
+ unless admin?
43
+ flash[:notice] = SuperSimpleAdmin.config[:unauthorized_message]
44
+ redirect_to SuperSimpleAdmin.config[:unauthorized_redirect]
45
+ false
46
+ end
47
+ end
48
+ # The admin method tells us whether we are logged in.
49
+ def admin?
50
+ session[:password] == SuperSimpleAdmin.config[:password]
51
+ end
52
+ end
53
+
54
+
55
+ # This contains code for the sessions controller to hook into
56
+ module SessionsController
57
+ def create
58
+ session[:password] = params[:password]
59
+ if session[:password] == SuperSimpleAdmin.config[:password]
60
+ flash[:notice] = SuperSimpleAdmin.config[:login_success_message]
61
+ redirect_to SuperSimpleAdmin.config[:login_success_redirect]
62
+ else
63
+ flash[:notice] = SuperSimpleAdmin.config[:login_failure_message]
64
+ redirect_to SuperSimpleAdmin.config[:login_failure_redirect]
65
+ end
66
+ end
67
+
68
+ def destroy
69
+ reset_session
70
+ flash[:notice] = SuperSimpleAdmin.config[:logout_message]
71
+ redirect_to SuperSimpleAdmin.config[:logout_redirect]
72
+ end
73
+
74
+ def new
75
+
76
+ end
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: super_simple_admin
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Christopher Small
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-28 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Provides super simple authentication al a Ryan Bates old screen cast. Creates admin access feature which allows for a single password login for admin tool access.
23
+ email: metasoarous@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README
32
+ - Changelog
33
+ - LICENSE
34
+ - lib/super_simple_admin.rb
35
+ has_rdoc: true
36
+ homepage: http://www.sharp-logic.com/
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.7
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Provides super simple authentication al a Ryan Bates old screen cast.
69
+ test_files: []
70
+