diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/application.rb | 4 | ||||
-rw-r--r-- | app/controllers/user_controller.rb | 8 | ||||
-rw-r--r-- | app/helpers/link_to_helper.rb | 4 | ||||
-rw-r--r-- | app/models/public_body.rb | 8 | ||||
-rw-r--r-- | app/models/user.rb | 14 |
5 files changed, 25 insertions, 13 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb index f518a89e9..af3f8de1b 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -6,7 +6,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: application.rb,v 1.29 2008-02-27 12:04:10 francis Exp $ +# $Id: application.rb,v 1.30 2008-02-27 12:18:28 francis Exp $ class ApplicationController < ActionController::Base @@ -44,7 +44,7 @@ class ApplicationController < ActionController::Base def authenticated_as_user?(user, reason_params) reason_params[:user_name] = user.name - reason_params[:user_url] = show_user_url(:simple_name => MySociety::Format.simplify_url_part(user.name)) + reason_params[:user_url] = show_user_url(:url_name => user.url_name) if session[:user_id] if session[:user_id] == user.id # They are logged in as the right user diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 8dc056167..2c10db6f8 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -4,16 +4,16 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: user_controller.rb,v 1.27 2008-02-27 12:04:10 francis Exp $ +# $Id: user_controller.rb,v 1.28 2008-02-27 12:18:28 francis Exp $ class UserController < ApplicationController # XXX See controllers/application.rb simplify_url_part for reverse of expression in SQL below def show - if MySociety::Format.simplify_url_part(params[:simple_name]) != params[:simple_name] - redirect_to :simple_name => MySociety::Format.simplify_url_part(params[:simple_name]) + if MySociety::Format.simplify_url_part(params[:url_name]) != params[:url_name] + redirect_to :url_name => MySociety::Format.simplify_url_part(params[:url_name]) end - @display_users = User.find(:all, :conditions => [ "regexp_replace(replace(lower(name), ' ', '-'), '[^a-z0-9_-]', '', 'g') = ?", params[:simple_name] ], :order => "created_at desc") + @display_users = User.find(:all, :conditions => [ "url_name = ?", params[:url_name] ], :order => "created_at desc") end # Login form diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index dbf569f20..8d4a1baca 100644 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -5,7 +5,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: link_to_helper.rb,v 1.17 2008-02-27 12:09:03 francis Exp $ +# $Id: link_to_helper.rb,v 1.18 2008-02-27 12:18:28 francis Exp $ module LinkToHelper @@ -47,7 +47,7 @@ module LinkToHelper # Users def user_url(user) - return show_user_url(:simple_name => MySociety::Format.simplify_url_part(user.name), :only_path => true) + return show_user_url(:url_name => user.url_name, :only_path => true) end def user_link(user) link_to h(user.name), user_url(user) diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 9c4956b68..546de2c40 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -21,7 +21,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: public_body.rb,v 1.22 2008-02-27 12:04:10 francis Exp $ +# $Id: public_body.rb,v 1.23 2008-02-27 12:18:28 francis Exp $ class PublicBody < ActiveRecord::Base validates_presence_of :name @@ -50,14 +50,14 @@ class PublicBody < ActiveRecord::Base # When name or short name is changed, also change the url name def short_name=(short_name) write_attribute(:short_name, short_name) - update_url_name + self.update_url_name end def name=(name) write_attribute(:name, name) - update_url_name + self.update_url_name end def update_url_name - url_name = MySociety::Format.simplify_url_part(short_or_long_name) + url_name = MySociety::Format.simplify_url_part(self.short_or_long_name) write_attribute(:url_name, url_name) end # Return the short name if present, or else long name diff --git a/app/models/user.rb b/app/models/user.rb index ab680dc1e..79f26464d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -19,7 +19,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: user.rb,v 1.29 2008-02-26 15:13:51 francis Exp $ +# $Id: user.rb,v 1.30 2008-02-27 12:18:28 francis Exp $ require 'digest/sha1' @@ -28,6 +28,8 @@ class User < ActiveRecord::Base validates_uniqueness_of :email, :case_sensitive => false, :message => "^There is already an account with that email address. You can sign in to it on the left." validates_presence_of :name, :message => "^Please enter your name" + validates_presence_of :url_name + validates_presence_of :hashed_password, :message => "^Please enter a password" has_many :info_requests @@ -73,6 +75,16 @@ class User < ActiveRecord::Base return self.find(:first, :conditions => [ 'email ilike ?', email ] ) # using ilike for case insensitive end + # When name is changed, also change the url name + def name=(name) + write_attribute(:name, name) + self.update_url_name + end + def update_url_name + url_name = MySociety::Format.simplify_url_part(self.name) + write_attribute(:url_name, url_name) + end + # Virtual password attribute, which stores the hashed password, rather than plain text. def password @password |