/** * Implementation for 'POST' method for Rest API * * @param mixed $sesUid Primary key * * @return array $result Returns array within multiple records or a single record depending if * a single selection was requested passing id(s) as param */ protected function post($sesUid, $sesStatus, $usrUid, $sesRemoteIp, $sesInitDate, $sesDueDate, $sesEndDate) { try { $result = array(); $obj = new Session(); $obj->setSesUid($sesUid); $obj->setSesStatus($sesStatus); $obj->setUsrUid($usrUid); $obj->setSesRemoteIp($sesRemoteIp); $obj->setSesInitDate($sesInitDate); $obj->setSesDueDate($sesDueDate); $obj->setSesEndDate($sesEndDate); $obj->save(); } catch (Exception $e) { throw new RestException(412, $e->getMessage()); } }
/** * function to start a web services session in ProcessMaker * * @param string $userid * @param string $password * @return $wsResponse will return an object */ public function login ($userid, $password) { global $RBAC; try { $uid = $RBAC->VerifyLogin( $userid, $password ); switch ($uid) { case '': case - 1: //The user doesn't exist $wsResponse = new wsResponse( 3, G::loadTranslation( 'ID_USER_NOT_REGISTERED' ) ); break; case - 2: //The password is incorrect $wsResponse = new wsResponse( 4, G::loadTranslation( 'ID_WRONG_PASS' ) ); break; case - 3: //The user is inactive $wsResponse = new wsResponse( 5, G::loadTranslation( 'ID_USER_INACTIVE' ) ); break; case - 4: //The Due date is finished $wsResponse = new wsResponse( 5, G::loadTranslation( 'ID_USER_INACTIVE' ) ); break; } if ($uid < 0 || $uid == '') { throw (new Exception( serialize( $wsResponse ) )); } //check access to PM $RBAC->loadUserRolePermission( $RBAC->sSystem, $uid ); $res = $RBAC->userCanAccess( "PM_LOGIN" ); if ($res != 1) { //if ($res == -2) // $wsResponse = new wsResponse(1, G::loadTranslation('ID_USER_HAVENT_RIGHTS_SYSTEM')); //else $wsResponse = new wsResponse( 2, G::loadTranslation( 'ID_USER_HAVENT_RIGHTS_SYSTEM' ) ); throw (new Exception( serialize( $wsResponse ) )); } $sessionId = G::generateUniqueID(); $wsResponse = new wsResponse( '0', $sessionId ); $session = new Session(); $session->setSesUid( $sessionId ); $session->setSesStatus( 'ACTIVE' ); $session->setUsrUid( $uid ); $session->setSesRemoteIp( $_SERVER['REMOTE_ADDR'] ); $session->setSesInitDate( date( 'Y-m-d H:i:s' ) ); $session->setSesDueDate( date( 'Y-m-d H:i:s', mktime( date( 'H' ), date( 'i' ) + 15, date( 's' ), date( 'm' ), date( 'd' ), date( 'Y' ) ) ) ); $session->setSesEndDate( '' ); $session->Save(); //save the session in DataBase return $wsResponse; } catch (Exception $e) { $wsResponse = unserialize( $e->getMessage() ); return $wsResponse; } }