Guest User

Untitled

a guest
Apr 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. ## page controller
  2. def save_article
  3. # TODO: validate the HTML coming in with hpricot
  4.  
  5. # validate that the user is logged in
  6. unless logged_in?
  7. # save this request in the session for after login
  8. session[:r_request] = request
  9. session[:r_controller] = params[:controller]
  10. session[:r_action] = params[:action]
  11.  
  12. # raise the NotLoggedIn exception to capture the login
  13. return raise(NotLoggedIn)
  14. end
  15.  
  16. # (article revision saved here)
  17.  
  18. end
  19.  
  20. ## account controller
  21.  
  22. def login
  23. session[:user] = User.first(:email=>params[:email], :password=>params[:password])
  24. if logged_in?
  25. flash[:notice] = "Welcome back, " + session[:user].name[/(\w\w\w+)/,1] + '!'
  26.  
  27. # was this called from a NotLoggedIn exception?
  28. # if so, pick up where we left off
  29. unless session[:r_request].nil?
  30. r_request = session[:r_request]
  31. r_controller = session[:r_controller]
  32. r_action = session[:r_action]
  33. session[:r_request] = nil
  34. session[:r_controller] = nil
  35. session[:r_action] = nil
  36.  
  37. # copy merb's dispather to run the original request
  38. controller = Object.full_const_get(r_controller.to_const_string).new(r_request, 200)
  39. controller._dispatch(r_action.to_sym)
  40. return controller.body#.to_yaml #(debuging)
  41. else
  42. return redirect(url(:home))
  43. end
  44. end
  45.  
  46. flash[:error] = "Your login did not succeed, please try again."
  47. redirect url(:home)
  48. end
Add Comment
Please, Sign In to add comment