Facebook login with Codeigniter stopped working suddenly - facebook

I am using Facebook with Codeigniter and was working fine
but suddenly stopped working, is facebook changed anything
the facebook function
public function takofacebook($page = TRUE, $name = TRUE) {
if (isset($page) and (($page != TRUE) or ($page != 1)) and isset($name)) {
$data['page'] = $page;
$data['name'] = $name;
}
$this -> load -> library('fb');
if (!$this -> fb -> is_connected()) {
redirect($this -> fb -> login_url(current_url()));
}
$fb_user = $this -> fb -> client -> api('/me');
if (empty($fb_user)) {
$error = "FACEBOOK LOGIN FAILED - USER US EMPTY. FILE: " . __FILE__ . " LINE: " . __LINE__;
$this -> session -> set_flashdata('register_error', $error);
} else {
$this -> user -> set_facebook_id($fb_user['id']);
$user = $this -> user -> get_by_facebook();
if (!empty($user) && !empty($user -> id) && is_numeric($user -> id)) {
//TODO: Make things a bit more secure here
//Login & Redirect home
$this -> _login($user -> id, 'facebook');
$this -> load -> view('users/redirect_home2', $data);
return;
}
}
//Go to the registeration page
$this -> load -> view('users/redirect2', array('method' => 'facebook'));
}
/**
* Logs user in with facebook
*/
//tako facebook
public function zangafacebook() {
$this -> load -> library('fb');
if (!$this -> fb -> is_connected()) {
redirect($this -> fb -> login_url(current_url()));
}
$fb_user = $this -> fb -> client -> api('/me');
if (empty($fb_user)) {
$error = "FACEBOOK LOGIN FAILED - USER US EMPTY. FILE: " . __FILE__ . " LINE: " . __LINE__;
$this -> session -> set_flashdata('register_error', $error);
} else {
$this -> user -> set_facebook_id($fb_user['id']);
$user = $this -> user -> get_by_facebook();
if (!empty($user) && !empty($user -> id) && is_numeric($user -> id)) {
//TODO: Make things a bit more secure here
//Login & Redirect home
$this -> _login($user -> id, 'facebook');
$this -> load -> view('users/redirect_home3');
return;
}
}
//Go to the registeration page
$this -> load -> view('users/redirect3', array('method' => 'facebook'));
}

I tested the official php sdk from Facebook that is on my CodeIgniter site and it works fine.
Is $fb_user empty? Where is the error? Are you using the official PHP SDK for Facebook? There are a lot of variables to figure out what is going wrong here.
Like ifaour suggests, use the official php sdk here if you are not already: https://github.com/facebook/facebook-php-sdk/tree/master/src
Drop the files in the library directory and call it normally
$this -> load -> library('facebook');
Then you can get the facebook data like this:
$fb_user = $this -> facebook -> api('/me');
again I am not sure where your error is so are you missing a parameter here?
$user = $this -> user -> get_by_facebook($fb_user['id']);
This is all I am doing on my site and it is working just fine. This also has the benifit that if Facebook does change anything you just need to download the new SDK and your code should remain unchanged.

Related

Error Use of exit language construct is discouraged

Use of exit language construct is discouraged.
if ($attribute_name == $customerGroup) {
if ($dropdown_field > $Quantity) {
$this->messageManager->addError($this->helper->getGeneralConfig('minimum_alertmsg') . $dropdown_field);
$cartUrl = $this->_url->getUrl('checkout/cart');
$this->_responseFactory->create()->setRedirect($cartUrl)->sendResponse();
Exit();
}
}
need to redirect in check out page without using exit(); and die();
i Got The Solution
Using Javascript We Can Remove Error "Use of exit language construct is discouraged"
if ($attribute_name == $customerGroup) {
if ($dropdown_field > $Quantity) {
$this -> messageManager -> addError($this -> helper -> getGeneralConfig('minimum_alertmsg').$dropdown_field);
$cartUrl = $this -> _url -> getUrl('checkout/cart');
?
>
<
script type = "text/javascript" >
window.location.href = "<?= $cartUrl; ?> "; <
/script>
<
? php
}
}

I can't access my site admin dashboard via wp-admin

You know how all these websites send out links to their new users for them to verify their Email address? I'm setup user verification process through email address , I will send email verification link to user email onclick on link user will be verified.
but the problem is that i am setting up usermeta field when user login the function will check user if it verified or not if verified it will be login otherwise show error when i was login to admin it will not access me to admin dashboard.
add_filter('wp_authenticate_user', 'check_user_activation_status', 10, 2);
function check_user_activation_status($user) {
if( ! $user->has_cap('administrator') ) {
if ( get_user_meta($user->ID ,'wp_user_level',true) != 10 ) {
if( get_user_meta($user->ID, 'activated', true) == 'true' ) {
return $user;
}
} else {
return $user;
}
}
return new WP_Error('Account Not Active...');
}
and also it will not showing error text
login page look like after login failed
sorry for bad english...
This hook passes two parameters, $user and $password (plaintext). In order to generate an error on login, you will need to return a new WP_Error() object.
https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_authenticate_user
/**
* Check User Status.
*
* #param $user WP_User Object
*/
function check_status( WP_User $user ) {
$status = get_user_meta( $user->ID, 'user_status' );
if ( 1 !== (int) $status ) {
$message = esc_html__( 'User not verified.', 'text-domain');
return new WP_Error( 'user_not_verified', $message );
}
return $user;
}
add_filter( 'wp_authenticate_user', 'check_status' );

GET url parameters Codeigniter

There is one view, and one controller, it is necessary, with the use of the get parameter, to change the path by the link. So in the end it turned out like this:
Upcoming -> http://mywebsite.com/tournaments?type=upcoming
Finished -> http://mywebsite.com/tournaments?type=finished
Here is the controller which will process your GET variable
Controller
<?php
class Demo_controller extends CI_Controller
{
public function demo($id)
{
echo $id; //the id which you will get in URL string
}
}
?>
View File where you will pass the Variable
<?php
$id = "1";//dyanmic id which will be pased with the form
echo form_open('demo/demos-function'.$id);
//in between your code
echo form_close
?>
Routes
Inside routes.php
$route['demo/demos-function/(:any)] = Demo_controller/demo/$1
No need to change the $1 it will explain the routes that it is having URL paramater.
So Ultimately Your link will be
https://localhost/demo/demos-function/1
https://localhost/demo/demos-function/2
In Codeigniter Url like this :
Upcoming -> http://mywebsite.com/controller/method/upcoming
Finished -> http://mywebsite.com/controller/method/finished
public function method_name()
{
$type = $this->uri->segment(3); // third level value of URL - Segment(1) is controller and followed by method and query string
if($type == 'upcoming')
{
echo $type;
$this->load->view('upcoming');
}
else
{
echo $type;
$this->load->view('finished');
}
}

Code coverage for $state changing service

I can't manage to provide code coverage for this $state changing service:
($state) ->
#$inject = ["$state"]
-> $state.go "home.about"
This is my test which fails the last two expects:
mock = require "mock"
describe "goHomeService", ->
goHomeService = $state = undefined
beforeEach mock.module "main"
beforeEach mock.inject (_goHomeService_, _$state_) ->
goHomeService = _goHomeService_
$state = _$state_
it "should chage $state to 'home.about'", ->
spy = jasmine.createSpy $state, "go"
expect($state.current.name).not.toEqual "home.about"
expect($state.go).toEqual jasmine.any Function
goHomeService()
expect($state.current.name).toEqual "home.about"
expect(spy).toHaveBeenCalledWith "home.about"

Session won't be created in Mozilla Firefox

I am working on a purchase system in my assignment and trying to solve the problem by using a session to store data in the process.
Although I'm experiencing a problem in Mozilla Firefox, which cannot for some reason work with the session I have created. There's most likely no doubt that I must have made some kind of mistake.
The process is as follows:
User fills form -> Clicks submit -> [Validation process] -> User reviews confirm page
Here is the relevant code from the controller:
public function indexAction() {
$this->gatewayForm = new Payment_Form_Gateway;
$save = $this->validate();
$this->view->gatewayForm = $save['form'];
$this->view->alert = $save['alert'];
}
public function validate() {
# get form
$form = $this->gatewayForm;
if ($this->_request->isPost()) {
# get params
$data = $this->_request->getPost();
# check validate form
if ($form->isValid($data)) {
$session = new Zend_Session_Namespace('formData'); // name space creation
$session->data = $data;
$this->_helper->redirector('confirm', 'gateway', 'payment');
} else {
$alert = array('Pay failed');
}
$form->populate($data);
}
return array('form' => $form, 'alert' => empty($alert) ? null : $alert );
}
public function confirmAction() {
$this->_helper->viewRenderer->setNoRender(true); // disable std. view
$session = new Zend_Session_Namespace('formData');
$data = $session->data;
if(isset($data)) {
$this->_helper->viewRenderer->setNoRender(false);
} else {
$this->_helper->redirector('index', 'gateway', 'payment');
}
}
Things go wrong in the confirmAction in Firefox, the session namespace seems to be empty? Although this does not occur in Safari, Chrome, IE etc.
Thanks in advance.
I reinstalled Firefox and removed config and cache files which did the magic. Problems solved!