kryptonite 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/Gemfile +1 -0
  2. data/MIT-LICENSE +20 -0
  3. data/PUBLIC_VERSION.yml +4 -0
  4. data/README.rdoc +209 -0
  5. data/Rakefile +40 -0
  6. data/app/controllers/kryptonite/kryptonite_controller.rb +72 -0
  7. data/app/controllers/kryptonite/password_resets_controller.rb +66 -0
  8. data/app/controllers/kryptonite/user_sessions_controller.rb +40 -0
  9. data/app/controllers/kryptonite/users_controller.rb +102 -0
  10. data/app/helpers/kryptonite/kryptonite_helper.rb +200 -0
  11. data/app/mailers/kryptonite/kryptonite_notification.rb +39 -0
  12. data/app/models/kryptonite/user.rb +55 -0
  13. data/app/models/kryptonite/user_session.rb +8 -0
  14. data/app/views/kryptonite/kryptonite/blank.html.erb +1 -0
  15. data/app/views/kryptonite/kryptonite_notification/generate_new_password.erb +12 -0
  16. data/app/views/kryptonite/kryptonite_notification/new_user_information.erb +12 -0
  17. data/app/views/kryptonite/kryptonite_notification/password_reset_instructions.erb +11 -0
  18. data/app/views/kryptonite/password_resets/edit.html.erb +48 -0
  19. data/app/views/kryptonite/user_sessions/new.html.erb +66 -0
  20. data/app/views/kryptonite/users/index.html.erb +35 -0
  21. data/app/views/kryptonite/users/new.html.erb +46 -0
  22. data/app/views/kryptonite/users/show.html.erb +94 -0
  23. data/app/views/layouts/kryptonite_auth.html.erb +24 -0
  24. data/app/views/layouts/kryptonite_main.html.erb +67 -0
  25. data/config/routes.rb +20 -0
  26. data/lib/generators/kryptonite/install/USAGE +1 -0
  27. data/lib/generators/kryptonite/install/install_generator.rb +37 -0
  28. data/lib/generators/kryptonite/install/templates/app/helpers/kryptonite/config_helper.rb +46 -0
  29. data/lib/generators/kryptonite/install/templates/app/views/kryptonite/layouts/_left_navigation.html.erb +2 -0
  30. data/lib/generators/kryptonite/install/templates/app/views/kryptonite/layouts/_right_navigation.html.erb +1 -0
  31. data/lib/generators/kryptonite/install/templates/db/migrate/kryptonite_create_users.rb +30 -0
  32. data/lib/generators/kryptonite/install/templates/public/casein/javascripts/custom.js +2 -0
  33. data/lib/generators/kryptonite/install/templates/public/casein/stylesheets/custom.css +2 -0
  34. data/lib/generators/kryptonite/install/templates/public/robots.txt +5 -0
  35. data/lib/generators/kryptonite/scaffold/USAGE +1 -0
  36. data/lib/generators/kryptonite/scaffold/scaffold_generator.rb +99 -0
  37. data/lib/generators/kryptonite/scaffold/templates/controller.rb +60 -0
  38. data/lib/generators/kryptonite/scaffold/templates/migration.rb +13 -0
  39. data/lib/generators/kryptonite/scaffold/templates/model.rb +3 -0
  40. data/lib/generators/kryptonite/scaffold/templates/views/_form.html.erb +9 -0
  41. data/lib/generators/kryptonite/scaffold/templates/views/_table.html.erb +17 -0
  42. data/lib/generators/kryptonite/scaffold/templates/views/index.html.erb +11 -0
  43. data/lib/generators/kryptonite/scaffold/templates/views/new.html.erb +18 -0
  44. data/lib/generators/kryptonite/scaffold/templates/views/show.html.erb +18 -0
  45. data/lib/generators/kryptonite/update/USAGE +1 -0
  46. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/casein.png +0 -0
  47. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/header.png +0 -0
  48. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/icons/add.png +0 -0
  49. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/icons/delete.png +0 -0
  50. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/icons/table.png +0 -0
  51. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/login/alertBg.png +0 -0
  52. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/login/background.png +0 -0
  53. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/login/bottom.png +0 -0
  54. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/login/loginBoxBg.png +0 -0
  55. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/login/loginBoxBottom.png +0 -0
  56. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/login/loginBoxTop.png +0 -0
  57. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/login/loginSubmit.png +0 -0
  58. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/login/recoverSubmit.png +0 -0
  59. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/login/top.png +0 -0
  60. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/nav.png +0 -0
  61. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/rightNav.png +0 -0
  62. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/rightNavButton.png +0 -0
  63. data/lib/generators/kryptonite/update/templates/public/kryptonite/images/visitSiteNav.png +0 -0
  64. data/lib/generators/kryptonite/update/templates/public/kryptonite/javascripts/jquery.js +154 -0
  65. data/lib/generators/kryptonite/update/templates/public/kryptonite/javascripts/kryptonite.js +25 -0
  66. data/lib/generators/kryptonite/update/templates/public/kryptonite/javascripts/login.js +24 -0
  67. data/lib/generators/kryptonite/update/templates/public/kryptonite/javascripts/rails.js +132 -0
  68. data/lib/generators/kryptonite/update/templates/public/kryptonite/stylesheets/elements.css +307 -0
  69. data/lib/generators/kryptonite/update/templates/public/kryptonite/stylesheets/login.css +137 -0
  70. data/lib/generators/kryptonite/update/templates/public/kryptonite/stylesheets/screen.css +224 -0
  71. data/lib/generators/kryptonite/update/update_generator.rb +40 -0
  72. data/lib/kryptonite.rb +3 -0
  73. data/lib/kryptonite/engine.rb +22 -0
  74. data/lib/railties/tasks.rake +31 -0
  75. metadata +169 -0
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010-2011 Spoiled Milk ApS
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.
@@ -0,0 +1,4 @@
1
+ major: 0
2
+ minor: 0
3
+ patch: 1
4
+ build:
data/README.rdoc ADDED
@@ -0,0 +1,209 @@
1
+ =Kryptonite. A really simple CMS
2
+
3
+ Comming
4
+
5
+ ==Installation
6
+
7
+ — Create a new Rails project (or use an existing one) and enter the project directory from a terminal prompt.
8
+
9
+ — Add the Kryptonite gem to your Gemfile:
10
+
11
+ gem 'kryptonite'
12
+
13
+ - Then use bundler to install Kryptonite and its dependencies:
14
+
15
+ bundle install
16
+
17
+ — If you have just created a new project, then remember to add your database details to /config/database.yml at this point.
18
+
19
+ — These installation instructions also assume that you have set up your RAILS_ENV environment variable.
20
+
21
+ — To enable Kryptonite notification emails (used for new users and forgotten passwords) then add your SMTP server information to your initializers. For example create a new file called initializers/setup_mail.rb and add the following to it:
22
+
23
+ ActionMailer::Base.delivery_method = :smtp
24
+ ActionMailer::Base.raise_delivery_errors = false
25
+ ActionMailer::Base.smtp_settings = {
26
+ :enable_starttls_auto => false,
27
+ :address => "mail.yourdomain.com",
28
+ :port => 25,
29
+ :domain => "yourdomain.com",
30
+ :user_name => "donotreply@yourdomain.com",
31
+ :password => "whatever",
32
+ :authentication => :login
33
+ }
34
+
35
+ — Install Kryptonite configuration files into your project. This should not be run more than once without backing up or merging the generated files, as your customisations will be overwritten:
36
+
37
+ rails g kryptonite:install
38
+
39
+ — Add Kryptonite assets to your project /public folder. These should not be modified as they may be overwritten in future updates:.
40
+
41
+ rails g kryptonite:update
42
+
43
+ — Perform a database migration to create the Kryptonite users table:
44
+
45
+ rake db:create (if needed)
46
+ rake db:migrate
47
+
48
+ — Run the following Rake task to set up an initial user. The default login and password will be displayed once the task has completed. You should specify your email address. If you set up an SMTP server in your Rails environment then you’ll also receive an email notification about the new account.
49
+
50
+ rake kryptonite:users:create_admin email=you@yourdomain.com
51
+
52
+ — Run your app! (rebooting the web server if applicable)
53
+
54
+ — You can access Kryptonite at http://yourdomain.com/kryptonite or http://yourdomain.com/admin
55
+
56
+ <b>Kryptonite should now be running! You should change the default password immediately!</b>
57
+
58
+ ==Usage
59
+
60
+ The default Kryptonite install supports user authentication. Users may have a status of either ‘admin’ or ‘user’. The former is allowed to add, edit and delete other Kryptonite users. The latter is only allowed to edit their own profile.
61
+
62
+ Kryptonite is a framework allowing you to quickly build up an interface to edit and create new records from your database model. As well as the user support and user interface, there are many configurations and generators to help you along the way.
63
+
64
+ ==Configuration
65
+
66
+ <b>app/helpers/kryptonite/config_helper.rb</b>
67
+
68
+ This is the main Kryptonite configuration file that allows you to change things such as the website name, logo, notification email address, dashboard URL, etc. The options are documented within the file.
69
+
70
+ <b>views/kryptonite/layouts/_left_navigation.html.erb</b>
71
+
72
+ An ERB partial for the the left navigation tabs. Note that using the scaffolding generator will automatically add tabs into this file, but it can also be manually edited and rearranged.
73
+
74
+ <b>view/kryptonite/layouts/_right_navigation.html.erb</b>
75
+
76
+ An ERB partial for the the right navigation tabs. Note that the ‘users’ tab is added automatically for admin users.
77
+
78
+ <b>/public/kryptonite/javascripts/custom.js & /public/kryptonite/stylesheets/custom.css</b>
79
+
80
+ The Kryptonite assets are located in /public/kryptonite. These are the only two files you should change. They allow you to add custom JavaScript or CSS to your Kryptonite deployment. These files are not overwritten using the ‘rails g kryptonite:update’ command.
81
+
82
+ ==Customising
83
+
84
+ Now that you have the basic Kryptonite installed and configured, you’ll want to extend it so that it actually has some functionality for your project!
85
+
86
+ <b>Rules and conventions</b>
87
+
88
+ * Kryptonite extension controllers and helpers should be namespaced to 'Kryptonite::'
89
+ * Kryptonite extension controllers should derive from Kryptonite::KryptoniteController and not ApplicationController
90
+ * To set the page title, your controller action should set @kryptonite_page_title. If this is not set, then Kryptonite will use a default created from your project name.
91
+
92
+ <b>Right bar</b>
93
+
94
+ The right bar in Kryptonite should be used for view specific actions, e.g. "Add user" for users/index, or "Back to list", "Delete user" for users/show.
95
+
96
+ To specify the contents of the sidebar, you must add a 'content_for :sidebar' block in the relevant view file (index, show, etc.) e.g.:
97
+
98
+ <%= content_for :sidebar do %>
99
+ <li><%= link_to "#{kryptonite_show_icon('table')}Back to list".html_safe, kryptonite_users_path %></li>
100
+ <% end %>
101
+
102
+ The kryptonite_show_icon function will display any icon present in the /public/kryptonite/images/icons folder. By default this only contains add, delete and table after install. However, more can be added as required by downloading from http://www.famfamfam.com/lab/icons/silk/
103
+
104
+ <b>Helper functions</b>
105
+
106
+ There are several Kryptonite helper functions that are automatically available in any of your Kryptonite extension views.
107
+
108
+ <i>TODO: These will be documented later. For now, just browse the kryptonite_helper.rb file to see what’s available.</i>
109
+
110
+ <b>Kryptonite version</b>
111
+
112
+ Your Rails application may discover what version of Kryptonite it is currently running by calling the function:
113
+
114
+ kryptonite_get_version_info
115
+
116
+ This will return an array with the keys 'major', 'minor' and 'patch'.
117
+
118
+ <b>Rake tasks</b>
119
+
120
+ There are several Kryptonite Rake tasks available to manage users. To see what is available, list all Rake commands using:
121
+
122
+ rake -T
123
+
124
+ The Kryptonite Rake tasks are all namespaced with ‘kryptonite:’
125
+
126
+ ==Scaffolding
127
+
128
+ Kryptonite has a scaffolding generator to automatically create all the views and controllers for your project models. This is the fastest way to add Kryptonite support to your project.
129
+
130
+ The command to run the scaffolding generator is:
131
+
132
+ rails g kryptonite:scaffold ModelName [field:type, field:type]
133
+
134
+ Where:
135
+
136
+ * ModelName – The singular name of your model, e.g. customer
137
+ * field:type – The name of your database fields and their types, e.g. name:string. The field name must match the name in your migrations and the type must be one of the Rails migration types (string, text, integer, float, decimal, datetime, timestamp, time, date, binary, boolean). Note that you do not have to specify all of the fields in your model, but just the ones that you wish to be editable in Kryptonite.
138
+
139
+ e.g. a typical scaffolding command might look like:
140
+
141
+ rails g kryptonite:scaffold customer name:string age:integer date_of_birth:date is_male:boolean
142
+
143
+ There is one command-line option that can be added to the end of the generate command:
144
+
145
+ --create-model-and-migration = Also creates a model and migration. By default the scaffold generator will work from existing models, but this option will generate the model and database migration files for you. This means you can also use Kryptonite to set up a new project quickly as well.
146
+
147
+ Once the command has been executed, the generator will:
148
+
149
+ * Add a new tab for the model to: app/views/kryptonite/layouts/_left_navigation.html.erb
150
+ * Create a controller with the name: app/controllers/kryptonite/model_controller.erb
151
+ * Add views for index, new and show to: app/views/kryptonite/model/
152
+ * If you restart and run your application now, you’ll be able to log in to Kryptonite and directly edit and create new instances of your model data right away!
153
+
154
+ However, you’ll probably want to customise your views and side bars and extend your controller to suit your project. The scaffold generator just sets up the defaults for you.
155
+
156
+ <em>NOTE: Once you start customising the generated scaffolding files, you should be aware that if you run the generator again you should not overwrite the changed files without backing them up first. The generator will warn you each time it finds a file that you’ve customised. If you run the scaffold generator from a new version of Kryptonite, then you should manually merge your backup and the new file. You can of course however, leave your originals untouched.</em>
157
+
158
+ ===Changing form elements / other helpers
159
+
160
+ Kryptonite will insert form elements suitable for the field types you specified in the command line. However, you may wish to customise these, e.g. swap a text field for a password field, swap an integer field for a select dropdown, or swap a date field for a full calendar picker, etc.
161
+
162
+ You will find the form used for both new and show in a partial named _fields.html.erb
163
+
164
+ All of the standard Rails form helpers are available, but the Kryptonite versions are prefixed with kryptonite_. These versions are styled for the Kryptonite interface and have automatic support for validation error reporting.
165
+
166
+ kryptonite_text_field form, model, attribute, options = {}
167
+ kryptonite_password_field form, model, attribute, options = {}
168
+ kryptonite_text_area form, model, attribute, options = {}
169
+ kryptonite_text_area_big form, model, attribute, options = {}
170
+ kryptonite_check_box form, model, attribute, options = {}
171
+ kryptonite_check_box_group form, model, check_boxes = {}
172
+ kryptonite_radio_button form, model, attribute, tag_value, options = {}
173
+ kryptonite_radio_button_group form, model, radio_buttons = {}
174
+ kryptonite_select form, model, attribute, option_tags, options = {}
175
+ kryptonite_time_zone_select form, obj, attribute, option_tags, options = {}
176
+ kryptonite_date_select form, model, attribute, options = {}
177
+ kryptonite_time_select form, model, attribute, options = {}
178
+ kryptonite_datetime_select form, model, attribute, options = {}
179
+ kryptonite_file_field form, model, object_name, attribute, options = {}
180
+ kryptonite_hidden_field form, model, attribute, options = {}
181
+
182
+ For more information on each function, check the app/helpers/kryptonite/kryptonite_helper.rb file within the project. The method parameters are typically the same as the Rails form tag helpers. There are some extra Kryptonite options that can be passed through as part of the options hash:
183
+
184
+ :kryptonite_label – by default the humanized version of the database field name is used as the label, but this will override it with a string of your choice.
185
+ :kryptonite_button_label – available in kryptonite_radio_button and kryptonite_check_box. Used to give individual buttons their labels.
186
+ :kryptonite_truncate - may be passed into kryptonite_table_cell_link along with a maximum length to automatically truncate strings and suffix with '...'
187
+
188
+ ===Changing form layout
189
+
190
+ A basic two-column layout is automatically created by the scaffold generator. The position of form elements is controlled by parent DIVs. A left column element is housed in a “tfContainer” and a right column element in “tfContainer tfContainerSecond”. Note that the generator does not take form element height into account, so you may need to have two sequential matching tfContainer types to balance out some of the larger components, such as the calendar picker.
191
+
192
+ There is an optional container class that forces form elements to use the whole width of the page. This is “tfContainer tfContainerFullWidth” and if used together with kryptonite_text_area_big will create a textarea suitable for, say, editing full page content.
193
+
194
+ ===Adding styled help blocks
195
+
196
+ Sometimes it is necessary or useful to add guidelines or help text to your forms and tables. Kryptonite offers a CSS class for this called “help”, which can be used throughout your views as necessary.
197
+
198
+ ===Routes
199
+
200
+ Kryptonite adds the routes for the scaffolded models to the top of your application’s routes.rb file. It also adds default routes for basic Kryptonite functionality <b>after</b> your application’s routes. If you have a catch-all style route defined, then these defaults won’t be run. You can solve this be using Rails’ constraint feature and the supplied Kryptonite::RouteConstraint, which will stop your catch-all from matching if the request is for a Kryptonite resource.
201
+
202
+ e.g.
203
+
204
+ match ':controller(/:action(/:id(.:format)))', :constraints => Kryptonite::RouteConstraint.new
205
+
206
+ ==Acknowledgements
207
+
208
+ The icons used in Kryptonite were created by Mark James and are licensed under the Creative Commons Attribution 2.5 License (http://creativecommons.org/licenses/by/2.5/). The full series of icons are available here: http://www.famfamfam.com/lab/icons/silk/
209
+ This Project is inspired by the Casein CMS.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the kryptonite gem.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the kryptonite gem.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'Kryptonite'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ begin
26
+ require "jeweler"
27
+ Jeweler::Tasks.new do |gem|
28
+ gem.name = "kryptonite"
29
+ gem.summary = "A lightweight Ruby on Rails CMS."
30
+ gem.description = "Kryptonite is an open-source CMS for Ruby on Rails, originally developed by Spoiled Milk. Extended by Alexander Feiglstorfer."
31
+ gem.files = Dir["Gemfile", "MIT-LICENSE", "Rakefile", "README.rdoc", "PUBLIC_VERSION.yml", "{lib}/**/*", "{app}/**/*", "{config}/**/*"]
32
+ gem.email = "delooks@gmail.com"
33
+ gem.authors = ["Alexander Feiglstorfer", "M2Hero"]
34
+ gem.homepage = "http://github.com/onefriendaday/Kryptonite"
35
+ gem.add_dependency("will_paginate", ["3.0.0"])
36
+ gem.add_dependency("authlogic", ["3.0.3"])
37
+ end
38
+ rescue
39
+ puts "Jeweler or one of its dependencies is not installed."
40
+ end
@@ -0,0 +1,72 @@
1
+ require 'authlogic'
2
+
3
+ module Kryptonite
4
+ class KryptoniteController < ApplicationController
5
+
6
+ unloadable
7
+
8
+ require 'kryptonite/kryptonite_helper'
9
+ include Kryptonite::KryptoniteHelper
10
+
11
+ require 'kryptonite/config_helper'
12
+ include Kryptonite::ConfigHelper
13
+
14
+ layout 'kryptonite_main'
15
+
16
+ helper_method :current_user_session, :current_user
17
+ before_filter :authorise
18
+ before_filter :set_time_zone
19
+
20
+ ActionView::Base.field_error_proc = proc { |input, instance| "<span class='formError'>#{input}</span>".html_safe }
21
+
22
+ def index
23
+ redirect_to kryptonite_config_dashboard_url
24
+ end
25
+
26
+ def blank
27
+ @kryptonite_page_title = "Welcome"
28
+ end
29
+
30
+ private
31
+
32
+ def authorise
33
+ unless current_user
34
+ session[:return_to] = request.fullpath
35
+ redirect_to new_kryptonite_user_session_url
36
+ return false
37
+ end
38
+ end
39
+
40
+ def set_time_zone
41
+ Time.zone = current_user.time_zone if current_user
42
+ end
43
+
44
+ def current_user_session
45
+ return @current_user_session if defined?(@current_user_session)
46
+ @current_user_session = Kryptonite::UserSession.find
47
+ end
48
+
49
+ def current_user
50
+ return @session_user if defined?(@session_user)
51
+ @session_user = current_user_session && current_user_session.user
52
+ end
53
+
54
+ def needs_admin
55
+ unless @session_user.is_admin?
56
+ redirect_to :controller => :kryptonite, :action => :index
57
+ end
58
+ end
59
+
60
+ def needs_admin_or_current_user
61
+ unless @session_user.is_admin? || params[:id].to_i == @session_user.id
62
+ redirect_to :controller => :kryptonite, :action => :index
63
+ end
64
+ end
65
+
66
+ def redirect_back_or_default(default)
67
+ redirect_to(session[:return_to] || default)
68
+ session[:return_to] = nil
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,66 @@
1
+ module Kryptonite
2
+ class PasswordResetsController < Kryptonite::KryptoniteController
3
+
4
+ unloadable
5
+
6
+ skip_before_filter :authorise
7
+ before_filter :load_user_using_perishable_token, :only => [:edit, :update]
8
+
9
+ layout 'kryptonite_auth'
10
+
11
+ def create
12
+ users = Kryptonite::User.where(:email => params[:recover_email]).all
13
+
14
+ if users.length > 0
15
+ users.each do |user|
16
+ user.send_password_reset_instructions
17
+ end
18
+
19
+ if users.length > 1
20
+ flash[:notice] = "Multiple accounts were found. Emails have been sent to " + params[:recover_email] + " with instructions on how to reset your passwords"
21
+ else
22
+ flash[:notice] = "An email has been sent to " + params[:recover_email] + " with instructions on how to reset your password"
23
+ end
24
+ else
25
+ flash[:warning] = "There is no user with that email"
26
+ end
27
+
28
+ redirect_to new_kryptonite_user_session_url
29
+ end
30
+
31
+ def edit
32
+ render
33
+ end
34
+
35
+ def update
36
+
37
+ if params[:kryptonite_user][:password].empty? || params[:kryptonite_user][:password_confirmation].empty?
38
+ flash.now[:warning] = "A field has been left empty"
39
+ else
40
+
41
+ @reset_user.password = params[:kryptonite_user][:password]
42
+ @reset_user.password_confirmation = params[:kryptonite_user][:password_confirmation]
43
+
44
+ if @reset_user.save
45
+ flash[:notice] = "Password successfully updated"
46
+ redirect_to new_kryptonite_user_session_url
47
+ return
48
+ end
49
+ end
50
+
51
+ render :action => :edit
52
+ end
53
+
54
+ private
55
+
56
+ def load_user_using_perishable_token
57
+
58
+ @reset_user = Kryptonite::User.find_using_perishable_token params[:token]
59
+
60
+ unless @reset_user
61
+ flash[:warning] = "Your account could not be located. Try to copy and paste the URL directly from the email."
62
+ redirect_to new_kryptonite_user_session_url
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,40 @@
1
+ module Kryptonite
2
+ class UserSessionsController < Kryptonite::KryptoniteController
3
+
4
+ unloadable
5
+
6
+ skip_before_filter :authorise, :only => [:new, :create]
7
+ before_filter :requires_no_session_user, :except => [:destroy]
8
+
9
+ layout 'kryptonite_auth'
10
+
11
+ def new
12
+ @user_session = Kryptonite::UserSession.new
13
+ end
14
+
15
+ def create
16
+ @user_session = Kryptonite::UserSession.new params[:kryptonite_user_session]
17
+ if @user_session.save
18
+ flash[:notice] = "Login successful"
19
+ redirect_back_or_default :controller => :kryptonite, :action => :index
20
+ else
21
+ render :action => :new
22
+ end
23
+ end
24
+
25
+ def destroy
26
+ current_user_session.destroy
27
+ flash[:notice] = "Logout successful"
28
+ redirect_back_or_default new_kryptonite_user_session_url
29
+ end
30
+
31
+ private
32
+
33
+ def requires_no_session_user
34
+ if current_user
35
+ redirect_to :controller => :kryptonite, :action => :index
36
+ end
37
+ end
38
+
39
+ end
40
+ end