Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.80 KB | None | 0 0
  1. Index: test/unit/membership_test.rb
  2. ===================================================================
  3. --- test/unit/membership_test.rb (revision 2128)
  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/functional/account_controller_test.rb
  32. ===================================================================
  33. --- test/functional/account_controller_test.rb (revision 2128)
  34. test/functional/account_controller_test.rb (working copy)
  35. @@ -5,7 5,7 @@
  36. class AccountController; def rescue_action(e) raise e end; end
  37.  
  38. class AccountControllerTest < Test::Unit::TestCase
  39. - fixtures :users, :sites, :memberships
  40. fixtures :users, :sites, :memberships, :contents
  41.  
  42. def setup
  43. @controller = AccountController.new
  44. @@ -13,14 13,37 @@
  45. @response = ActionController::TestResponse.new
  46.  
  47. # for testing action mailer
  48. - # @emails = ActionMailer::Base.deliveries
  49. - # @emails.clear
  50. @emails = ActionMailer::Base.deliveries
  51. @emails.clear
  52. end
  53.  
  54. def test_should_login_and_redirect
  55. post :login, :login => 'quentin', :password => 'quentin'
  56. assert session[:user]
  57. # quentin has User.admin true
  58. assert_redirected_to :controller => 'admin/overview', :action => 'index'
  59.  
  60. post :login, :login => 'arthur', :password => 'arthur'
  61. assert session[:user]
  62. # arthur is an admin for the site :first
  63. assert_redirected_to :controller => 'admin/overview', :action => 'index'
  64. get :logout
  65. assert !session[:user]
  66.  
  67. # (need to activate ben before logging in)
  68. get :activate, :activation_code => users(:ben).activation_code
  69. post :login, :login => 'ben', :password => 'arthur'
  70. assert session[:user]
  71. # ben is not an admin so should be redirected to the front page
  72. assert_redirected_to :controller => 'mephisto', :action => 'list'
  73. get :logout
  74. assert !session[:user]
  75.  
  76. # make sure redirected to referrer
  77. post :login, :login => 'arthur', :password => 'arthur', :referrer => contents(:welcome).full_permalink
  78. assert_redirected_to contents(:welcome).full_permalink
  79. get :logout
  80. assert !session[:user]
  81. end
  82.  
  83. def test_should_fail_login_and_not_redirect
  84. @@ -81,17 104,90 @@
  85. assert !@controller.send(:logged_in?)
  86. end
  87.  
  88. - protected
  89. - def auth_token(token)
  90. - CGI::Cookie.new('name' => 'auth_token', 'value' => token)
  91. def test_should_activate_user
  92. if User.require_activation
  93. assert_nil User.authenticate_for(sites(:first), 'ben', 'arthur')
  94. get :activate, :activation_code => users(:ben).activation_code
  95. assert_equal users(:ben), User.authenticate_for(sites(:first), 'ben', 'arthur')
  96. end
  97. -
  98. - def cookie_for(user)
  99. - auth_token users(user).remember_token
  100. end
  101.  
  102. def test_should_not_activate_nil
  103. get :activate, :activation_code => nil
  104. assert_activate_error
  105. end
  106.  
  107. def test_should_not_activate_bad
  108. get :activate, :activation_code => 'foobar'
  109. assert flash.has_key?(:error), "Flash should contain error message."
  110. assert_activate_error
  111. end
  112.  
  113. def assert_activate_error
  114. assert_response :success
  115. assert_template "account/activate"
  116. end
  117.  
  118. def test_should_activate_user_and_send_activation_email
  119. if User::require_activation
  120. get :activate, :activation_code => users(:ben).activation_code
  121. assert_equal 1, @emails.length
  122. assert(@emails.first.subject =~ /Your account has been activated/)
  123. assert(@emails.first.body =~ /#{assigns(:user).login}, your account has been activated/)
  124. end
  125. end
  126.  
  127. - def create_user(options = {})
  128. - post :signup, :user => { :login => 'quire', :email => 'quire@example.com',
  129. - :password => 'quire', :password_confirmation => 'quire' }.merge(options)
  130. def test_should_send_activation_email_after_signup
  131. if User::require_activation
  132. create_user
  133. assert_equal 1, @emails.length
  134. assert(@emails.first.subject =~ /Please activate your new account/)
  135. assert(@emails.first.body =~ /Username: quire/)
  136. assert(@emails.first.body =~ /Password: quire/)
  137. assert(@emails.first.body =~ /account\/activate\/#{assigns(:user).activation_code}/)
  138. end
  139. end
  140.  
  141. def test_should_allow_password_change
  142. post :login, :login => 'quentin', :password => 'quentin'
  143. assert session[:user]
  144. post :change_password, :old_password => 'quentin', :password => 'newpassword', :password_confirmation => 'newpassword'
  145. assert_equal 'newpassword', assigns(:current_user).password # doesn't work because passwords are crypted
  146. assert_equal "Password changed", flash[:notice]
  147. post :logout
  148. assert_nil session[:user]
  149. post :login, :login => 'quentin', :password => 'newpassword'
  150. assert session[:user]
  151. end
  152.  
  153. def test_non_matching_passwords_should_not_change
  154. post :login, :login => 'quentin', :password => 'quentin'
  155. assert session[:user]
  156. post :change_password, { :old_password => 'test', :password => 'newpassword', :password_confirmation => 'test' }
  157. assert_not_equal 'newpassword', assigns(:current_user).password
  158. assert_equal "Wrong password", flash[:notice]
  159. end
  160.  
  161. def test_incorrect_old_password_does_not_change
  162. post :login, :login => 'quentin', :password => 'quentin'
  163. assert session[:user]
  164. post :change_password, { :old_password => 'wrongpassword', :password => 'newpassword', :password_confirmation => 'newpassword' }
  165. assert_not_equal 'newpassword', assigns(:current_user).password
  166. assert_equal "Wrong password", flash[:notice]
  167. end
  168.  
  169. protected
  170.  
  171. def auth_token(token)
  172. CGI::Cookie.new('name' => 'auth_token', 'value' => token)
  173. end
  174.  
  175. def cookie_for(user)
  176. auth_token users(user).remember_token
  177. end
  178.  
  179. def create_user(options = {})
  180. post :signup, :user => { :login => 'quire', :email => 'quire@example.com',
  181. :password => 'quire', :password_confirmation => 'quire' }.merge(options)
  182. end
  183. end
  184. Index: test/functional/admin/users_controller_test.rb
  185. ===================================================================
  186. --- test/functional/admin/users_controller_test.rb (revision 2128)
  187. test/functional/admin/users_controller_test.rb (working copy)
  188. @@ -40,7 40,7 @@
  189. login_as :quentin
  190. assert_difference User, :count do
  191. post :create, :user => { :login => 'bob', :email => 'foo', :password => 'testy', :password_confirmation => 'testy', :admin => true }
  192. - assert_equal assigns(:user), User.authenticate_for(sites(:first), 'bob', 'testy')
  193. assert_equal assigns(:user), User.authenticate_for(sites(:first), 'bob', 'testy', :require_activation => false)
  194. assert_redirected_to :action => 'index'
  195. assert flash[:notice]
  196. end
  197. @@ -114,7 114,7 @@
  198. def test_should_show_deleted_users
  199. login_as :quentin
  200. get :index
  201. - assert_equal 3, assigns(:users).size
  202. assert_equal 4, assigns(:users).size
  203. user_tag = { :tag => 'li', :attributes => { :id => 'user-1', :class => 'clear' } }
  204. normal_tag = { :tag => 'li', :attributes => { :id => 'user-2', :class => 'clear' } }
  205. deleted_tag = { :tag => 'li', :attributes => { :id => 'user-3', :class => 'clear deleted' } }
  206. Index: test/fixtures/users.yml
  207. ===================================================================
  208. --- test/fixtures/users.yml (revision 2128)
  209. test/fixtures/users.yml (working copy)
  210. @@ -10,7 10,7 @@
  211. filter: textile_filter
  212. remember_token: quentintoken
  213. remember_token_expires_at: <%= 5.days.from_now.to_s :db %>
  214. - # activated_at: <%= 5.days.ago.to_s :db %> # only if you're activating new signups
  215. activated_at: <%= 5.days.ago.to_s :db %> # only if you're activating new signups
  216. admin: true
  217. arthur:
  218. id: 2
  219. @@ -21,6 21,7 @@
  220. activation_code: arthurscode # only if you're activating new signups
  221. created_at: <%= 1.days.ago.to_s :db %>
  222. updated_at: <%= 1.days.ago.to_s :db %>
  223. activated_at: <%= 5.days.ago.to_s :db %> # only if you're activating new signups
  224. filter: markdown_filter
  225. aaron:
  226. id: 3
  227. @@ -32,4 33,14 @@
  228. created_at: <%= 1.days.ago.to_s :db %>
  229. updated_at: <%= 1.days.ago.to_s :db %>
  230. deleted_at: <%= 5.hours.ago.to_s :db %>
  231. - filter: markdown_filter
  232. \ No newline at end of file
  233. filter: markdown_filter
  234. ben:
  235. id: 4
  236. login: ben
  237. email: ben@example.com
  238. salt: 55bc51360864c82dcd7ff4bcfec56a8d8e79e751
  239. crypted_password: 37ba966058c6f39162e5b537adb516af91cd1fe6 # arthur
  240. activation_code: benscode # only if you're activating new signups
  241. created_at: <%= 1.days.ago.to_s :db %>
  242. updated_at: <%= 1.days.ago.to_s :db %>
  243. filter: markdown_filter
  244. Index: test/fixtures/memberships.yml
  245. ===================================================================
  246. --- test/fixtures/memberships.yml (revision 2128)
  247. test/fixtures/memberships.yml (working copy)
  248. @@ -22,4 22,8 @@
  249. id: 5
  250. user_id: 1
  251. site_id: 2
  252. - admin: true
  253. \ No newline at end of file
  254. admin: true
  255. ben_first:
  256. id: 6
  257. user_id: 4
  258. site_id: 1
  259. Index: app/models/user.rb
  260. ===================================================================
  261. --- app/models/user.rb (revision 2128)
  262. app/models/user.rb (working copy)
  263. @@ -3,7 3,7 @@
  264. has_many :articles
  265. acts_as_paranoid
  266.  
  267. - has_many :memberships
  268. has_many :memberships, :dependent=>:destroy
  269. has_many :sites, :through => :memberships, :order => 'title, host'
  270.  
  271. def self.find_admins(*args)
  272. Index: app/models/user_auth.rb
  273. ===================================================================
  274. --- app/models/user_auth.rb (revision 2128)
  275. app/models/user_auth.rb (working copy)
  276. @@ -18,13 18,23 @@
  277. validates_uniqueness_of :login, :email, :case_sensitve => false
  278. before_save :encrypt_password
  279.  
  280. - # Uncomment this to use activation
  281. - # before_create :make_activation_code
  282. @@require_activation = false # Set to true to require activation
  283. if @@require_activation
  284. before_create :make_activation_code
  285. end
  286. mattr_reader :require_activation
  287.  
  288. # Authenticates a user by their login name and unencrypted password. Returns the user or nil.
  289. - def self.authenticate_for(site, login, password)
  290. def self.authenticate_for(site, login, password, options={})
  291. options[:require_activation] = @@require_activation if options[:require_activation].nil?
  292. if options[:require_activation]
  293. activation_cond = ' and activated_at is not NULL'
  294. else
  295. activation_cond = ''
  296. end
  297. u = find(:first, @@membership_options.merge(
  298. - :conditions => ['users.login = ? and (memberships.site_id = ? or users.admin = ?)', login, site.id, true]))
  299. :conditions => ['users.login = ? and (memberships.site_id = ? or users.admin = ?)' activation_cond,
  300. login, site.id, true]))
  301. u && u.authenticated?(password) ? u : nil
  302. end
  303.  
  304. @@ -45,15 55,25 @@
  305. find_with_deleted(:all, @@membership_options.merge(options.reverse_merge(:conditions => ['memberships.site_id = ? or users.admin = ?', site.id, true]))).uniq
  306. end
  307.  
  308. def self.find_by_site_and_activation_code(site, activation_code)
  309. with_deleted_scope do
  310. find_with_deleted(:first, @@membership_options.merge(
  311. :conditions => ['users.activation_code = ? and memberships.site_id = ?', activation_code, site.id]))
  312. end
  313. end
  314.  
  315. def self.find_by_site_and_password_reset_code(site, password_reset_code)
  316. with_deleted_scope do
  317. find_with_deleted(:first, @@membership_options.merge(
  318. :conditions => ['users.password_reset_code = ? and memberships.site_id = ?', password_reset_code, site.id]))
  319. end
  320. end
  321.  
  322. # Encrypts some data with the salt.
  323. def self.encrypt(password, salt)
  324. Digest::SHA1.hexdigest("--#{salt}--#{password}--")
  325. end
  326.  
  327. - def make_activation_code
  328. - self.activation_code = Digest::SHA1.hexdigest( Time.now.to_s.split('//').sort_by {rand}.join )
  329. - end
  330. -
  331. # Encrypts the password with the user salt
  332. def encrypt(password)
  333. self.class.encrypt(password, salt)
  334. @@ -80,14 100,54 @@
  335. save(false)
  336. end
  337.  
  338. # Activates the user in the database.
  339. def activate
  340. @activated = true
  341. update_attributes(:activated_at => Time.now.utc)
  342. end
  343.  
  344. # Returns true if the user has just been activated.
  345. def recently_activated?
  346. @activated
  347. end
  348.  
  349. def forgot_password
  350. @forgotten_password = true
  351. self.make_password_reset_code
  352. end
  353.  
  354. def reset_password
  355. # First update the password_reset_code before setting the
  356. # reset_password flag to avoid duplicate email notifications.
  357. update_attributes(:password_reset_code => nil)
  358. @reset_password = true
  359. end
  360.  
  361. def recently_reset_password?
  362. @reset_password
  363. end
  364.  
  365. def recently_forgot_password?
  366. @forgotten_password
  367. end
  368.  
  369. protected
  370. - def encrypt_password
  371. - return if password.blank?
  372. - self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--") if new_record?
  373. - self.crypted_password = encrypt(password)
  374. - end
  375.  
  376. def encrypt_password
  377. return if password.blank?
  378. self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--") if new_record?
  379. self.crypted_password = encrypt(password)
  380. end
  381.  
  382. - def password_required?
  383. - crypted_password.nil? || !password.blank?
  384. - end
  385. def password_required?
  386. crypted_password.nil? || !password.blank?
  387. end
  388.  
  389. def make_activation_code
  390. self.activation_code = Digest::SHA1.hexdigest( Time.now.to_s.split(//).sort_by {rand}.join )
  391. end
  392.  
  393. def make_password_reset_code
  394. self.password_reset_code = Digest::SHA1.hexdigest( Time.now.to_s.split(//).sort_by {rand}.join )
  395. end
  396. end
  397. Index: app/models/site.rb
  398. ===================================================================
  399. --- app/models/site.rb (revision 2128)
  400. app/models/site.rb (working copy)
  401. @@ -16,7 16,7 @@
  402. has_many :assets, :as => :attachable, :order => 'created_at desc'
  403. has_many :assets, :order => 'created_at desc', :conditions => 'parent_id is null'
  404.  
  405. - has_many :memberships
  406. has_many :memberships, :dependent=>:destroy
  407. has_many :members, :through => :memberships, :source => :user
  408. has_many :admins, :through => :memberships, :source => :user, :conditions => ['memberships.admin = ? or users.admin = ?', true, true]
  409.  
  410. Index: app/controllers/account_controller.rb
  411. ===================================================================
  412. --- app/controllers/account_controller.rb (revision 2128)
  413. app/controllers/account_controller.rb (working copy)
  414. @@ -2,23 2,32 @@
  415. include AuthenticatedSystem
  416. before_filter :login_from_cookie
  417. layout 'simple'
  418. observer :user_observer
  419.  
  420. def index
  421. render :action => 'login'
  422. end
  423.  
  424. def login
  425. @referrer = params[:referrer] || request.env["HTTP_REFERER"] || ""
  426. return unless request.post?
  427. @login = params[:login]
  428. self.current_user = User.authenticate_for(site, params[:login], params[:password])
  429. if logged_in?
  430. if params[:remember_me] == "1"
  431. self.current_user.remember_me
  432. cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
  433. end
  434. - redirect_back_or_default(:controller => '/admin/overview', :action => 'index')
  435. - flash[:notice] = "Logged in successfully"
  436. store_location :overwrite => false, :uri => @referrer.blank? ? nil : @referrer
  437. flash[:notice] = "You are logged in"
  438. redirect_back_or_default(default_url(self.current_user))
  439. else
  440. - flash[:error] = "Could not log you in. Are you sure your Login name and Password are correct?"
  441. if User.require_activation and user = User.authenticate_for(site, params[:login], params[:password], :require_activation=>false)
  442. flash[:error] = "You must activate your account before you can log in. An activation code was e-mailed to you when you signed up."
  443. flash[:user_to_activate] = user
  444. else
  445. flash[:error] = "Could not log you in. Are you sure your Login name and Password are correct?"
  446. end
  447. end
  448. end
  449.  
  450. @@ -29,4 38,109 @@
  451. flash[:notice] = "You have been logged out."
  452. redirect_back_or_default(:controller => 'mephisto', :action => 'list', :sections => [])
  453. end
  454.  
  455. def signup
  456. @user = User.new(params[:user])
  457. return unless request.post?
  458. @user.save!
  459. Membership.create(:user_id=>@user.id, :site_id=>site.id)
  460. self.current_user = @user
  461. if User.require_activation
  462. flash[:notice] = "Thanks for signing up! An activation code has been sent to #{@user.email}"
  463. else
  464. flash[:notice] = "Thanks for signing up!"
  465. end
  466. redirect_back_or_default(:controller => '/account', :action => 'index')
  467. rescue ActiveRecord::RecordInvalid
  468. render :action => 'signup'
  469. end
  470.  
  471. def activate
  472. if params[:activation_code]
  473. @user = User.find_by_site_and_activation_code(site, params[:activation_code])
  474. if @user
  475. if @user.activated_at
  476. flash[:notice] = "Your account has already been activated."
  477. else
  478. @user.activate
  479. flash[:notice] = "Your account has been activated."
  480. end
  481. self.current_user = @user
  482. redirect_back_or_default(default_url(self.current_user))
  483. else
  484. flash[:error] = "Unable to activate the account. Did you enter the correct information?"
  485. end
  486. end
  487. end
  488.  
  489. def forgot_password
  490. return unless request.post?
  491. if @user = User.find_by_email(params[:email])
  492. @user.forgot_password
  493. @user.save
  494. flash[:notice] = "A password reset link has been sent to your email address"
  495. redirect_back_or_default(:controller => '/account', :action => 'index')
  496. else
  497. flash[:notice] = "Could not find a user with that email address"
  498. end
  499. end
  500.  
  501. def reset_password
  502. @user = User.find_by_site_and_password_reset_code(params[:id])
  503. raise if @user.nil?
  504. return if @user unless params[:password]
  505. if (params[:password] == params[:password_confirmation])
  506. self.current_user = @user #for the next two lines to work
  507. current_user.password_confirmation = params[:password_confirmation]
  508. current_user.password = params[:password]
  509. @user.reset_password
  510. flash[:notice] = current_user.save ? "Password reset" : "Password not reset"
  511. else
  512. flash[:notice] = "Password mismatch"
  513. end
  514. redirect_back_or_default(default_url(self.current_user))
  515. rescue
  516. logger.error "Invalid Reset Code entered"
  517. 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?)"
  518. redirect_back_or_default(:controller => '/account', :action => 'index')
  519. end
  520.  
  521. def change_password
  522. return unless request.post?
  523. if User.authenticate_for(site, current_user.login, params[:old_password])
  524. if (params[:password] == params[:password_confirmation])
  525. current_user.password_confirmation = params[:password_confirmation]
  526. current_user.password = params[:password]
  527. flash[:notice] = current_user.save ?
  528. "Password changed" :
  529. "Password not changed"
  530. else
  531. flash[:notice] = "Password mismatch"
  532. @old_password = params[:old_password]
  533. end
  534. else
  535. flash[:notice] = "Wrong password"
  536. end
  537. end
  538.  
  539. def send_activation_code
  540. if request.post? and user = flash[:user_to_activate]
  541. UserNotifier.deliver_signup_notification(user)
  542. flash[:user_to_activate] = nil
  543. flash[:error] = nil
  544. flash[:notice] = "An activation code has been sent to #{user.email}"
  545. end
  546. redirect_to :controller => '/account', :action => 'login'
  547. end
  548.  
  549. protected
  550.  
  551. def default_url(user)
  552. if admin?
  553. url_for :controller => '/admin/overview', :action => 'index'
  554. else
  555. section_url :sections=>[]
  556. end
  557. end
  558.  
  559. end
  560. Index: app/controllers/application.rb
  561. ===================================================================
  562. --- app/controllers/application.rb (revision 2128)
  563. app/controllers/application.rb (working copy)
  564. @@ -7,6 7,10 @@
  565. helper_method :site
  566. attr_reader :site
  567.  
  568. def admin?
  569. logged_in? && current_user.admin? || current_user.site_admin?
  570. end
  571.  
  572. protected
  573. # so not the best place for this...
  574. def asset_image_args_for(asset, thumbnail = :tiny, options = {})
  575. Index: app/controllers/admin/base_controller.rb
  576. ===================================================================
  577. --- app/controllers/admin/base_controller.rb (revision 2128)
  578. app/controllers/admin/base_controller.rb (working copy)
  579. @@ -3,9 3,9 @@
  580. before_filter :login_from_cookie
  581. before_filter :login_required, :except => :feed
  582.  
  583. - def admin?
  584. - logged_in? && current_user.admin? || current_user.site_admin?
  585. - end
  586. -
  587. helper_method :admin?
  588.  
  589. protected
  590.  
  591. alias authorized? admin?
  592. end
  593. Index: app/views/account/login.rhtml
  594. ===================================================================
  595. --- app/views/account/login.rhtml (revision 2128)
  596. app/views/account/login.rhtml (working copy)
  597. @@ -1,8 1,9 @@
  598. -<%= start_form_tag({}, { :id => 'login_form' }) %>
  599. <div class="little-box">
  600. <%= start_form_tag({:controller=>:account, :action=>:login}, { :id => 'login_form' }) %>
  601. <%= hidden_field_tag "referrer", @referrer %>
  602. <dl>
  603. <dt><%= label_tag 'login', 'Login' %></dt>
  604. - <dd><%= text_field_tag 'login', {}, :class => 'big' %></dd>
  605. <dd><%= text_field_tag 'login', @login, :class => 'big' %></dd>
  606. <dt><%= label_tag 'password', 'Password' %></dt>
  607. <dd><%= password_field_tag 'password', {}, :class => 'big' %></dd>
  608. <dt></dt>
  609. @@ -12,5 13,16 @@
  610. </dd>
  611. </dl>
  612. <p class="btns"><%= submit_tag 'Sign in' %></p>
  613. <%= end_form_tag %>
  614. </div>
  615.  
  616. <br />
  617. <% if user=flash[:user_to_activate] -%>
  618. <div class="little-box">
  619. <%= start_form_tag({:controller=>:account, :action=>:send_activation_code}, { :id => 'send_activation_code_form' }) %>
  620. <p>Click the button below to send another activation code to <%=user.email%>.</p>
  621. <%= hidden_field_tag 'id', user.id %>
  622. <p class="btns"><%= submit_tag 'Resend code' %></p>
  623. <%= end_form_tag %>
  624. </div>
  625. <% end -%>
  626. Index: config/routes.rb
  627. ===================================================================
  628. --- config/routes.rb (revision 2128)
  629. config/routes.rb (working copy)
  630. @@ -12,6 12,8 @@
  631. map.admin 'admin', :controller => 'admin/overview', :action => 'index'
  632. map.resources :assets, :path_prefix => '/admin', :controller => 'admin/assets', :member => { :add_bucket => :post },
  633. :collection => { :latest => :post, :search => :post, :upload => :post, :clear_bucket => :post }
  634.  
  635. map.activate 'account/activate/:activation_code', :controller => 'account', :action => 'activate'
  636.  
  637. map.connect 'xmlrpc', :controller => 'backend', :action => 'xmlrpc'
  638.  
  639. Index: config/environment.rb
  640. ===================================================================
  641. --- config/environment.rb (revision 2128)
  642. config/environment.rb (working copy)
  643. @@ -4,6 4,10 @@
  644. # you don't control web/app server and can't set it the proper way
  645. # ENV['RAILS_ENV'] ||= 'production'
  646.  
  647. require 'rubygems'
  648. require 'ruby-debug'
  649. Debugger.start
  650.  
  651. # Bootstrap the Rails environment, frameworks, and default configuration
  652. require File.join(File.dirname(__FILE__), 'boot')
  653.  
  654. @@ -43,4 47,7 @@
  655. # Mephisto::SweeperMethods.cache_sweeper_tracing = true
  656.  
  657. # Enable if you want to host multiple sites on this app
  658. -# Site.multi_sites_enabled = true
  659. \ No newline at end of file
  660. # Site.multi_sites_enabled = true
  661.  
  662. UserNotifier.default_url_options[:host] = 'localhost:3000'
  663. UserNotifier.mail_from = 'webmaster@localhost'
  664. Index: db/schema.rb
  665. ===================================================================
  666. --- db/schema.rb (revision 2128)
  667. db/schema.rb (working copy)
  668. @@ -2,7 2,7 @@
  669. # migrations feature of ActiveRecord to incrementally modify your database, and
  670. # then regenerate this schema definition.
  671.  
  672. -ActiveRecord::Schema.define(:version => 56) do
  673. ActiveRecord::Schema.define(:version => 100) do
  674.  
  675. create_table "assets", :force => true do |t|
  676. t.column "content_type", :string
  677. @@ -162,6 162,7 @@
  678. t.column "remember_token_expires_at", :datetime
  679. t.column "filter", :string
  680. t.column "admin", :boolean, :default => false
  681. t.column "password_reset_code", :string, :limit => 40
  682. end
  683.  
  684. end
  685. Index: lib/mephisto/liquid/comment_form.rb
  686. ===================================================================
  687. --- lib/mephisto/liquid/comment_form.rb (revision 2128)
  688. lib/mephisto/liquid/comment_form.rb (working copy)
  689. @@ -9,12 9,12 @@
  690. context.stack do
  691. if context['message'].blank?
  692. errors = context['errors'].blank? ? '' : %Q{<ul id="comment-errors"><li>#{context['errors'].join('</li><li>')}</li></ul>}
  693. -
  694.  
  695. submitted = context['submitted'] || {}
  696. submitted.each{ |k, v| submitted[k] = CGI::escapeHTML(v) }
  697.  
  698. context['form'] = {
  699. - 'body' => %(<textarea id="comment_body" name="comment[body]">#{submitted['body']}</textarea>),
  700. 'body' => %(<textarea id="comment_body" class="commentbox" name="comment[body]">#{submitted['body']}</textarea>),
  701. 'name' => %(<input type="text" id="comment_author" name="comment[author]" value="#{submitted['author']}" />),
  702. 'email' => %(<input type="text" id="comment_author_email" name="comment[author_email]" value="#{submitted['author_email']}" />),
  703. 'url' => %(<input type="text" id="comment_author_url" name="comment[author_url]" value="#{submitted['author_url']}" />),
  704. @@ -30,4 30,4 @@
  705. end
  706. end
  707. end
  708. -end
  709. \ No newline at end of file
  710. end
  711. Index: lib/authenticated_system.rb
  712. ===================================================================
  713. --- lib/authenticated_system.rb (revision 2128)
  714. lib/authenticated_system.rb (working copy)
  715. @@ -36,10 36,16 @@
  716.  
  717. # store current uri in the session.
  718. # we can return to this location by calling return_location
  719. - def store_location
  720. - session[:return_to] = request.request_uri
  721. # Options:
  722. # * :overwrite - (default = true) Overwrite existing stored location
  723. # * :uri - Return to the specified URI (defaults to request.request_uri)
  724. def store_location(options={})
  725. options[:overwrite] = true if options[:overwrite].nil?
  726. return if !options[:overwrite] and session[:return_to]
  727. session[:return_to] = options[:uri] or request.request_uri
  728. else
  729. end
  730. -
  731.  
  732. # move to the last store_location call or to the passed default one
  733. def redirect_back_or_default(default)
  734. session[:return_to] ? redirect_to_url(session[:return_to]) : redirect_to(default)
  735. @@ -95,4 101,4 @@
  736. end
  737. return [user, pass]
  738. end
  739. -end
  740. \ No newline at end of file
  741. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement