Confirms a users username and password, and optionally returns user information.
If returnUserInfo is set to false, this method will return the user id when the settings were correct. This method always returns false when username or password is incorrect.
If login is set to true a session will be started and the system will return a sessiontoken property in the userData struct. If the returnUserInfo is false, login will be ignored.
This is the data array that could potentially be returned if returnUserInfo is set to true
Name | Type | Description |
---|
id | INT | The user id for the username/email provided. |
user | STRING | The username for the account requested. |
vhost | INT | The vhost for the account requested. |
firstname | STRING | The first name for the account requested. |
lastname | STRING | The last name for the account requested. |
nickname | STRING | The nickname for the account requested. |
address1 | STRING | The first line of the address for the account requested. |
address2 | STRING | The second line of the address for the account requested. |
city | STRING | The city for the account requested. |
state | STRING | The state/province for the account requested. |
country | STRING | The country for the requested account. |
postal | STRING | The postal code or zip code for the requested account. |
email | STRING | The e-mail address for the requested account. |
website | STRING | The website for the requested account. |
gender | CHAR | The gender of the requested account owner, obviously this is only going to be M for male or F for female. |
phone | STRING | The phone number for the requested account owner. |
cellphone | STRING | The cell phone number for the requested account owner. |
occupation | STRING | The occupation for the requested account owner. |
meta | SERIALIZED ARRAY | An array containing any meta data that was provided by the account owner that has been saved by the system. |
newsletter | BOOL | Whether or not the account owner wanted the newsletter or not. 1 is true, 0 is false. |
Sample REST Response
http://api.newspark.ca/services/rest/users/confirmCredentials?vhost=[VHOST_ID]&username=[USERNAME]&password=[USER_PASSWORD]&APIKEY=[APIKEY]
<?xml version="1.0" encoding="UTF-8"?>
<result>USER_ID</result>
Sample JSON Response
{
"status": true,
"result": USER_ID
}
Sample REST Response
http://api.newspark.ca/services/rest/users/confirmCredentials?vhost=[VHOST_ID]&username=[USERNAME]&password=[USER_PASSWORD]&returnUserInfo=true&APIKEY=[APIKEY]
<?xml version="1.0" encoding="UTF-8"?>
<result>
<id>USER_ID</id>
<user>USER_NAME</user>
<email>USER_EMAIL</email>
<firstname>USER_FIRSTNAME</firstname>
<lastname>USER_LASTNAME</lastname>
<city>Toronto</city>
<gender>M</gender>
<cellphone>4162222222</cellphone>
<phone>4162222222</phone>
<website/>
<occupation/>
<address1>1 Toronto Street</address1>
<address2/>
<state>ON</state>
<country>CA</country>
<newsletter>0</newsletter>
<nickname/>
<vhost>VHOST_ID</vhost>
<meta>
<lang>en</lang>
<twitterUserName/>
<rules>1</rules>
</meta>
</result>
Sample JSON Response
{
"status": true,
"result": {
"id": USER_ID,
"user": "USER_NAME",
"email": "USER_EMAIL",
"firstname": "USER_FIRSTNAME",
"lastname": "USER_LASTNAME",
"city": "Toronto",
"gender": "M",
"cellphone": "4162222222",
"phone": "4162222222",
"website": "",
"occupation": "",
"address1": "1 Toronto Street",
"address2": null,
"state": "ON",
"country": "CA",
"newsletter": "0",
"nickname": "",
"vhost": VHOST_ID,
"meta": {
"lang": "en",
"twitterUserName": "",
"rules": "1"
}
}
}
PHP-RPC
$path = 'https://api.newspark.ca/services/php';
// Listing the arguments
$arguments = array(
'APIKEY' => 'YOURAPIKEY',
'method' => 'users.confirmCredentials',
'vhost' => '2',
'username' => $username,
'password' => $password,
'returnUserInfo' => $returnUserInfo,
'login' => $login,
'isEmail' => $isEmail,
'isPhone' => $isPhone,
'detailedError' => $detailedError,
'mfatoken' => $mfatoken
);
// http_build_query basically turns an array into a url-encoded list of variables
$url = $path .'?' . http_build_query($arguments,null,'&');
// get the contents from the specified url
$data = file_get_contents($url);
// transform it back into php data structures
$data = unserialize($data);
// the actual data is stored in $data['result']
print_r($data['result']);
back to topPEAR XMLRPC client
// Include the client
require_once 'XML/RPC.php';
// Create the XMLRPC Client
$client = new XML_RPC_Client('/services/xmlrpc?APIKEY={YOURAPIKEY}', 'api.newspark.ca');
// PEAR's XML-RPC client requires all arguments to wrapped in a special value class
// XML_RPC_encode converts this automatically
$arguments = array(
XML_RPC_encode('2'),
XML_RPC_encode($username),
XML_RPC_encode($password),
XML_RPC_encode($returnUserInfo),
XML_RPC_encode($login),
XML_RPC_encode($isEmail),
XML_RPC_encode($isPhone),
XML_RPC_encode($detailedError),
XML_RPC_encode($mfatoken)
);
// Creating an XML-RPC message
$message = new XML_RPC_Message('users.confirmCredentials',$arguments);
// Sending the message to the server
$response = $client->send($message);
// We also need to decode the response back to normal PHP types
$response = XML_RPC_decode($response);
print_r($response);
back to topSabreTooth XMLRPC client
// Include the client
require_once 'Sabre/XMLRPC/Client.php';
// Create the XMLRPC Client
$xmlrpc = new Sabre_XMLRPC_Client('https://api.newspark.ca/services/xmlrpc?APIKEY={YOURAPIKEY}');
$arguments = array(
'2',
$username,
$password,
$returnUserInfo,
$login,
$isEmail,
$isPhone,
$detailedError,
$mfatoken
);
$data = $xmlrpc->invoke('users.confirmCredentials',$arguments);
print_r($data);
back to topZend XMLRPC client
// Include the client
require_once 'Zend/XmlRpc/Client.php';
// Create the XMLRPC Client
$client = new Zend_XmlRpc_Client('https://api.newspark.ca/services/xmlrpc?APIKEY={YOURAPIKEY}');
$arguments = array(
'2',
$username,
$password,
$returnUserInfo,
$login,
$isEmail,
$isPhone,
$detailedError,
$mfatoken
);
$data = $client->call('users.confirmCredentials',$arguments);
print_r($data);
back to topActionscript 2
/*
* In ActionScript 2 remote service calls are done using the RemotingConnector Component.
* An instance of the component must exist on the stage and have an instance name.
*
* Results and Faults are handled by addEventListener's and the call parameters are placed inside of an associative array
*
* You must also specify the service class and method names under the appropriate property fields of the component
*/
var gatewayURL:String = "/services/amf2";
//Set up service call
myRemConn_rc.gatewayUrl = gatewayURL;
myRemConn_rc.serviceName = "users";
myRemConn_rc.methodName = "confirmCredentials";
myRemConn_rc.params = {2:vhost, username:username, password:password, returnUserInfo:returnUserInfo, login:login, isEmail:isEmail, isPhone:isPhone, detailedError:detailedError, mfatoken:mfatoken};
myRemConn_rc.addEventListener("result", widgetResult);
myRemConn_rc.addEventListener("status", widgetFault);
//Make the call
myRemConn_rc.trigger();
/*
* Handles service result.
*/
function widgetResult(ev:Object){
//Do stuff
//Data is returned inside of ev.target.results
//(i.e. ev.traget.results.description or ev.traget.results.settings.color)
}
/*
* Handles service fault.
*/
function widgetFault(ev:Object){
//Display Error
trace("Categories Error - " + ev.code + " - " + ev.data.faultstring);
}
back to topActionscript 3
/*
* In ActionScript 3 remote service calls are done using the NetConnection Object.
* A Responder Object controls what functions handle successful or failed calls
* and any parameters for the call are placed in an array and passed as a parameter
* in the NetConnection.call() method.
*/
var gatewayURL:String = "/services/amf2";
var parameters:Array = new Array(vhost, username, password, returnUserInfo, login, isEmail, isPhone, detailedError, mfatoken);
var connection:NetConnection = new NetConnection();
connection.connect(gatewayURL);
connection.call("users.confirmCredentials", new Responder(widgetResult, widgetFault), parameters);
/*
* Handles service result.
*/
function widgetResult(ev:Object):void{
//Do stuff
//Data is returned inside of ev
//(i.e. ev.description or ev.settings.color)
}
/*
* Handles service fault.
*/
function widgetFault(ev:Object):void{
//Display Error
error.showError(parentClip, ev.code + " - " + ev.description, "Please refresh your browser to try again.");
error.x = (parentClip.width - error.width) / 2;
error.y = (parentClip.height - error.height) / 2;
}
back to topREST service example
<%@ Page Language="vb" %>
<%
' REST gateway
dim gateway as string = "http://api.newspark.ca/services/rest/"
' Service + method we're calling.
dim method as string = "users/confirmCredentials"
dim apiKey as string = "YOURAPIKEY"
dim url as string = gateway & method & "?APIKEY=" & apiKey & "&vhost=2" & "&username=" & username & "&password=" & password
' HTTP Client
dim wcHTTPScrape as new System.net.WebClient()
' Opening a stream
dim objInput as System.IO.Stream = wcHTTPScrape.OpenRead(url)
dim objReader as new System.IO.StreamReader ( objInput )
' Reading the entire HTTP response and output it
Response.Write ( objReader.ReadToEnd () )
objReader.Close ()
objInput.Close ()
%>
back to topjQuery JSON
/*
* jQuery post example
*/
function confirmCredentials ( username, password, returnUserInfo, login, isEmail, isPhone, detailedError, mfatoken ) {
var params = {
"method" : 'users.confirmCredentials',
"vhost" : 2,
"username" : username,
"password" : password,
"returnUserInfo" : returnUserInfo,
"login" : login,
"isEmail" : isEmail,
"isPhone" : isPhone,
"detailedError" : detailedError,
"mfatoken" : mfatoken}
$.post('/services/json',params
,function(response){
console.log(response);
});
back to topLocal API
// Get the Service Mapper
$mapper = Sabre_ServiceMap_Mapper::getMapper();
// Calling the method
$data = $mapper->users->confirmCredentials( 2, $username, $password, $returnUserInfo, $login, $isEmail, $isPhone, $detailedError, $mfatoken );
print_r($data);
back to top