Example #1
0
function vtws_loginportal($username, $password)
{
    $uname = 'portal';
    $user = new Users();
    $userId = $user->retrieve_user_id($uname);
    if (empty($userId)) {
        throw new WebServiceException(WebServiceErrorCode::$INVALIDUSERPWD, "User {$uname} does not exist");
    }
    global $adb, $log;
    $log->debug('Entering LoginPortal function with parameter username: '******'select id
			from vtiger_portalinfo
			inner join vtiger_customerdetails on vtiger_portalinfo.id=vtiger_customerdetails.customerid
			inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_portalinfo.id
			where vtiger_crmentity.deleted=0 and user_name=? and user_password=?
			  and isactive=1 and vtiger_customerdetails.portal=1', array($username, $password));
    if ($ctors and $adb->num_rows($ctors) == 1) {
        $user = $user->retrieveCurrentUserInfoFromFile($userId);
        if ($user->status != 'Inactive') {
            $result = $adb->query("SELECT id FROM vtiger_ws_entity WHERE name = 'Users'");
            $wsid = $adb->query_result($result, 0, 'id');
            $accessinfo = vtws_getchallenge($uname);
            $sessionManager = new SessionManager();
            $sid = $sessionManager->startSession(null, false);
            if (!$sid) {
                throw new WebServiceException(WebServiceErrorCode::$SESSIONIDINVALID, 'Could not create session');
            }
            $sessionManager->set("authenticatedUserId", $userId);
            $accessinfo['sessionName'] = $sessionManager->getSessionId();
            $accessinfo['user'] = array('id' => $wsid . 'x' . $userId, 'user_name' => $user->column_fields['user_name'], 'accesskey' => $user->column_fields['accesskey']);
            return $accessinfo;
        } else {
            throw new WebServiceException(WebServiceErrorCode::$AUTHREQUIRED, 'Given user is inactive');
        }
    }
    throw new WebServiceException(WebServiceErrorCode::$AUTHREQUIRED, "Given contact is inactive");
}
Example #2
0
function webforms_init()
{
    global $defaultUserName, $defaultUserAccessKey, $defaultOwner, $adb, $enableAppKeyValidation, $application_unique_key;
    try {
        $active = vtlib_isModuleActive('Webforms');
        if ($active === false) {
            webforms_returnError(array('code' => "WEBFORMS_DISABLED", 'message' => 'Webforms module is disabled'), 'Webforms');
        }
        if ($enableAppKeyValidation == true) {
            if ($application_unique_key !== $_REQUEST['appKey']) {
                webforms_returnError(array('code' => "WEBFORMS_INVALID_APPKEY", 'message' => 'AppKey provided is invalid'), null);
                return;
            }
        }
        $module = $_REQUEST['moduleName'];
        $challengeResult = vtws_getchallenge($defaultUserName);
        $challengeToken = $challengeResult['token'];
        $user = vtws_login($defaultUserName, md5($challengeToken . $defaultUserAccessKey));
        $describeResult = vtws_describe($module, $user);
        $fields = $describeResult['fields'];
        $assignedUser = new Users();
        $ownerId = $assignedUser->retrieve_user_id($defaultOwner);
        $userData = webforms_getUserData(vtws_getId(VtigerWebserviceObject::fromName($adb, "Users")->getEntityId(), $ownerId), $fields, $_REQUEST);
        if ($userData === null) {
            webforms_returnError(array('code' => "WEBFORMS_INVALID_DATA", 'message' => 'data provided is invalid'), $module);
            return;
        }
        if (sizeof($userData) < 1) {
            webforms_returnError(array('code' => "WEBFORMS_INVALID_DATA", 'message' => 'data provided is invalid'), $module);
            return;
        }
        $createResult = vtws_create($module, $userData, $user);
        webforms_returnSuccess($createResult, $module);
    } catch (WebServiceException $e) {
        webforms_returnError($e, $module);
    }
}