Guest User

Untitled

a guest
Jul 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. class SessionsController < ApplicationController
  2. @base_uri = 'service.hwrdprkns.com:8080/'
  3.  
  4. def new
  5. @title = 'Sign In'
  6. end
  7.  
  8. def create
  9.  
  10. if params[:session][:email].blank? || params[:session][:password].blank?
  11. flash[:error] = 'You must fill out both fields.'
  12. @title = 'Sign In'
  13. redirect_to '/signin'
  14. end
  15.  
  16. vendor = authenticate(params[:session][:email],params[:session][:password])
  17. if vendor.nil?
  18. flash.now[:error] = 'Invalid email and password combination.'
  19. redirect_to '/signin'
  20. else
  21. #redirect user to show page.
  22. end
  23. end
  24.  
  25.  
  26. def authenticate(email,password)
  27. key = Base64.encode64(email+':'+password)
  28. params_hash = {:headers => {:authentication =>'Basic '+key}}
  29. response = HTTParty.get(@base_uri+'vendors/verifyVendorCredentials', params_hash)
  30. raise response
  31. end
  32.  
  33. def destroy
  34. sign_out
  35. redirect_to root_path
  36. end
  37.  
  38. end
Add Comment
Please, Sign In to add comment