smithycms-auth 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = SmithyCMS Auth
2
+
3
+ Smithy CMS ships with no authentication but is able to utilize other authentication/authorization systems. This implements a basic has_secure_password in a Smithy::User model
4
+
5
+ To roll your own or use an existing auth scheme, you need #smithy_current_user, #smithy_login_path & #smithy_logout_path helper methods (see `authentication_helpers.rb`). You also need to provide the appropriate routes (see `routes.rb`).
6
+
7
+ Lastly, your User model (whatever it may be) needs to expose a #smithy_admin? method. We leave the implementation details up to you.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'SmithyAuth'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,31 @@
1
+ module Smithy
2
+ class UserSessionsController < BaseController
3
+ skip_before_filter :authenticate_smithy_admin, :only => [:new, :create]
4
+
5
+ def new
6
+ Smithy.log :debug, "[Auth] Entering UserSessionsController#new"
7
+ end
8
+
9
+ def create
10
+ Smithy.log :debug, "[Auth] Entering UserSessionsController#create"
11
+ user = User.find_by_email(params[:login][:email])
12
+ Smithy.log :debug, "[Auth] user found: #{user.inspect}"
13
+ if user && user.authenticate(params[:login][:password])
14
+ Smithy.log :debug, "[Auth] User authenticated"
15
+ session[:user_id] = user.id
16
+ Smithy.log :debug, "[Auth] session[:user_id]: #{session[:user_id].inspect}"
17
+ redirect_to pages_path, :notice => "Logged in!"
18
+ else
19
+ flash.now.alert = "Invalid email or password"
20
+ render "new"
21
+ end
22
+ end
23
+
24
+ def destroy
25
+ session[:user_id] = nil
26
+ Smithy.log :debug, "[Auth] User signed out"
27
+ Smithy.log :debug, "[Auth] session[:user_id]: #{session[:user_id].inspect}"
28
+ redirect_to root_url, :notice => "Logged out!"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,50 @@
1
+ module Smithy
2
+ class UsersController < BaseController
3
+
4
+ before_filter :load_users
5
+ respond_to :html, :json
6
+
7
+ def index
8
+ respond_with @users
9
+ end
10
+
11
+ def new
12
+ @user = User.new(params[:user])
13
+ respond_with @user
14
+ end
15
+
16
+ def create
17
+ @user = User.new(params[:user])
18
+ @user.save
19
+ flash.notice = "The user was created" if @user.persisted?
20
+ respond_with @user do |format|
21
+ format.html { redirect_to [:edit, @user] }
22
+ end
23
+ end
24
+
25
+ def edit
26
+ @user = User.find(params[:id])
27
+ respond_with @user
28
+ end
29
+
30
+ def update
31
+ @user = User.find(params[:id])
32
+ flash.notice = "The user was saved" if @user.update_attributes(params[:user])
33
+ respond_with @user do |format|
34
+ format.html { redirect_to [:edit, @user] }
35
+ end
36
+ end
37
+
38
+ def destroy
39
+ @user = User.find(params[:id])
40
+ @user.destroy
41
+ respond_with @user
42
+ end
43
+
44
+ private
45
+ def load_users
46
+ @users = User.order(:email)
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,4 @@
1
+ module SmithyAuth
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ module Smithy
2
+ class User < ActiveRecord::Base
3
+ attr_accessible :email, :password, :password_confirmation
4
+
5
+ validates_presence_of :email
6
+ validates_presence_of :password, :on => :create
7
+
8
+ has_secure_password
9
+
10
+ def smithy_admin?
11
+ true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ <% content_for :title, "Login" %>
2
+
3
+ <%= semantic_form_for :login, :url => smithy.user_session_path do |f| %>
4
+ <%= f.inputs :email, :password %>
5
+ <%= f.actions do %>
6
+ <%= f.action :submit, :label => "Login" %>
7
+ <% end %>
8
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <%= semantic_form_for @user, :html => { :class => 'form-horizontal' } do |f| %>
2
+ <%= f.inputs "User" do %>
3
+ <%= f.input :email %>
4
+ <%= f.input :password %>
5
+ <%= f.input :password_confirmation %>
6
+ <% end %>
7
+ <%= f.actions :submit %>
8
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <% content_for :secondary_nav do %>
2
+ <ul class="nav nav-list">
3
+ <li class="nav-header">Users</li>
4
+ <%= render @users %>
5
+ </ul>
6
+
7
+ <div class="btn-group actions pull-right">
8
+ <%= link_to "<i class=\"icon-plus\"></i> Add User".html_safe, new_user_path, :class => 'btn btn-inverse', :role => 'button' %>
9
+ </div>
10
+ <% end %>
@@ -0,0 +1 @@
1
+ <li<%= raw ' class="active"' if action_name == "edit" && @user == user %>><%= link_to user.email, [:edit, user] %></li>
@@ -0,0 +1,9 @@
1
+ <% content_for :title, "Users" %>
2
+
3
+ <%= render :partial => 'form' %>
4
+
5
+ <% content_for :related do %>
6
+ <p><%= link_to "Delete User", @user, :method => :delete, :confirm => "Are you sure you want to delete this user?", :class => 'btn btn-danger' %></p>
7
+ <% end %>
8
+
9
+ <%= render :partial => "secondary_nav" %>
@@ -0,0 +1,14 @@
1
+ <% content_for :title, "Users" %>
2
+
3
+ <div class="hero-unit">
4
+ <%- if @users.empty? -%>
5
+ <p>Be the first to add a User to your site.</p>
6
+ <% else %>
7
+ <p>Add a user or select one from your left to edit.</p>
8
+ <% end %>
9
+ <p>
10
+ <%= link_to "Add User", new_user_path, :class => 'btn btn-primary btn-large' %>
11
+ </p>
12
+ </div>
13
+
14
+ <%= render :partial => "secondary_nav" %>
@@ -0,0 +1,5 @@
1
+ <% content_for :title, "Users" %>
2
+
3
+ <%= render :partial => 'form' %>
4
+
5
+ <%= render :partial => "secondary_nav" %>
data/config/routes.rb ADDED
@@ -0,0 +1,8 @@
1
+ Smithy::Engine.routes.prepend do
2
+ scope '/smithy' do
3
+ match '/login' => 'user_sessions#new', :as => :login
4
+ match '/logout' => 'user_sessions#destroy', :via => :delete, :as => :logout
5
+ resource :user_session, :only => [:new, :create, :destroy]
6
+ resources :users
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class CreateSmithyUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :smithy_users do |t|
4
+ t.string :email
5
+ t.string :password_digest
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module Smithy
2
+ module Auth
3
+ class Engine < Rails::Engine
4
+ isolate_namespace Smithy
5
+ engine_name 'smithy_auth' # the underscore allows proper naming for migrations with `rake smithy_auth:install:migrations`
6
+
7
+ def self.activate
8
+ ApplicationController.send :include, Smithy::AuthenticationHelpers
9
+ end
10
+
11
+ config.to_prepare &method(:activate).to_proc
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Smithy
2
+ module Auth
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ module Smithy
2
+ module AuthenticationHelpers
3
+ def self.included(receiver)
4
+ receiver.send :helper_method, :current_user
5
+ receiver.send :helper_method, :smithy_current_user
6
+ receiver.send :helper_method, :smithy_login_path
7
+ receiver.send :helper_method, :smithy_logout_path
8
+ end
9
+
10
+ def current_user
11
+ @current_user ||= Smithy::User.find(session[:user_id]) if session[:user_id]
12
+ end
13
+
14
+ def smithy_current_user
15
+ current_user
16
+ end
17
+
18
+ def smithy_login_path
19
+ smithy.login_path
20
+ end
21
+
22
+ def smithy_logout_path
23
+ smithy.logout_path
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,2 @@
1
+ require 'smithy/auth/engine'
2
+ require 'smithy/authentication_helpers'
@@ -0,0 +1 @@
1
+ require 'smithy-auth'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :smithy-auth do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,249 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smithycms-auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tim Glen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-01-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bcrypt-ruby
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: smithycms
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: capybara
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: debugger
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard-spork
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rspec-rails
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rb-fsevent
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: shoulda-matchers
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: spork
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: sqlite3
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ description: Smithy CMS ships with no authentication. This implements a basic has_secure_password
191
+ in a Smithy::User model
192
+ email:
193
+ - tim@tag.ca
194
+ executables: []
195
+ extensions: []
196
+ extra_rdoc_files: []
197
+ files:
198
+ - app/assets/javascripts/smithy-auth/application.js
199
+ - app/assets/stylesheets/smithy-auth/application.css
200
+ - app/controllers/smithy/user_sessions_controller.rb
201
+ - app/controllers/smithy/users_controller.rb
202
+ - app/helpers/smithy-auth/application_helper.rb
203
+ - app/models/smithy/user.rb
204
+ - app/views/smithy/user_sessions/new.html.erb
205
+ - app/views/smithy/users/_form.html.erb
206
+ - app/views/smithy/users/_secondary_nav.html.erb
207
+ - app/views/smithy/users/_user.html.erb
208
+ - app/views/smithy/users/edit.html.erb
209
+ - app/views/smithy/users/index.html.erb
210
+ - app/views/smithy/users/new.html.erb
211
+ - config/routes.rb
212
+ - db/migrate/20130402202356_create_smithy_users.rb
213
+ - lib/smithy/auth/engine.rb
214
+ - lib/smithy/auth/version.rb
215
+ - lib/smithy/authentication_helpers.rb
216
+ - lib/smithy-auth.rb
217
+ - lib/smithycms-auth.rb
218
+ - lib/tasks/smithy-auth_tasks.rake
219
+ - MIT-LICENSE
220
+ - Rakefile
221
+ - README.rdoc
222
+ homepage: https://github.com/sterrym/smithycms-auth
223
+ licenses: []
224
+ post_install_message:
225
+ rdoc_options: []
226
+ require_paths:
227
+ - lib
228
+ required_ruby_version: !ruby/object:Gem::Requirement
229
+ none: false
230
+ requirements:
231
+ - - ! '>='
232
+ - !ruby/object:Gem::Version
233
+ version: 1.9.3
234
+ required_rubygems_version: !ruby/object:Gem::Requirement
235
+ none: false
236
+ requirements:
237
+ - - ! '>='
238
+ - !ruby/object:Gem::Version
239
+ version: '0'
240
+ segments:
241
+ - 0
242
+ hash: -1149123323603983115
243
+ requirements: []
244
+ rubyforge_project:
245
+ rubygems_version: 1.8.23
246
+ signing_key:
247
+ specification_version: 3
248
+ summary: Provides basic authentication to Smithy CMS
249
+ test_files: []