Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function Authenticate()
- {
- $user = isset($_POST['userName']) ? $_POST['userName'] : '';
- $pass = isset($_POST['userPassword']) ? $_POST['userPassword'] : '';
- $payload = array('Request' => 'UserSignIn',
- 'userName' => $user,
- 'userPassword' => $pass);
- // Default error - if json_decode returns false then
- // this status will remain.
- $msg = 'Error parsing API response.';
- $status = 'ERROR';
- // Invalid request, back to the sign in page with ya
- if( ! $user || ! $pass )
- {
- $response = false;
- $msg = 'Please provide both a username and password.';
- }
- $cURLOptions = array(CURLOPT_URL => DRAWBRIDGE_API_REQUEST_URI,
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => http_build_query($payload),
- CURLOPT_RETURNTRANSFER => true);
- //print_r($cURLOptions);
- try
- {
- $db = Factory::GetDrawbridge();
- $response = $db->Request($cURLOptions, 'JSON');
- }
- catch(Exception $e)
- {
- $response = false;
- $msg = $e->getMessage();
- //throw new Exception(sprintf("API Error: %s", $e->getMessage()));
- //var_dump($response);
- }
- //echo Util::Debug($response);
- // These conditions indicate that the request was
- // successful
- if( $response !== false &&
- isset($response->Status) &&
- isset($response->Message)
- )
- {
- // Set message
- $msg = $response->Message;
- $status = $response->Status;
- }
- //echo Util::Debug($msg);
- //echo Util::Debug($status);
- $message = Factory::GetMessage();
- $message->Add('ResponseMessage', $msg, 'Notice');
- $message->Add('ResponseStatus', $status, 'Notice');
- $message->Add('Response', $response, 'Notice');
- $message->Add('signInTimestamp', time(), 'Info');
- $message->Add('UserInfo', $response->UserInfo, 'Info');
- $message->Add('signInTime', date('r'), 'Info');
- $location = ( $status == 'OK' ) ? '/' : '/user/signIn';
- header(sprintf('Location: %s', $location));
- die;
- }
Add Comment
Please, Sign In to add comment