<?php
	require_once("common.inc");
    $consumer = getConsumer();
    $return_to = getReturnTo();
    $response = $consumer->complete($return_to);
    if ($response->status == Auth_OpenID_CANCEL) {
        $msg = 'Verification cancelled.';
        $app = "2";
    } else if ($response->status == Auth_OpenID_FAILURE) {
        $msg = "OpenID authentication failed: " . $response->message;
        $app = "2";
    } else if ($response->status == Auth_OpenID_SUCCESS) {
        $openid = $response->getDisplayIdentifier();
        $esc_identity = htmlspecialchars($openid, ENT_QUOTES);
        $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
        $sreg = $sreg_resp->contents();
progress(__FILE__,__LINE__,"Just got sreg.");
buggywuggy(print_r($sreg_resp,TRUE));
reset($sreg);
foreach ($sreg as $_key=>$_value)
{
  buggywuggy("sreg[$_key]=>$_value");
  buggywuggy($_key);
  buggywuggy($_value);
  buggywuggy("Did an element of sreg.");
}
reset($sreg);
        if (@$sreg['nickname']) {
progress(__FILE__,__LINE__);
          $nickName = $sreg['nickname'];
        } else {
progress(__FILE__,__LINE__);
	        $nickName = $openid;
	      }
buggywuggy("We got a nickname of $nickName.");
        if (@$sreg['email']) {
            $emailAdddress = $sreg['email'];
            buggywuggy("The email address is $emailAdddress.");
        }
        else
          buggywuggy("No email address available.");
        $_SESSION['isSession'] = "true";
	      $_SESSION['sessionTime'] = time();
	      $_SESSION['userIdentity'] = $openid;
        $success =  "Authenticated ".$openid;	
    } 
?>