Guest User

Untitled

a guest
Jun 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. prepend_before_filter(:preprocessRequest)
  2. # Anything we want to happen before a request is handled.
  3. def preprocessRequest()
  4. # If the request is a POST with a login attempt...
  5. if((request.post?) && (params[:commit] == "Login!") && (params[:User]))
  6.  
  7. require("digest")
  8. params[:User][:passwordMD5] = Digest::MD5.hexdigest(params[:User][:passwordMD5])
  9. @user = User.find_by_eMail_and_passwordMD5(params[:User][:eMail], params[:User][:passwordMD5])
  10.  
  11. params[:User][:passwordMD5] = nil
  12.  
  13. # If the login succeeded, @user will be an instance of User.
  14. if(@user.kind_of?(User))
  15.  
  16. flash[:notice] = "You have sucessfully logged in! Your current user information appears on the left side of the page."
  17.  
  18. # The login failed, re-populate with the email address.
  19. else
  20.  
  21. @user = User.create(params[:User])
  22. flash[:formErrors] = @user.errors
  23. end
Add Comment
Please, Sign In to add comment