Mobile_WS_Controller not found - php

Hi in the below php file I am calling in my android application but I am tried in postman am getting the below error.Using this url am accessing the login page but it is not working .No response from app
can any one please help me
Login.php:
<?php
class Mobile_WS_Login extends Mobile_WS_Controller {
function requireLogin() {
return false;
}
function process(Mobile_API_Request $request) {
$response = new Mobile_API_Response();
$username = $request->get('username');
$password = $request->get('password');
$current_user = CRMEntity::getInstance('Users');
$current_user->column_fields['user_name'] = $username;
if(vtlib_isModuleActive('Mobile') === false) {
$response->setError(1501, 'Service not available');
return $response;
}
if(!$current_user->doLogin($password)) {
$response->setError(1210, 'Authentication Failed');
} else {
// Start session now
$sessionid = Mobile_API_Session::init();
if($sessionid === false) {
echo "Session init failed $sessionid\n";
}
$current_user->id = $current_user->retrieve_user_id($username);
$current_user->retrieveCurrentUserInfoFromFile($current_user->id);
$this->setActiveUser($current_user);
$result = array();
$result['login'] = array(
'userid' => $current_user->id,
'crm_tz' => DateTimeField::getDBTimeZone(),
'user_tz' => $current_user->time_zone,
'user_currency' => $current_user->currency_code,
'session'=> $sessionid,
'vtiger_version' => Mobile_WS_Utils::getVtigerVersion(),
'date_format' => $current_user->date_format,
'mobile_module_version' => Mobile_WS_Utils::getVersion()
);
$response->setResult($result);
$this->postProcess($response);
}
return $response;
}
function postProcess(Mobile_API_Response $response) {
return $response;
}
}
Postman:
URL:http://XXXXXXX/modules/mobile/api/ws/Login.php
parms: username:abc
password:abc1
operation:login
Response From Postman:
<br />
<b>Fatal error</b>: Class 'Mobile_WS_Controller' not found in
<b>C:\xampp\htdocs\crmtest\modules\Mobile\api\ws\Login.php</b> on line
<b>10</b>
<br />

Related

Facebook login php sdk - problem on mobile devices - empty headers [website app]

I have a little problem with my integration with Facebook PHP SDK on my website. On desktop everything works fine. When try to register account using fb-login button on mobile devices despite the successful redirection from the facebook website to my website, it receives an empty response.
I don't know where is the main problem, session, redirects policy, cookie problem?
The problem does not exist when accounts are merged and connected - so login function works on mobile, just creating account and connecting new ids.
I note that everything works fine on the desktop version
my config
Facebook PHP SDK: 5.6.2
Graph API: v14.0
$config = array_merge([
'app_id' => getenv(static::APP_ID_ENV_NAME),
'app_secret' => getenv(static::APP_SECRET_ENV_NAME),
'default_graph_version' => static::DEFAULT_GRAPH_VERSION,
'enable_beta_mode' => false,
'http_client_handler' => null,
'persistent_data_handler' => 'memory',
'pseudo_random_string_generator' => null,
'url_detection_handler' => null,
], $config);
You can see the code implementations below
public function _facebook_account($action = null){
$isLogged = $this->getCustomer()->isAuthenticated();
$fb = FacebookAPIHelper::getInstance()->getAPI($this->getContext());
$redirectUrl = null;
if (!empty($_POST['secret_code']))
{
$code = $_POST['secret_code'];
}
if (!$isLogged) {
if ($action == FacebookAPI::ACTION_LOGIN || $action == FacebookAPI::ACTION_REGISTER){
$redirectUrl = '/customer/login_with_facebook/' . $action;
}
}
else{
if ($action == FacebookAPI::ACTION_MERGE) {
$redirectUrl = '/customer/merge_with_facebook';
}
else {
$this->redirectTo('customer,profile');
}
}
if (!is_null($redirectUrl)) {
$url = $fb->getLoginUrl($this->getRouter()->getHost(null, true) . $redirectUrl, isset($code) ? $code : null);
header("Location: $url");
}
else {
$this->redirectTo('');
}
}
2
try {
$facebookProfileData = FacebookLoginHelper::getFacebookProfileData($this->getContext());
if ($facebookProfileData) {
$customer = FacebookLoginHelper::findOrCreateCustomerByFacebookProfileData($facebookProfileData);
} else {
$this->addMessageForNextRequest('`facebook_login.error_fetch_user_data`');
$this->redirectTo('customer,login');
}
if (is_null($customer)) {
$customer = CustomerBase::getCustomerFromFacebookProfileData($facebookProfileData);
if (Module::moduleInstalled('referer')) {
if ($this->hasCookie(RefererSettings::COOKIE_NAME)) {
$referer = $this->getCookie(RefererSettings::COOKIE_NAME);
$customer->referer = $referer;
}
}
$this->view->customer = $customer;
$this->renderAction('confirm_customer_data.tpl');
}
3
public function _login_with_facebook($action)
{
$customer = null;
$oldCustomer = $this->getCustomer();
$isLogged = $oldCustomer->isAuthenticated();
$facebookLoginNotInstalled = Module::moduleInstalled('facebook_login') == false;
if ($isLogged) {
$this->redirectTo('customer,profile');
return;
}
if ($facebookLoginNotInstalled) {
$this->redirectTo('customer,login');
return;
}
try {
$facebookProfileData = FacebookLoginHelper::getFacebookProfileData($this->getContext());
if ($facebookProfileData) {
$customer = FacebookLoginHelper::findOrCreateCustomerByFacebookProfileData($facebookProfileData);
} else {
$this->addMessageForNextRequest('`facebook_login.error_fetch_user_data`');
$this->redirectTo('customer,login');
}
if (is_null($customer)) {
$customer = CustomerBase::getCustomerFromFacebookProfileData($facebookProfileData);
if (Module::moduleInstalled('referer')) {
if ($this->hasCookie(RefererSettings::COOKIE_NAME)) {
$referer = $this->getCookie(RefererSettings::COOKIE_NAME);
$customer->referer = $referer;
}
}
$this->view->customer = $customer;
$this->renderAction('confirm_customer_data.tpl');

Yii No data received in post method only on server

Created an API endpoint I which I am submitted data as the body in postman, but it is always empty on the server whereas it works fine on localhost.
Please look at the request
The same request works on localhost but not online. Here is code on the server side I am using Yii::$app->request->post() to dump the data, here is the full code of that endpoint. I had tried $_POST,$_REQUEST every request is empty on the server,
public function actionSocialcheck()
{
$data = [];
$model = new User();
var_dump(Yii::$app->request->post());
if ($model->load(Yii::$app->request->post(),'')) {
$social = User::findBySocialLogin($model->socialLogin);
if (empty($social)) {
$data['status'] = self::API_OK;
$data['check'] = false;
} else {
if (Yii::$app->request->post('role_id') != $social->role_id) {
$data['error'] = \Yii::t('app', "You don't have permission to login as " . User::getRoleOptions($social->role_id));
return $this->response = $data;
}
$data['error'] = \yii::t('app', "Social ID already exists.");
$data['check'] = true;
$data['status'] = self::API_OK;
$data['detail'] =$social;
$data['access-token'] = $social->access_token;
// $usercl=new User();
$loginarr = array(
'device_name' => Yii::$app->request->post('device_name'),
'device_token' => Yii::$app->request->post('device_token'),
'device_type' => Yii::$app->request->post('device_type'),
);
$data['login_detail']=$loginarr;
}
} else {
$data['error'] = "Data not posted.";
}
$this->response = $data;
}
When I try the same request on the local server it works fine here is the output of that
Can you please help me out in this case. Thanks
public function actionSocialcheck(){
if(Yii::$app->request->isPost){
$data = [];
$social = User::findBySocialLogin(Yii::$app->request->post('socialLogin'));
if (empty($social)){
$data['status'] = self::API_OK;
$data['check'] = false;
}else{
if (Yii::$app->request->post('role_id') != $social->role_id) {
$data['error'] = \Yii::t('app', "You don't have permission to login as " . User::getRoleOptions($social->role_id));
return $this->response = $data;
}
$data['error'] = \yii::t('app', "Social ID already exists.");
$data['check'] = true;
$data['status'] = self::API_OK;
$data['detail'] =$social;
$data['access-token'] = $social->access_token;
$loginarr = array(
'device_name' => Yii::$app->request->post('device_name'),
'device_token' => Yii::$app->request->post('device_token'),
'device_type' => Yii::$app->request->post('device_type'),
);
$data['login_detail']=$loginarr;
}
}else {
$data['error'] = "Data not posted.";
}
$this->response = $data;
}

Undefined index X-Api-Key in cake php

I am trying to post some data in json format and passing 'X-Api-Key' as header key. But my code always give notice of undefined index x-api-key. And no data is stored.
I am using cake php 2.x
Here is my php code
public function checkXAPI() {
$headers = apache_request_headers();
//X-Api-key unidentified
if($headers['X-Api-Key'] == 'AB5433GMDF657VBB'){
return true;
} else {
return true;
}
}
public function beforeFilter(){
$this->Auth->Allow(array('checkXAPI','Registerowner'));
$headersNotAllowed = array('login', 'checkXAPI', 'register');
$noSecurityAllowed = array('register');
if(!in_array($this->request->action, $noSecurityAllowed)){
$checkXAPI = $this->checkXAPI();
if (!$checkXAPI) {
$message = array(
'status' => false,
'message' => __('wrong X-API')
);
echo json_encode($message);
exit;
} else {
$headers = apache_request_headers();
if(!in_array($this->request->action, $headersNotAllowed)){
if (isset($headers['Id'])) {
$checkUserToken = $this->checkUserToken();
if (!$checkUserToken) {
$message = array(
'status' => false,
'message' => __('wrong User ID and User token combination')
);
echo json_encode($message);
exit;
}
}
}
}
}
}
Use $this->request->header('X-Api-Key') instead:
public function checkXAPI() {
return $this->request->header('X-Api-Key') === 'AB5433GMDF657VBB';
}

Update query for API in codeigniter is not working

i want to write a API for updating data in sql. I am using CI for it.I am new to this field.while i have written it is not working in localhost itself .Can anyone help me? I am attaching my controller and model here.it is showing an error like this page is not working
function editprofile($id,$data) {
$this->db->where(array('user_id' => $id));
$this->db->update('registrationdetails', $data);
if(!empty($id))
{
$result = true;
} else {
$result = false;
}
return $result;
}
public function updateuser()
{
$adminId = 1;
$AUTHENTIC_KEY = "4u0IOxa1YTwNo38QjArD9ysW6PgVnbX7vtlJ";
$user_id=2;
$firstname ="aiswarya";
$lastname ="mathew";
$email ="aiswarya#gmail.com";
$password ="aiswarya";
$confirmpassword ="aiswarya";
$contactnumber ="999999999";
$gender ="female";
$address ="canada";
$department ="cse";
$designation ="swe";
$Admindetails = $this->common->CheckValidAdmin($adminId,$AUTHENTIC_KEY);
if($Admindetails != false)
{
$validAdmin = array('authentication_key' => $Admindetails->authentication_key,
'admin_id' => $Admindetails->id
);
$data = array();
$data = array('firstname'=>$firstname,'lastname'=>$lastname,'email'=>$email,'password'=>$password,'confirmpassword'=>$confirmpassword,'contactnumber'=>$contactnumber,'gender'=>$gender,'address'=>$address,'department'=>$department,'designation'=>$designation);
$status = $this->user->editprofile($user_id,$data);
if($status == true)
{
$response = array('status' => 200,
'message' => 'updated successfully',
'admin_details' => $validAdmin
);
} else {
$response = array('status' => 404,
'message' => 'unable to add, please try again',
'admin_details' => $validAdmin);
}
} else {
$response = array('status' => 404,
'message' => 'Authentication Failed');
}
echo json_encode($response);
}
function editprofile($data) {
if(!empty($data['user_id']))
{
$this->db->where(array('user_id' => $data['user_id']));
$this->db->update('registrationdetails', $data);
$result = true;
} else {
$result = false;
}
return $result;
}
public function updateuser()
{
$data['adminId'] = 1;
$data['AUTHENTIC_KEY'] = "4u0IOxa1YTwNo38QjArD9ysW6PgVnbX7vtlJ";
$data['user_id']=2;
$data['firstname'] ="aiswarya";
$data['lastname'] ="mathew";
$data['email'] ="aiswarya#gmail.com";
$data['password'] ="aiswarya";
$data['confirmpassword'] ="aiswarya";
$data['contactnumber'] ="999999999";
$data['gender'] ="female";
$data['address'] ="canada";
$data['department'] ="cse";
$data['designation'] ="swe";
$Admindetails = $this->common->CheckValidAdmin($data['adminId'],$data['AUTHENTIC_KEY']);
if($Admindetails != false)
{
$validAdmin = array('authentication_key' => $Admindetails->authentication_key,
'admin_id' => $Admindetails->id);
$status = $this->user->editprofile($data);
if($status == true)
{
$response = array('status' => 200,
'message' => 'updated successfully',
'admin_details' => $validAdmin
);
} else {
$response = array('status' => 404,
'message' => 'unable to add, please try again',
'admin_details' => $validAdmin);
}
} else {
$response = array('status' => 404,
'message' => 'Authentication Failed');
}
echo json_encode($response);
}

posting in group on behalf of user using facebook graph API

I am trying to post on behalf of user. I have used tutorial given on this page: http://25labs.com/updated-post-to-multiple-facebook-pages-or-groups-efficiently-v2-0/ .
I could successfully perform authentication but could not post on behalf.
Here is the source code : https://github.com/karimkhanp/fbPostOnBehalf
Testing can be done here: http://ec2-54-186-110-98.us-west-2.compute.amazonaws.com/fb/
Does any one experienced this?
I'm not familiar with the batch process that the tutorial is using but below is a code sample that posts to a Facebook group
<?php
# same this file as
# test.php
include_once "src/facebook.php";
$config = array(
'appId' => "YOURAPPID",
'secret' => "YOURAPPSECRET",
'allowSignedRequest' => false, // optional, but should be set to false for non-canvas apps
);
class PostToFacebook
{
private $facebook;
private $pages;
public function initialise($config){
$this->name = "Facebook";
// current necessary configs to set
// $config = array(
// 'appId' => FB_APP_ID,
// 'secret' => FB_APP_SECRET,
// 'allowSignedRequest' => false, // optional, but should be set to false for non-canvas apps
// );
$this->facebook = new Facebook($config);
try{
// if user removes app authorization
$this->hasAccess = $this->has_permissions();
if($this->hasAccess){
$this->groups = $this->getGroupData();
}
}
catch(Exception $err){
}
}
public function postMessageToGroup($message, $groupid){
$messageResponse = array(
'STATUS' => 0
);
$fbMessageObj = array(
"message" => strip_tags($message),
);
try
{
$user_page_post = $this->facebook->api("/$groupid/feed", 'POST', $fbMessageObj);
if($user_page_post && !empty($user_page_post['id'])){
$messageResponse['STATUS'] = 200;
$messageData = array(
'id' => $user_page_post['id'],
'link' => 'http://facebook.com/' . $user_page_post['id'],
);
$messageResponse['data'] = $messageData;
}
else{
$messageResponse['STATUS'] = 302;
}
}
catch(Exception $err){
$messageResponse['STATUS'] = 500;
$messageResponse['data'] = array($err);
}
return $messageResponse;
}
// TODO: should read a template somewhere
function show_login() {
$login_url = $this->facebook->getLoginUrl( array( 'scope' => implode(",",$this->permissions()) ));
return 'Login to Facebook and Grant Necessary Permissions';
}
// TODO: should read a template somewhere
public function toString()
{
if($this->hasAccess){
if($this->groups){
$msg = "";
$msg .= '<select name="group_id"><option value=""></option>';
foreach($this->groups as $group) {
$msg .= '<option value="' .
'' . urlencode($group['id']) .
'">' .
$group['name'] .
'</option>' .
'';
}
$msg .= '</select>';
return $msg;
}
else
return "No Groups";
}
else{
return $this->show_login();
}
}
function getGroupData(){
$raw = $this->facebook->api('/me/groups', 'GET');
$data = array();
if (null != $raw && array_key_exists('data', $raw))
return $raw['data'];
return null;
}
// check if current instance has access to facebook
function has_permissions() {
$user_id = #$this->facebook->getUser();
#print_r($user_id);
if($user_id == null) return false;
$permissions = $this->facebook->api("/me/permissions");
foreach($this->permissions() as $perm){
if( !array_key_exists($perm, $permissions['data'][0]) ) {
return false;
}
}
return true;
}
// permissins needed to post
function permissions(){
return array('manage_pages', 'user_groups');
}
}
$fb = new PostToFacebook();
$fb->initialise($config);
if(!$fb->has_permissions())
{
echo $fb->show_login();
}
else{
?>
<form method="post" action="test.php">
<textarea name='message'></textarea>
<?php echo $fb->toString(); ?>
<input type='submit'>
</form>
<?php
}
if(!empty($_POST)){
$response = $fb->postMessageToGroup($_POST['message'], $_POST['group_id']);
if($response['STATUS'] == 200)
print_r("<a href='" . $response['data']['link'] . "'>" . $response['data']['id'] ."</a>");
else
{
echo "ERROR!";
print_r($response);
}
}
?>

Categories