<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Api_Vb4_login extends vB_Api { public function facebook($signed_request, $devicetoken = null, $privacyconsent = null) { $cleaner = vB::getCleaner(); $signed_request = $cleaner->clean($signed_request, vB_Cleaner::TYPE_STR); $userAPI = vB_Api::instance('user'); $loginInfo = $userAPI->loginExternal('facebook', array('signedrequest' => $signed_request)); if (empty($loginInfo) || isset($loginInfo['errors'])) { return array('response' => array('errormessage' => array('badlogin_facebook'))); } if (!empty($loginInfo['login']['userid']) AND $privacyconsent !== null) { if ($privacyconsent) { $check = $userAPI->save( $loginInfo['login']['userid'], null, array('privacyconsent' => 1), null, array(), null ); } else { $userinfo = $userAPI->fetchUserinfo(); if (empty($userinfo['privacyconsent']) OR $userinfo['privacyconsent'] == -1) { $userAPI->logout(); throw new Exception('badlogin_no_privacy_consent'); } } } try { $updateTokenResult = vB_Library::instance('fcmessaging')->updateDeviceToken($devicetoken); } catch (Exception $e) { } $result = array( 'session' => array( 'dbsessionhash' => $loginInfo['login']['sessionhash'], 'userid' => $loginInfo['login']['userid'], ), 'response' => array( 'errormessage' => array('redirect_login') ), ); return $result; } public function login( $vb_login_username, $vb_login_password = null, $vb_login_md5password = null, $vb_login_md5password_utf = null, $devicetoken = null, $privacyconsent = null ) { $userAPI = vB_Api::instanceInternal('user'); $loginResult = $userAPI->login( $vb_login_username, $vb_login_password, $vb_login_md5password, $vb_login_md5password_utf ); if (!empty($loginResult['userid']) AND $privacyconsent !== null) { $userAPI = vB_Api::instance('user'); if ($privacyconsent) { $check = $userAPI->save( $loginResult['userid'], null, array('privacyconsent' => 1), null, array(), null ); } else { $userinfo = $userAPI->fetchUserinfo(); if (empty($userinfo['privacyconsent']) OR $userinfo['privacyconsent'] == -1) { $userAPI->logout(); throw new Exception('badlogin_no_privacy_consent'); } } } try { $updateTokenResult = vB_Library::instance('fcmessaging')->updateDeviceToken($devicetoken); } catch (Exception $e) { } return $loginResult; } public function logout() { vB_Library::instance('fcmessaging')->removeDeviceToken(); $logoutResult = vB_Api::instanceInternal('user')->logout(); return $logoutResult; } } 