From 8b96de49e2924f3f92459238778f0fbf093cbcb2 Mon Sep 17 00:00:00 2001 From: Gavin Joyce Date: Sat, 13 Dec 2008 11:15:38 +0000 Subject: [PATCH] deleted and re-generated the restful_authentication framework. I've removed the user signup process as it isn't currently needed. --- app/controllers/application.rb | 2 +- app/controllers/sessions_controller.rb | 3 +- app/controllers/users_controller.rb | 73 ------- app/helpers/users_helper.rb | 73 ------- app/models/user.rb | 7 +- app/models/user_mailer.rb | 24 --- app/models/user_observer.rb | 11 - app/views/layouts/application.html.erb | 7 - app/views/user_mailer/activation.erb | 3 - app/views/user_mailer/signup_notification.erb | 8 - app/views/users/_user_bar.html.erb | 8 - app/views/users/new.html.erb | 19 -- config/environment.rb | 5 +- config/initializers/site_keys.rb | 3 +- config/routes.rb | 8 +- ...sers.rb => 20081213105754_create_users.rb} | 6 +- public/stylesheets/main.css | 4 - spec/controllers/sessions_controller_spec.rb | 1 + spec/controllers/users_controller_spec.rb | 196 ------------------ spec/fixtures/users.yml | 15 +- spec/helpers/users_helper_spec.rb | 119 ----------- spec/models/user_spec.rb | 65 +----- stories/steps/user_steps.rb | 19 +- stories/users/accounts.story | 77 +------ 24 files changed, 20 insertions(+), 736 deletions(-) delete mode 100644 app/controllers/users_controller.rb delete mode 100644 app/models/user_mailer.rb delete mode 100644 app/models/user_observer.rb delete mode 100644 app/views/user_mailer/activation.erb delete mode 100644 app/views/user_mailer/signup_notification.erb delete mode 100644 app/views/users/_user_bar.html.erb delete mode 100644 app/views/users/new.html.erb rename db/migrate/{20081210104519_create_users.rb => 20081213105754_create_users.rb} (75%) delete mode 100644 spec/controllers/users_controller_spec.rb diff --git a/app/controllers/application.rb b/app/controllers/application.rb index f1db903..9755554 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -2,8 +2,8 @@ # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base - include AuthenticatedSystem helper :all # include all helpers, all the time + include AuthenticatedSystem # See ActionController::RequestForgeryProtection for details # Uncomment the :secret if you're not using the cookie session store diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 44065c4..7b55954 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,5 +1,6 @@ # This controller handles the login/logout function of the site. class SessionsController < ApplicationController + # Be sure to include AuthenticationSystem in Application Controller instead # render new.rhtml def new @@ -17,7 +18,7 @@ def create new_cookie_flag = (params[:remember_me] == "1") handle_remember_cookie! new_cookie_flag redirect_back_or_default('/') - flash[:success] = "Welcome back #{h(user.login)}" + flash[:notice] = "Logged in successfully" else note_failed_signin @login = params[:login] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb deleted file mode 100644 index 34a3494..0000000 --- a/app/controllers/users_controller.rb +++ /dev/null @@ -1,73 +0,0 @@ -class UsersController < ApplicationController - - # Protect these actions behind an admin login - # before_filter :admin_required, :only => [:suspend, :unsuspend, :destroy, :purge] - before_filter :find_user, :only => [:suspend, :unsuspend, :destroy, :purge] - - - # render new.rhtml - def new - @user = User.new - end - - def create - logout_keeping_session! - @user = User.new(params[:user]) - @user.register! if @user && @user.valid? - success = @user && @user.valid? - if success && @user.errors.empty? - redirect_back_or_default('/') - flash[:notice] = "Thanks for signing up! We're sending you an email with your activation code." - else - flash[:error] = "We couldn't set up that account, sorry. Please try again, or contact an admin (link is above)." - render :action => 'new' - end - end - - def activate - logout_keeping_session! - user = User.find_by_activation_code(params[:activation_code]) unless params[:activation_code].blank? - case - when (!params[:activation_code].blank?) && user && !user.active? - user.activate! - self.current_user = user - flash[:notice] = "That's it! Welcome aboard." - redirect_to '/' #TODO: GJ: redirect to user page when we have added it - when params[:activation_code].blank? - flash[:error] = "The activation code was missing. Please follow the URL from your email." - redirect_back_or_default('/') - else - flash[:error] = "We couldn't find a user with that activation code -- check your email? Or maybe you've already activated -- try signing in." - redirect_back_or_default('/') - end - end - - def suspend - @user.suspend! - redirect_to users_path - end - - def unsuspend - @user.unsuspend! - redirect_to users_path - end - - def destroy - @user.delete! - redirect_to users_path - end - - def purge - @user.destroy - redirect_to users_path - end - - # There's no page here to update or destroy a user. If you add those, be - # smart -- make sure you check that the visitor is authorized to do so, that they - # supply their old password along with a new one to update it, etc. - -protected - def find_user - @user = User.find(params[:id]) - end -end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 281e0a4..9000ace 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -17,77 +17,4 @@ def if_authorized?(action, resource, &block) end end - # - # Link to user's page ('users/1') - # - # By default, their login is used as link text and link title (tooltip) - # - # Takes options - # * :content_text => 'Content text in place of user.login', escaped with - # the standard h() function. - # * :content_method => :user_instance_method_to_call_for_content_text - # * :title_method => :user_instance_method_to_call_for_title_attribute - # * as well as link_to()'s standard options - # - # Examples: - # link_to_user @user - # # => barmy - # - # # if you've added a .name attribute: - # content_tag :span, :class => :vcard do - # (link_to_user user, :class => 'fn n', :title_method => :login, :content_method => :name) + - # ': ' + (content_tag :span, user.email, :class => 'email') - # end - # # => Cyril Fotheringay-Phipps: - # - # link_to_user @user, :content_text => 'Your user page' - # # => Your user page - # - def link_to_user(user, options={}) - raise "Invalid user" unless user - options.reverse_merge! :content_method => :login, :title_method => :login, :class => :nickname - content_text = options.delete(:content_text) - content_text ||= user.send(options.delete(:content_method)) - options[:title] ||= user.send(options.delete(:title_method)) - link_to h(content_text), user_path(user), options - end - - # - # Link to login page using remote ip address as link content - # - # The :title (and thus, tooltip) is set to the IP address - # - # Examples: - # link_to_login_with_IP - # # => 169.69.69.69 - # - # link_to_login_with_IP :content_text => 'not signed in' - # # => not signed in - # - def link_to_login_with_IP content_text=nil, options={} - ip_addr = request.remote_ip - content_text ||= ip_addr - options.reverse_merge! :title => ip_addr - if tag = options.delete(:tag) - content_tag tag, h(content_text), options - else - link_to h(content_text), login_path, options - end - end - - # - # Link to the current user's page (using link_to_user) or to the login page - # (using link_to_login_with_IP). - # - def link_to_current_user(options={}) - if current_user - link_to_user current_user, options - else - content_text = options.delete(:content_text) || 'not signed in' - # kill ignored options from link_to_user - [:content_method, :title_method].each{|opt| options.delete(opt)} - link_to_login_with_IP content_text, options - end - end - end diff --git a/app/models/user.rb b/app/models/user.rb index 69a0366..42f98d7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,6 @@ class User < ActiveRecord::Base include Authentication include Authentication::ByPassword include Authentication::ByCookieToken - include Authorization::AasmRoles validates_presence_of :login validates_length_of :login, :within => 3..40 @@ -36,7 +35,7 @@ class User < ActiveRecord::Base # def self.authenticate(login, password) return nil if login.blank? || password.blank? - u = find_in_state :first, :active, :conditions => {:login => login} # need to get the salt + u = find_by_login(login) # need to get the salt u && u.authenticated?(password) ? u : nil end @@ -50,10 +49,6 @@ def email=(value) protected - def make_activation_code - self.deleted_at = nil - self.activation_code = self.class.make_token - end end diff --git a/app/models/user_mailer.rb b/app/models/user_mailer.rb deleted file mode 100644 index b105a43..0000000 --- a/app/models/user_mailer.rb +++ /dev/null @@ -1,24 +0,0 @@ -class UserMailer < ActionMailer::Base - def signup_notification(user) - setup_email(user) - @subject += 'Please activate your new account' - - @body[:url] = "http://YOURSITE/activate/#{user.activation_code}" - - end - - def activation(user) - setup_email(user) - @subject += 'Your account has been activated!' - @body[:url] = "http://YOURSITE/" - end - - protected - def setup_email(user) - @recipients = "#{user.email}" - @from = "ADMINEMAIL" - @subject = "[YOURSITE] " - @sent_on = Time.now - @body[:user] = user - end -end diff --git a/app/models/user_observer.rb b/app/models/user_observer.rb deleted file mode 100644 index 03616f8..0000000 --- a/app/models/user_observer.rb +++ /dev/null @@ -1,11 +0,0 @@ -class UserObserver < ActiveRecord::Observer - def after_create(user) - UserMailer.deliver_signup_notification(user) - end - - def after_save(user) - - UserMailer.deliver_activation(user) if user.recently_activated? - - end -end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a57e07a..889896d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,13 +10,6 @@