Guest User

Untitled

a guest
Jan 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. public function Authenticate()
  2. {
  3. $user = isset($_POST['userName']) ? $_POST['userName'] : '';
  4. $pass = isset($_POST['userPassword']) ? $_POST['userPassword'] : '';
  5.  
  6. $payload = array('Request' => 'UserSignIn',
  7. 'userName' => $user,
  8. 'userPassword' => $pass);
  9.  
  10.  
  11. // Default error - if json_decode returns false then
  12. // this status will remain.
  13. $msg = 'Error parsing API response.';
  14. $status = 'ERROR';
  15.  
  16. // Invalid request, back to the sign in page with ya
  17. if( ! $user || ! $pass )
  18. {
  19. $response = false;
  20. $msg = 'Please provide both a username and password.';
  21. }
  22.  
  23. $cURLOptions = array(CURLOPT_URL => DRAWBRIDGE_API_REQUEST_URI,
  24. CURLOPT_POST => true,
  25. CURLOPT_POSTFIELDS => http_build_query($payload),
  26. CURLOPT_RETURNTRANSFER => true);
  27.  
  28. //print_r($cURLOptions);
  29.  
  30. try
  31. {
  32. $db = Factory::GetDrawbridge();
  33. $response = $db->Request($cURLOptions, 'JSON');
  34. }
  35. catch(Exception $e)
  36. {
  37. $response = false;
  38. $msg = $e->getMessage();
  39. //throw new Exception(sprintf("API Error: %s", $e->getMessage()));
  40. //var_dump($response);
  41. }
  42.  
  43. //echo Util::Debug($response);
  44.  
  45. // These conditions indicate that the request was
  46. // successful
  47. if( $response !== false &&
  48. isset($response->Status) &&
  49. isset($response->Message)
  50. )
  51. {
  52. // Set message
  53. $msg = $response->Message;
  54. $status = $response->Status;
  55. }
  56.  
  57. //echo Util::Debug($msg);
  58. //echo Util::Debug($status);
  59.  
  60. $message = Factory::GetMessage();
  61. $message->Add('ResponseMessage', $msg, 'Notice');
  62. $message->Add('ResponseStatus', $status, 'Notice');
  63. $message->Add('Response', $response, 'Notice');
  64.  
  65. $message->Add('signInTimestamp', time(), 'Info');
  66. $message->Add('UserInfo', $response->UserInfo, 'Info');
  67. $message->Add('signInTime', date('r'), 'Info');
  68.  
  69.  
  70. $location = ( $status == 'OK' ) ? '/' : '/user/signIn';
  71.  
  72. header(sprintf('Location: %s', $location));
  73. die;
  74. }
Add Comment
Please, Sign In to add comment