diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 7873b0bd..75b2c31c 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -44,9 +44,10 @@ class AdminController < ApplicationController end def edit_web - if @params['system_password'] + system_password = @params['system_password'] + if system_password # form submitted - if wiki.authenticate(@params['system_password']) + if wiki.authenticate(system_password) wiki.edit_web( @web.address, @params['address'], @params['name'], @params['markup'].intern, @@ -61,11 +62,7 @@ class AdminController < ApplicationController ) redirect_show('HomePage', @params['address']) else - if @params['system_password'].empty? - flash[:error] = 'Please enter the system password' - else - flash[:error] = 'You entered a wrong system password. Please enter the right one' - end + flash[:error] = password_error(system_password) # and re-render the same template again end else diff --git a/app/controllers/application.rb b/app/controllers/application.rb index dd0a2914..c2648b66 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -71,6 +71,14 @@ class ApplicationController < ActionController::Base not @web_name.nil? end + def password_error(password) + if password.nil? or password.empty? + 'Please enter the password.' + else + 'You entered a wrong password. Please enter the right one.' + end + end + def redirect_show(page_name = @page_name, web = @web_name) redirect_to :web => web, :controller => 'wiki', :action => 'show', :id => CGI.escape(page_name || 'HomePage') diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 240dab43..6a949199 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -93,7 +93,8 @@ class WikiController < ApplicationController wiki.remove_orphaned_pages(@web_name) redirect_to :action => 'list' else - redirect_show 'HomePage' + flash[:error] = password_error(@params['system_password']) + return_to_last_remembered end end