Guest User

Untitled

a guest
Feb 20th, 2018
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.65 KB | None | 0 0
  1. Index: test/unit/membership_test.rb
  2. ===================================================================
  3. --- test/unit/membership_test.rb (revision 2170)
  4. +++ test/unit/membership_test.rb (working copy)
  5. @@ -8,7 +8,7 @@
  6. end
  7.  
  8. def test_should_find_site_members
  9. - assert_models_equal [users(:arthur), users(:quentin)].collect(&:id).sort, sites(:first).members.collect(&:id).sort
  10. + assert_models_equal [users(:arthur), users(:quentin), users(:ben)].collect(&:id).sort, sites(:first).members.collect(&:id).sort
  11. end
  12.  
  13. def test_should_find_site_admins
  14. @@ -17,12 +17,12 @@
  15. end
  16.  
  17. def test_should_find_all_site_users
  18. - assert_models_equal [users(:arthur), users(:quentin)].collect(&:id).sort, User.find_all_by_site(sites(:first)).collect(&:id).sort
  19. - assert_models_equal [users(:arthur), users(:quentin)].collect(&:id).sort, sites(:first).users.collect(&:id).sort
  20. + assert_models_equal [users(:arthur), users(:quentin), users(:ben)].collect(&:id).sort, User.find_all_by_site(sites(:first)).collect(&:id).sort
  21. + assert_models_equal [users(:arthur), users(:quentin), users(:ben)].collect(&:id).sort, sites(:first).users.collect(&:id).sort
  22. end
  23.  
  24. def test_should_find_all_site_users_with_deleted
  25. - assert_models_equal [User.find_with_deleted(3), users(:arthur), users(:quentin)].collect(&:id).sort, User.find_all_by_site_with_deleted(sites(:first)).collect(&:id).sort
  26. - assert_models_equal [User.find_with_deleted(3), users(:arthur), users(:quentin)].collect(&:id).sort, sites(:first).users_with_deleted.collect(&:id).sort
  27. + assert_models_equal [User.find_with_deleted(3), users(:arthur), users(:quentin), users(:ben)].collect(&:id).sort, User.find_all_by_site_with_deleted(sites(:first)).collect(&:id).sort
  28. + assert_models_equal [User.find_with_deleted(3), users(:arthur), users(:quentin), users(:ben)].collect(&:id).sort, sites(:first).users_with_deleted.collect(&:id).sort
  29. end
  30. end
  31. Index: test/unit/user_notifier_test.rb
  32. ===================================================================
  33. --- test/unit/user_notifier_test.rb (revision 0)
  34. +++ test/unit/user_notifier_test.rb (revision 0)
  35. @@ -0,0 +1,45 @@
  36. +require File.dirname(__FILE__) + '/../test_helper'
  37. +require 'user_notifier'
  38. +
  39. +class UserNotifierTest < Test::Unit::TestCase
  40. + include ActionController::UrlWriter
  41. + fixtures :users
  42. +
  43. + FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
  44. + CHARSET = "utf-8"
  45. +
  46. + include ActionMailer::Quoting
  47. +
  48. + def setup
  49. + ActionMailer::Base.delivery_method = :test
  50. + ActionMailer::Base.perform_deliveries = true
  51. + ActionMailer::Base.deliveries = []
  52. +
  53. + @expected = TMail::Mail.new
  54. + @expected.set_content_type "text", "plain", { "charset" => CHARSET }
  55. + end
  56. +
  57. + def test_forgot_password
  58. + user = users(:quentin)
  59. + user.forgot_password
  60. + response = UserNotifier.deliver_forgot_password(user)
  61. + assert_equal user.email, response.to[0]
  62. + assert_match /#{url_for :controller => :account, :action => :reset_password, :id => user.password_reset_code}/, response.body
  63. + end
  64. +
  65. + def test_reset_password
  66. + user = users(:quentin)
  67. + response = UserNotifier.deliver_reset_password(user)
  68. + assert_equal user.email, response.to[0]
  69. + assert_match /Your password has been reset/, response.subject
  70. + end
  71. +
  72. + private
  73. + def read_fixture(action)
  74. + IO.readlines("#{FIXTURES_PATH}/user_notifier/#{action}")
  75. + end
  76. +
  77. + def encode(subject)
  78. + quoted_printable(subject, CHARSET)
  79. + end
  80. +end
  81. Index: test/functional/account_controller_test.rb
  82. ===================================================================
  83. --- test/functional/account_controller_test.rb (revision 2170)
  84. +++ test/functional/account_controller_test.rb (working copy)
  85. @@ -5,7 +5,7 @@
  86. class AccountController; def rescue_action(e) raise e end; end
  87.  
  88. class AccountControllerTest < Test::Unit::TestCase
  89. - fixtures :users, :sites, :memberships
  90. + fixtures :users, :sites, :memberships, :contents
  91.  
  92. def setup
  93. @controller = AccountController.new
  94. @@ -13,14 +13,35 @@
  95. @response = ActionController::TestResponse.new
  96.  
  97. # for testing action mailer
  98. - # @emails = ActionMailer::Base.deliveries
  99. - # @emails.clear
  100. + @emails = ActionMailer::Base.deliveries
  101. + @emails.clear
  102. end
  103.  
  104. def test_should_login_and_redirect
  105. post :login, :login => 'quentin', :password => 'quentin'
  106. assert session[:user]
  107. + # quentin has User.admin true
  108. assert_redirected_to :controller => 'admin/overview', :action => 'index'
  109. +
  110. + post :login, :login => 'arthur', :password => 'arthur'
  111. + assert session[:user]
  112. + # arthur is an admin for the site :first
  113. + assert_redirected_to :controller => 'admin/overview', :action => 'index'
  114. + get :logout
  115. + assert !session[:user]
  116. +
  117. + post :login, :login => 'ben', :password => 'arthur'
  118. + assert session[:user]
  119. + # ben is not an admin so should be redirected to the front page
  120. + assert_redirected_to :controller => 'mephisto', :action => 'dispatch'
  121. + get :logout
  122. + assert !session[:user]
  123. +
  124. + # make sure redirected to referrer
  125. + post :login, :login => 'arthur', :password => 'arthur', :referrer => contents(:welcome).full_permalink
  126. + assert_redirected_to contents(:welcome).full_permalink
  127. + get :logout
  128. + assert !session[:user]
  129. end
  130.  
  131. def test_should_fail_login_and_not_redirect
  132. @@ -81,17 +102,46 @@
  133. assert !@controller.send(:logged_in?)
  134. end
  135.  
  136. + def test_should_allow_password_change
  137. + post :login, :login => 'quentin', :password => 'quentin'
  138. + assert session[:user]
  139. + post :change_password, :old_password => 'quentin', :password => 'newpassword', :password_confirmation => 'newpassword'
  140. + assert_equal 'newpassword', assigns(:current_user).password # doesn't work because passwords are crypted
  141. + assert_equal "Password changed", flash[:notice]
  142. + post :logout
  143. + assert_nil session[:user]
  144. + post :login, :login => 'quentin', :password => 'newpassword'
  145. + assert session[:user]
  146. + end
  147. +
  148. + def test_non_matching_passwords_should_not_change
  149. + post :login, :login => 'quentin', :password => 'quentin'
  150. + assert session[:user]
  151. + post :change_password, { :old_password => 'test', :password => 'newpassword', :password_confirmation => 'test' }
  152. + assert_not_equal 'newpassword', assigns(:current_user).password
  153. + assert_equal "Wrong password", flash[:notice]
  154. + end
  155. +
  156. + def test_incorrect_old_password_does_not_change
  157. + post :login, :login => 'quentin', :password => 'quentin'
  158. + assert session[:user]
  159. + post :change_password, { :old_password => 'wrongpassword', :password => 'newpassword', :password_confirmation => 'newpassword' }
  160. + assert_not_equal 'newpassword', assigns(:current_user).password
  161. + assert_equal "Wrong password", flash[:notice]
  162. + end
  163. +
  164. protected
  165. - def auth_token(token)
  166. - CGI::Cookie.new('name' => 'auth_token', 'value' => token)
  167. - end
  168. -
  169. - def cookie_for(user)
  170. - auth_token users(user).remember_token
  171. - end
  172.  
  173. - def create_user(options = {})
  174. - post :signup, :user => { :login => 'quire', :email => 'quire@example.com',
  175. - :password => 'quire', :password_confirmation => 'quire' }.merge(options)
  176. - end
  177. + def auth_token(token)
  178. + CGI::Cookie.new('name' => 'auth_token', 'value' => token)
  179. + end
  180. +
  181. + def cookie_for(user)
  182. + auth_token users(user).remember_token
  183. + end
  184. +
  185. + def create_user(options = {})
  186. + post :signup, :user => { :login => 'quire', :email => 'quire@example.com',
  187. + :password => 'quire', :password_confirmation => 'quire' }.merge(options)
  188. + end
  189. end
  190. Index: test/functional/admin/users_controller_test.rb
  191. ===================================================================
  192. --- test/functional/admin/users_controller_test.rb (revision 2170)
  193. +++ test/functional/admin/users_controller_test.rb (working copy)
  194. @@ -40,7 +40,7 @@
  195. login_as :quentin
  196. assert_difference User, :count do
  197. assert_difference Membership, :count do
  198. - post :create, :user => { :login => 'bob', :email => 'foo', :password => 'testy', :password_confirmation => 'testy', :admin => true }
  199. + post :create, :user => { :login => 'bob', :email => 'foo@example.com', :password => 'testy', :password_confirmation => 'testy', :admin => true }
  200. assert_models_equal [sites(:first)], assigns(:user).sites
  201. assert_equal assigns(:user), User.authenticate_for(sites(:first), 'bob', 'testy')
  202. assert_redirected_to :action => 'index'
  203. @@ -51,34 +51,34 @@
  204.  
  205. def test_should_update_email_and_password
  206. login_as :quentin
  207. - post :update, :id => users(:quentin).id, :user => { :email => 'foo', :password => 'testy', :password_confirmation => 'testy' }
  208. + post :update, :id => users(:quentin).id, :user => { :email => 'foo@example.com', :password => 'testy', :password_confirmation => 'testy' }
  209. users(:quentin).reload
  210. - assert_equal 'foo', users(:quentin).email
  211. + assert_equal 'foo@example.com', users(:quentin).email
  212. assert_equal users(:quentin), User.authenticate_for(sites(:first), 'quentin', 'testy')
  213. assert_response :success
  214. end
  215.  
  216. def test_should_update_email_and_password_as_site_member
  217. login_as :arthur, :hostess
  218. - post :update, :id => users(:arthur).id, :user => { :email => 'foo', :password => 'testy', :password_confirmation => 'testy' }
  219. + post :update, :id => users(:arthur).id, :user => { :email => 'foo@example.com', :password => 'testy', :password_confirmation => 'testy' }
  220. users(:arthur).reload
  221. - assert_equal 'foo', users(:arthur).email
  222. + assert_equal 'foo@example.com', users(:arthur).email
  223. assert_equal users(:arthur), User.authenticate_for(sites(:hostess), 'arthur', 'testy')
  224. assert_response :success
  225. end
  226.  
  227. def test_should_leave_password_alone
  228. login_as :quentin
  229. - post :update, :id => users(:quentin).id, :user => { :email => 'foo', :password => '', :password_confirmation => '' }
  230. + post :update, :id => users(:quentin).id, :user => { :email => 'foo@example.com', :password => '', :password_confirmation => '' }
  231. users(:quentin).reload
  232. - assert_equal 'foo', users(:quentin).email
  233. + assert_equal 'foo@example.com', users(:quentin).email
  234. assert_equal users(:quentin), User.authenticate_for(sites(:first), 'quentin', 'quentin')
  235. assert_response :success
  236. end
  237.  
  238. def test_should_show_error_while_updating
  239. login_as :quentin
  240. - post :update, :id => users(:quentin).id, :user => { :email => 'foo', :password => 'tea', :password_confirmation => '' }
  241. + post :update, :id => users(:quentin).id, :user => { :email => 'foo@example.com', :password => 'tea', :password_confirmation => '' }
  242. users(:quentin).reload
  243. assert_equal 'quentin@example.com', users(:quentin).email
  244. assert_equal users(:quentin), User.authenticate_for(sites(:first), 'quentin', 'quentin')
  245. @@ -87,7 +87,7 @@
  246.  
  247. def test_should_show_error_while_creating
  248. login_as :quentin
  249. - post :create, :user => { :email => 'foo', :password => 'tea', :password_confirmation => '' }
  250. + post :create, :user => { :email => 'foo@example.com', :password => 'tea', :password_confirmation => '' }
  251. assert_response :success
  252. end
  253.  
  254. @@ -117,7 +117,7 @@
  255. def test_should_show_deleted_users
  256. login_as :quentin
  257. get :index
  258. - assert_equal 3, assigns(:users).size
  259. + assert_equal 4, assigns(:users).size
  260. user_tag = { :tag => 'li', :attributes => { :id => 'user-1', :class => 'clear' } }
  261. normal_tag = { :tag => 'li', :attributes => { :id => 'user-2', :class => 'clear' } }
  262. deleted_tag = { :tag => 'li', :attributes => { :id => 'user-3', :class => 'clear deleted' } }
  263. Index: test/fixtures/users.yml
  264. ===================================================================
  265. --- test/fixtures/users.yml (revision 2170)
  266. +++ test/fixtures/users.yml (working copy)
  267. @@ -10,7 +10,7 @@
  268. filter: textile_filter
  269. remember_token: quentintoken
  270. remember_token_expires_at: <%= 5.days.from_now.to_s :db %>
  271. - # activated_at: <%= 5.days.ago.to_s :db %> # only if you're activating new signups
  272. + activated_at: <%= 5.days.ago.to_s :db %> # only if you're activating new signups
  273. admin: true
  274. arthur:
  275. id: 2
  276. @@ -21,6 +21,7 @@
  277. activation_code: arthurscode # only if you're activating new signups
  278. created_at: <%= 1.days.ago.to_s :db %>
  279. updated_at: <%= 1.days.ago.to_s :db %>
  280. + activated_at: <%= 5.days.ago.to_s :db %> # only if you're activating new signups
  281. filter: markdown_filter
  282. aaron:
  283. id: 3
  284. @@ -32,4 +33,14 @@
  285. created_at: <%= 1.days.ago.to_s :db %>
  286. updated_at: <%= 1.days.ago.to_s :db %>
  287. deleted_at: <%= 5.hours.ago.to_s :db %>
  288. - filter: markdown_filter
  289. \ No newline at end of file
  290. + filter: markdown_filter
  291. +ben:
  292. + id: 4
  293. + login: ben
  294. + email: ben@example.com
  295. + salt: 55bc51360864c82dcd7ff4bcfec56a8d8e79e751
  296. + crypted_password: 37ba966058c6f39162e5b537adb516af91cd1fe6 # arthur
  297. + activation_code: benscode # only if you're activating new signups
  298. + created_at: <%= 1.days.ago.to_s :db %>
  299. + updated_at: <%= 1.days.ago.to_s :db %>
  300. + filter: markdown_filter
  301. Index: test/fixtures/memberships.yml
  302. ===================================================================
  303. --- test/fixtures/memberships.yml (revision 2170)
  304. +++ test/fixtures/memberships.yml (working copy)
  305. @@ -22,4 +22,8 @@
  306. id: 5
  307. user_id: 1
  308. site_id: 2
  309. - admin: true
  310. \ No newline at end of file
  311. + admin: true
  312. +ben_first:
  313. + id: 6
  314. + user_id: 4
  315. + site_id: 1
  316. Index: app/models/user_notifier.rb
  317. ===================================================================
  318. --- app/models/user_notifier.rb (revision 0)
  319. +++ app/models/user_notifier.rb (revision 0)
  320. @@ -0,0 +1,25 @@
  321. +class UserNotifier < ActionMailer::Base
  322. + include ActionController::UrlWriter
  323. + @@mail_from = nil
  324. + mattr_accessor :host, :mail_from
  325. +
  326. + def forgot_password(user)
  327. + setup_email(user)
  328. + @subject += 'Request to change your password'
  329. + @body[:url] = url_for :controller => :account, :action => :reset_password, :id => user.password_reset_code
  330. + end
  331. +
  332. + def reset_password(user)
  333. + setup_email(user)
  334. + @subject += 'Your password has been reset'
  335. + end
  336. +
  337. + protected
  338. + def setup_email(user)
  339. + @recipients = "#{user.email}"
  340. + @from = "#{@@mail_from}"
  341. + @subject = "#{default_url_options[:host]}: "
  342. + @sent_on = Time.now
  343. + @body[:user] = user
  344. + end
  345. +end
  346. Index: app/models/user_observer.rb
  347. ===================================================================
  348. --- app/models/user_observer.rb (revision 0)
  349. +++ app/models/user_observer.rb (revision 0)
  350. @@ -0,0 +1,6 @@
  351. +class UserObserver < ActiveRecord::Observer
  352. + def after_save(user)
  353. + UserNotifier.deliver_forgot_password(user) if user.recently_forgot_password?
  354. + UserNotifier.deliver_reset_password(user) if user.recently_reset_password?
  355. + end
  356. +end
  357. Index: app/models/user_auth.rb
  358. ===================================================================
  359. --- app/models/user_auth.rb (revision 2170)
  360. +++ app/models/user_auth.rb (working copy)
  361. @@ -9,18 +9,15 @@
  362. attr_accessor :password
  363.  
  364. validates_presence_of :login, :email
  365. + validates_format_of :email, :with => Mephisto::EmailRegex
  366. validates_presence_of :password, :if => :password_required?
  367. validates_presence_of :password_confirmation, :if => :password_required?
  368. validates_length_of :password, :within => 5..40, :if => :password_required?
  369. validates_confirmation_of :password, :if => :password_required?
  370. validates_length_of :login, :within => 3..40
  371. - validates_length_of :email, :within => 3..100
  372. validates_uniqueness_of :login, :email, :case_sensitve => false
  373. before_save :encrypt_password
  374.  
  375. - # Uncomment this to use activation
  376. - # before_create :make_activation_code
  377. -
  378. # Authenticates a user by their login name and unencrypted password. Returns the user or nil.
  379. def self.authenticate_for(site, login, password)
  380. u = find(:first, @@membership_options.merge(
  381. @@ -45,15 +42,18 @@
  382. find_with_deleted(:all, @@membership_options.merge(options.reverse_merge(:conditions => ['memberships.site_id = ? or users.admin = ?', site.id, true]))).uniq
  383. end
  384.  
  385. + def self.find_by_site_and_password_reset_code(site, password_reset_code)
  386. + with_deleted_scope do
  387. + find_with_deleted(:first, @@membership_options.merge(
  388. + :conditions => ['users.password_reset_code = ? and memberships.site_id = ?', password_reset_code, site.id]))
  389. + end
  390. + end
  391. +
  392. # Encrypts some data with the salt.
  393. def self.encrypt(password, salt)
  394. Digest::SHA1.hexdigest("--#{salt}--#{password}--")
  395. end
  396.  
  397. - def make_activation_code
  398. - self.activation_code = Digest::SHA1.hexdigest( Time.now.to_s.split('//').sort_by {rand}.join )
  399. - end
  400. -
  401. # Encrypts the password with the user salt
  402. def encrypt(password)
  403. self.class.encrypt(password, salt)
  404. @@ -80,6 +80,26 @@
  405. save(false)
  406. end
  407.  
  408. + def forgot_password
  409. + @forgotten_password = true
  410. + self.make_password_reset_code
  411. + end
  412. +
  413. + def reset_password
  414. + # First update the password_reset_code before setting the
  415. + # reset_password flag to avoid duplicate email notifications.
  416. + update_attributes(:password_reset_code => nil)
  417. + @reset_password = true
  418. + end
  419. +
  420. + def recently_reset_password?
  421. + @reset_password
  422. + end
  423. +
  424. + def recently_forgot_password?
  425. + @forgotten_password
  426. + end
  427. +
  428. protected
  429. def encrypt_password
  430. return if password.blank?
  431. @@ -90,4 +110,8 @@
  432. def password_required?
  433. crypted_password.nil? || !password.blank?
  434. end
  435. +
  436. + def make_password_reset_code
  437. + self.password_reset_code = Digest::SHA1.hexdigest( Time.now.to_s.split(//).sort_by {rand}.join )
  438. + end
  439. end
  440. Index: app/models/comment.rb
  441. ===================================================================
  442. --- app/models/comment.rb (revision 2170)
  443. +++ app/models/comment.rb (working copy)
  444. @@ -1,3 +1,4 @@
  445. +require 'mephisto_constants'
  446. require 'uri'
  447.  
  448. class Comment < Content
  449. @@ -2,3 +3,3 @@
  450. validates_presence_of :author, :author_ip, :article_id, :body
  451. - validates_format_of :author_email, :with => /(\A(\s*)\Z)|(\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z)/i
  452. + validates_format_of :author_email, :with => Mephisto::EmailRegex
  453. before_validation :clean_up_author_email
  454. Index: app/controllers/account_controller.rb
  455. ===================================================================
  456. --- app/controllers/account_controller.rb (revision 2170)
  457. +++ app/controllers/account_controller.rb (working copy)
  458. @@ -2,21 +2,25 @@
  459. include AuthenticatedSystem
  460. before_filter :login_from_cookie
  461. layout 'simple'
  462. + observer :user_observer
  463.  
  464. def index
  465. render :action => 'login'
  466. end
  467.  
  468. def login
  469. + @referrer = params[:referrer] || request.env["HTTP_REFERER"] || ""
  470. return unless request.post?
  471. + @login = params[:login]
  472. self.current_user = User.authenticate_for(site, params[:login], params[:password])
  473. if logged_in?
  474. if params[:remember_me] == "1"
  475. self.current_user.remember_me
  476. cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
  477. end
  478. - redirect_back_or_default(:controller => '/admin/overview', :action => 'index')
  479. - flash[:notice] = "Logged in successfully"
  480. + store_location :overwrite => false, :uri => @referrer.blank? ? nil : @referrer
  481. + flash[:notice] = "You are logged in"
  482. + return redirect_back_or_default(default_url(self.current_user))
  483. else
  484. flash[:error] = "Could not log you in. Are you sure your Login name and Password are correct?"
  485. end
  486. @@ -29,4 +33,65 @@
  487. flash[:notice] = "You have been logged out."
  488. redirect_back_or_default(dispatch_path)
  489. end
  490. +
  491. + def forgot_password
  492. + return unless request.post?
  493. + if @user = User.find_by_email(params[:email])
  494. + @user.forgot_password
  495. + @user.save
  496. + flash[:notice] = "A password reset link has been sent to your email address"
  497. + redirect_back_or_default(:controller => '/account', :action => 'index')
  498. + else
  499. + flash[:notice] = "Could not find a user with that email address"
  500. + end
  501. + end
  502. +
  503. + def reset_password
  504. + @user = User.find_by_site_and_password_reset_code(params[:id])
  505. + raise if @user.nil?
  506. + return if @user unless params[:password]
  507. + if (params[:password] == params[:password_confirmation])
  508. + self.current_user = @user #for the next two lines to work
  509. + current_user.password_confirmation = params[:password_confirmation]
  510. + current_user.password = params[:password]
  511. + @user.reset_password
  512. + flash[:notice] = current_user.save ? "Password reset" : "Password not reset"
  513. + else
  514. + flash[:notice] = "Password mismatch"
  515. + end
  516. + redirect_back_or_default(default_url(self.current_user))
  517. + rescue
  518. + logger.error "Invalid Reset Code entered"
  519. + flash[:notice] = "Sorry, that is an invalid password reset code. Please check the link and try again. (Perhaps your email client inserted a carriage return?)"
  520. + redirect_back_or_default(:controller => '/account', :action => 'index')
  521. + end
  522. +
  523. + def change_password
  524. + return unless request.post?
  525. + if User.authenticate_for(site, current_user.login, params[:old_password])
  526. + if (params[:password] == params[:password_confirmation])
  527. + current_user.password_confirmation = params[:password_confirmation]
  528. + current_user.password = params[:password]
  529. + flash[:notice] = current_user.save ?
  530. + "Password changed" :
  531. + "Password not changed"
  532. + else
  533. + flash[:notice] = "Password mismatch"
  534. + @old_password = params[:old_password]
  535. + end
  536. + else
  537. + flash[:notice] = "Wrong password"
  538. + end
  539. + end
  540. +
  541. + protected
  542. +
  543. + def default_url(user)
  544. + if admin?
  545. + url_for :controller => '/admin/overview', :action => 'index'
  546. + else
  547. + dispatch_url :path => []
  548. + end
  549. + end
  550. +
  551. end
  552. Index: app/controllers/application.rb
  553. ===================================================================
  554. --- app/controllers/application.rb (revision 2170)
  555. +++ app/controllers/application.rb (working copy)
  556. @@ -7,6 +7,10 @@
  557. helper_method :site
  558. attr_reader :site
  559.  
  560. + def admin?
  561. + logged_in? && current_user.admin? || current_user.site_admin?
  562. + end
  563. +
  564. protected
  565. # so not the best place for this...
  566. def asset_image_args_for(asset, thumbnail = :tiny, options = {})
  567. Index: app/controllers/admin/base_controller.rb
  568. ===================================================================
  569. --- app/controllers/admin/base_controller.rb (revision 2170)
  570. +++ app/controllers/admin/base_controller.rb (working copy)
  571. @@ -3,13 +3,11 @@
  572. before_filter :login_from_cookie
  573. before_filter :login_required, :except => :feed
  574.  
  575. - def admin?
  576. - logged_in? && current_user.admin? || current_user.site_admin?
  577. - end
  578. -
  579. helper_method :admin?
  580.  
  581. protected
  582. + alias authorized? admin?
  583. +
  584. def find_and_sort_templates
  585. @layouts, @templates = site.templates.partition { |t| t.dirname.to_s =~ /layouts$/ }
  586. end
  587. Index: app/views/account/forgot_password.rhtml
  588. ===================================================================
  589. --- app/views/account/forgot_password.rhtml (revision 0)
  590. +++ app/views/account/forgot_password.rhtml (revision 0)
  591. @@ -0,0 +1,9 @@
  592. +<%= start_form_tag({}, {:id=>'forgot_password'}) %>
  593. +<div class="little-box">
  594. + <dl>
  595. + <dt><%= label_tag "email", "Email Address" %></dt>
  596. + <dd><%= text_field_tag 'email' %></dd>
  597. + </dl>
  598. + <p><%= submit_tag 'Forgot password' %></p>
  599. +</div>
  600. +<%= end_form_tag %>
  601. Index: app/views/account/reset_password.rhtml
  602. ===================================================================
  603. --- app/views/account/reset_password.rhtml (revision 0)
  604. +++ app/views/account/reset_password.rhtml (revision 0)
  605. @@ -0,0 +1,11 @@
  606. +<%= start_form_tag({}, {:id=>'reset_password'}) %>
  607. +<div class="little-box">
  608. + <dl>
  609. + <dt><%= label_tag "password", "Password" %></dt>
  610. + <dd><%= password_field_tag 'password' %></dd>
  611. + <dt><%= label_tag "password_confirmation", "Confirm Password" %></dt>
  612. + <dd><%= password_field_tag 'password_confirmation' %></dd>
  613. + </dl>
  614. + <p><%= submit_tag 'Reset password' %></p>
  615. +</div>
  616. +<%= end_form_tag %>
  617. Index: app/views/account/change_password.rhtml
  618. ===================================================================
  619. --- app/views/account/change_password.rhtml (revision 0)
  620. +++ app/views/account/change_password.rhtml (revision 0)
  621. @@ -0,0 +1,13 @@
  622. +<%= start_form_tag({}, { :id => 'change_password' }) %>
  623. +<div class="little-box">
  624. + <dl>
  625. + <dt><%= label_tag "old_password", "Old Password" %></dt>
  626. + <dd><%= password_field_tag 'old_password', @old_password %></dd>
  627. + <dt><%= label_tag "password", "Password" %></dt>
  628. + <dd><%= password_field_tag 'password' %></dd>
  629. + <dt><%= label_tag "password_confirmation", "Confirm Password" %></dt>
  630. + <dd><%= password_field_tag 'password_confirmation' %></dd>
  631. + </dl>
  632. + <p><%= submit_tag 'Change password' %></p>
  633. +</div>
  634. +<%= end_form_tag %>
  635. Index: app/views/account/login.rhtml
  636. ===================================================================
  637. --- app/views/account/login.rhtml (revision 2170)
  638. +++ app/views/account/login.rhtml (working copy)
  639. @@ -1,8 +1,9 @@
  640. -<%= start_form_tag({}, { :id => 'login_form' }) %>
  641. <div class="little-box">
  642. +<%= start_form_tag({:controller=>:account, :action=>:login}, { :id => 'login_form' }) %>
  643. +<%= hidden_field_tag "referrer", @referrer %>
  644. <dl>
  645. <dt><%= label_tag 'login', 'Login' %></dt>
  646. - <dd><%= text_field_tag 'login', {}, :class => 'big' %></dd>
  647. + <dd><%= text_field_tag 'login', @login, :class => 'big' %></dd>
  648. <dt><%= label_tag 'password', 'Password' %></dt>
  649. <dd><%= password_field_tag 'password', {}, :class => 'big' %></dd>
  650. <dt></dt>
  651. @@ -12,5 +13,5 @@
  652. </dd>
  653. </dl>
  654. <p class="btns"><%= submit_tag 'Sign in' %></p>
  655. +<%= end_form_tag %>
  656. </div>
  657. -<%= end_form_tag %>
  658. Index: app/views/user_notifier/signup_notification.rhtml
  659. ===================================================================
  660. --- app/views/user_notifier/signup_notification.rhtml (revision 0)
  661. +++ app/views/user_notifier/signup_notification.rhtml (revision 0)
  662. @@ -0,0 +1,8 @@
  663. +Your account has been created.
  664. +
  665. + Username: <%= @user.login %>
  666. + Password: <%= @user.password %>
  667. +
  668. +Visit this url to activate your account:
  669. +
  670. + <%= @url %>
  671. \ No newline at end of file
  672. Index: app/views/user_notifier/activation.rhtml
  673. ===================================================================
  674. --- app/views/user_notifier/activation.rhtml (revision 0)
  675. +++ app/views/user_notifier/activation.rhtml (revision 0)
  676. @@ -0,0 +1,3 @@
  677. +<%= @user.login %>, your account has been activated. You may now start adding your comments:
  678. +
  679. + <%= @url %>
  680. Index: app/views/user_notifier/forgot_password.rhtml
  681. ===================================================================
  682. --- app/views/user_notifier/forgot_password.rhtml (revision 0)
  683. +++ app/views/user_notifier/forgot_password.rhtml (revision 0)
  684. @@ -0,0 +1,3 @@
  685. +<%= @user.login %>, follow the link to reset your password
  686. +
  687. + <%= @url %>
  688. Index: app/views/user_notifier/reset_password.rhtml
  689. ===================================================================
  690. --- app/views/user_notifier/reset_password.rhtml (revision 0)
  691. +++ app/views/user_notifier/reset_password.rhtml (revision 0)
  692. @@ -0,0 +1 @@
  693. +<%= @user.login %>, your password has been reset
  694. Index: app/views/user_notifier/signup_notification.rhtml.bak
  695. ===================================================================
  696. --- app/views/user_notifier/signup_notification.rhtml.bak (revision 0)
  697. +++ app/views/user_notifier/signup_notification.rhtml.bak (revision 0)
  698. @@ -0,0 +1,8 @@
  699. +Your account has been created.
  700. +
  701. + Username: <%= @user.login %>
  702. + Password: <%= @user.password %>
  703. +
  704. +Visit this url to activate your account:
  705. +
  706. + <%= @url %>
  707. \ No newline at end of file
  708. Index: config/environment.rb
  709. ===================================================================
  710. --- config/environment.rb (revision 2170)
  711. +++ config/environment.rb (working copy)
  712. @@ -4,6 +4,10 @@
  713. # you don't control web/app server and can't set it the proper way
  714. # ENV['RAILS_ENV'] ||= 'production'
  715.  
  716. +#require 'rubygems'
  717. +#require 'ruby-debug'
  718. +#Debugger.start
  719. +
  720. # Bootstrap the Rails environment, frameworks, and default configuration
  721. require File.join(File.dirname(__FILE__), 'boot')
  722.  
  723. @@ -43,4 +47,7 @@
  724. # Mephisto::SweeperMethods.cache_sweeper_tracing = true
  725.  
  726. # Enable if you want to host multiple sites on this app
  727. -# Site.multi_sites_enabled = true
  728. \ No newline at end of file
  729. +# Site.multi_sites_enabled = true
  730. +
  731. +UserNotifier.default_url_options[:host] = 'localhost:3000'
  732. +UserNotifier.mail_from = 'webmaster@localhost'
  733. Index: db/schema.rb
  734. ===================================================================
  735. --- db/schema.rb (revision 2170)
  736. +++ db/schema.rb (working copy)
  737. @@ -2,7 +2,7 @@
  738. # migrations feature of ActiveRecord to incrementally modify your database, and
  739. # then regenerate this schema definition.
  740.  
  741. -ActiveRecord::Schema.define(:version => 58) do
  742. +ActiveRecord::Schema.define(:version => 59) do
  743.  
  744. create_table "assets", :force => true do |t|
  745. t.column "content_type", :string
  746. @@ -169,6 +169,7 @@
  747. t.column "remember_token_expires_at", :datetime
  748. t.column "filter", :string
  749. t.column "admin", :boolean, :default => false
  750. + t.column "password_reset_code", :string, :limit => 40
  751. end
  752.  
  753. end
  754. Index: db/migrate/059_add_password_reset_code.rb
  755. ===================================================================
  756. --- db/migrate/059_add_password_reset_code.rb (revision 0)
  757. +++ db/migrate/059_add_password_reset_code.rb (revision 0)
  758. @@ -0,0 +1,9 @@
  759. +class AddPasswordResetCode < ActiveRecord::Migration
  760. + def self.up
  761. + add_column "users", "password_reset_code", :string, :limit => 40
  762. + end
  763. +
  764. + def self.down
  765. + remove_column "users", "password_reset_code"
  766. + end
  767. +end
  768. Index: lib/mephisto_constants.rb
  769. ===================================================================
  770. --- lib/mephisto_constants.rb (revision 0)
  771. +++ lib/mephisto_constants.rb (revision 0)
  772. @@ -0,0 +1,3 @@
  773. +module Mephisto
  774. + EmailRegex = /(\A(\s*)\Z)|(\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z)/i
  775. +end
  776. Index: lib/mephisto/liquid/comment_form.rb
  777. ===================================================================
  778. --- lib/mephisto/liquid/comment_form.rb (revision 2170)
  779. +++ lib/mephisto/liquid/comment_form.rb (working copy)
  780. @@ -9,12 +9,12 @@
  781. context.stack do
  782. if context['message'].blank?
  783. errors = context['errors'].blank? ? '' : %Q{<ul id="comment-errors"><li>#{context['errors'].join('</li><li>')}</li></ul>}
  784. -
  785. +
  786. submitted = context['submitted'] || {}
  787. submitted.each{ |k, v| submitted[k] = CGI::escapeHTML(v) }
  788.  
  789. context['form'] = {
  790. - 'body' => %(<textarea id="comment_body" name="comment[body]">#{submitted['body']}</textarea>),
  791. + 'body' => %(<textarea id="comment_body" class="commentbox" name="comment[body]">#{submitted['body']}</textarea>),
  792. 'name' => %(<input type="text" id="comment_author" name="comment[author]" value="#{submitted['author']}" />),
  793. 'email' => %(<input type="text" id="comment_author_email" name="comment[author_email]" value="#{submitted['author_email']}" />),
  794. 'url' => %(<input type="text" id="comment_author_url" name="comment[author_url]" value="#{submitted['author_url']}" />),
  795. @@ -30,4 +30,4 @@
  796. end
  797. end
  798. end
  799. -end
  800. \ No newline at end of file
  801. +end
  802. Index: lib/mephisto/attachments/template_methods.rb
  803. ===================================================================
  804. --- lib/mephisto/attachments/template_methods.rb (revision 2170)
  805. +++ lib/mephisto/attachments/template_methods.rb (working copy)
  806. @@ -29,4 +29,4 @@
  807. end
  808. end
  809. end
  810. -end
  811. \ No newline at end of file
  812. +end
  813. Index: lib/authenticated_system.rb
  814. ===================================================================
  815. --- lib/authenticated_system.rb (revision 2170)
  816. +++ lib/authenticated_system.rb (working copy)
  817. @@ -36,10 +36,16 @@
  818.  
  819. # store current uri in the session.
  820. # we can return to this location by calling return_location
  821. - def store_location
  822. - session[:return_to] = request.request_uri
  823. + # Options:
  824. + # * :overwrite - (default = true) Overwrite existing stored location
  825. + # * :uri - Return to the specified URI (defaults to request.request_uri)
  826. + def store_location(options={})
  827. + options[:overwrite] = true if options[:overwrite].nil?
  828. + return if !options[:overwrite] and session[:return_to]
  829. + session[:return_to] = options[:uri] or request.request_uri
  830. + else
  831. end
  832. -
  833. +
  834. # move to the last store_location call or to the passed default one
  835. def redirect_back_or_default(default)
  836. session[:return_to] ? redirect_to_url(session[:return_to]) : redirect_to(default)
  837. @@ -95,4 +101,4 @@
  838. end
  839. return [user, pass]
  840. end
  841. -end
  842. \ No newline at end of file
  843. +end
  844. Index: lib/mephisto_init.rb
  845. ===================================================================
  846. --- lib/mephisto_init.rb (revision 2170)
  847. +++ lib/mephisto_init.rb (working copy)
  848. @@ -4,6 +4,7 @@
  849. require 'coderay'
  850. require 'ruby_pants'
  851. require 'xmlrpc_patch'
  852. +require 'mephisto_constants'
  853.  
  854. Inflector.inflections do |inflect|
  855. #inflect.plural /^(ox)$/i, '\1en'
  856. @@ -116,4 +117,4 @@
  857. end
  858. end
  859. end
  860. -end
  861. \ No newline at end of file
  862. +end
Add Comment
Please, Sign In to add comment