Laravel user sessions - session

How do I distinguish between a session which stores data about a logged-in user, and a session which doesn't have any data about a logged-in user (basically a session which belongs to a logged-out viewer of the page)?

You can check whether a user is logged in via Auth::check
See http://laravel.com/docs/security#authenticating-users
Update
Here's the output of Session::all(). The first one is of a unauthenticated user:
Array (
[flash] => Array (
[old] => Array (
)
[new] => Array (
)
)
[_token] => sqwf2m9vxjePpq0jYWw4Vs16nhXoFBGH4PT14xpm
[language] => de
)
And a authenticated user:
Array (
[flash] => Array (
[old] => Array (
)
[new] => Array (
)
)
[_token] => sqwf2m9vxjePpq0jYWw4Vs16nhXoFBGH4PT14xpm
[language] => de
[login_82e5d2c56bdd0811318f0cf078b78bfc] => 1
)
A look into the source tells us what's going on:
public function login(UserInterface $user, $remember = false)
So there's a way of distinguishing a logged in user from a user "just passing by", of course..

Related

How do i know notification send to firebase or not

i want to send notification to specific android device with laravel-firebase . currently i am following this "brozot/laravel-fcm" so when Sending a Downstream Message to a Device , how do i know notification is send or not . when i test it in my postman it returns
LaravelFCM\Response\DownstreamResponse Object
(
[numberTokensSuccess:protected] => 0
[numberTokensFailure:protected] => 1
[numberTokenModify:protected] => 0
[messageId:protected] =>
[tokensToDelete:protected] => Array
(
[0] => .....
)
[tokensToModify:protected] => Array
(
)
[tokensToRetry:protected] => Array
(
)
[tokensWithError:protected] => Array
(
)
[hasMissingToken:protected] =>
[tokens:LaravelFCM\Response\DownstreamResponse:private] => Array
(
[0] => .....
)
[logEnabled:protected] =>
)
You can see in the response how many messages succeeded or failed. From your own output above:
[numberTokensSuccess:protected] => 0
[numberTokensFailure:protected] => 1
It looks like you tried to send a message to one device, and it failed.

Google Drive API get files in specific folder in Laravel

i am using the following code to get files from folder id. But I am not getting the files id instead empty array returning.
putenv('GOOGLE_APPLICATION_CREDENTIALS=C:\Users\new\Downloads\zonefunnel1.json');
$client = new Google_Client();
$client->addScope(Google_Service_Drive::DRIVE);
$client->useApplicationDefaultCredentials();
$service = new Google_Service_Drive($client);
$res=$service->files->listFiles();
//print_r($res);
$folderId="0B_bZZilaXPR4WkNvdFpMZmdneEU";
$optParams = array(
'pageSize' => 10,
'fields' => "nextPageToken, files(contentHints/thumbnail,fileExtension,iconLink,id,name,size,thumbnailLink,webContentLink,webViewLink,mimeType,parents)",
'q' => "'".$folderId."' in parents"
);
$results = $service->files->listFiles($optParams);
print_r($results);die();
I am getting the following,
Google_Service_Drive_FileList Object ( [collection_key:protected] => files [filesType:protected] => Google_Service_Drive_DriveFile [filesDataType:protected] => array [incompleteSearch] => [kind] => [nextPageToken] => [internal_gapi_mappings:protected] => Array ( ) [modelData:protected] => Array ( ) [processed:protected] => Array ( ) [files] => Array ( ) )
Please help me I have spent one week time for this.But not able to sort it out.
Regards,
Rekha
$files_list = $service->files->listFiles(array())->getFiles($optParams);

Square API - Object Update for Multiple Locations

I'm trying to update objects using the endpoint BatchRetrieveCatalogObjects (POST /v2/catalog/batch-upsert).
When I post the request, I get the error
[type] => bad_request
[message] => Multi-location support is unavailable for this endpoint. Parameter `merchant_id` must correspond to a single-location account, not a business account
How can I update objects if there are multiple locations and if items have location overrides?
Is there another endpoint that I can use?
UpsertCatalogObject (POST /v2/catalog/object) does not work either. Same error.
Below is a sample request payload:
Array
(
[idempotency_key] => 1122334455667788
[batches] => Array
(
[type] => ITEM
[id] => 5BLFIPNYBTDD5ARZYQU4K7SV
[item_data] => Array
(
[name] => Honey Mead
[description] => Mead is an adult beverage brewed exclusively with honey.
[category_id] => OIMGQF7DCO7W6SEXEMKGIJK5
)
[variations] => Array
(
[type] => ITEM_VARIATION
[id] => BEQZ6FXAJACGW55RRZBMXDEI
[item_variation_data] => Array
(
[item_id] => 5BLFIPNYBTDD5ARZYQU4K7SV
[name] => Case (24 bottles)
[pricing_type] => FIXED_PRICING
[ordinal] => 4
[price_money] => Array
(
[amount] => 11900
)
[location_overrides] => Array
(
[0] => Array
(
[location_id] => 81J6E4K21KGC9
[price_money] => Array
(
[amount] => 11900
)
[pricing_type] => FIXED_PRICING
[track_inventory] => 1
[inventory_alert_type] => LOW_QUANTITY
[inventory_alert_threshold] => 15
)
)
)
)
)
)
Additional Notes for Clarification:
I'm trying to edit the price at either the variation or location_overrides level. I get the error for any call to the endpoint. I think the Square API developers don't allow any calls to the endpoint for any multi-unit locations. I also cannot delete locations either on the website or API. They only allow you to hide locations, which I did. But the error still persists.
I tried the v1 endpoint and get strange results. V1 & V2 use different variation_id. So if I pass a v2 variation_id to the v1 endpoint, it creates a new variation rather than updating it. The new variation then displays a new field called catalog_v1_id. Then when I try to delete the variation on the website, it disappears from the website view but still exists as an active item when I call the v2 list variation endpoint. I'm thinking this API has a whole host of bugs and is not ready for prime time.

Yammer: get usernames with messages

I was wondering how I could get the usernames, etc. from messages using the API. Calling the GET messages API gives me all the info I need from the message, but I only get the userID. Because of API request limits, I can't afford to do another API request to know for each messages all the needed userinfo.
Am I missing something, or is this simply not possible?
In fact, check the "references" part of the response and you will find the whole details concerning your user.
I dont see where that is? This is my API response from yammer (for one message)
Array
(
[0] => stdClass Object
(
[id] => 544689850
[sender_id] => 1507082247
[replied_to_id] => 544673530
[created_at] => 2015/06/04 13:03:09 +0000
[network_id] => 355014
[message_type] => update
[sender_type] => user
[url] => https://www.yammer.com/api/v1/messages/544689850
[web_url] => https://www.yammer.com/b-rail.be/messages/544689850
[group_id] => 5741341
[body] => stdClass Object
(
[parsed] => Signed and Approved!
[plain] => Signed and Approved!
[rich] => Signed and Approved!
)
[thread_id] => 544673530
[client_type] => Web
[client_url] => https://www.yammer.com/
[system_message] =>
[direct_message] =>
[chat_client_sequence] =>
[language] => en
[notified_user_ids] => Array
(
)
[privacy] => private
[attachments] => Array
(
)
[liked_by] => stdClass Object
(
[count] => 0
[names] => Array
(
)
)
[content_excerpt] => Signed and Approved!
[group_created_id] => 5741341
)

Codeigniter echo session Multidimensional Array variable

Okay im using codeigniter and i got a session where i want to echo [user_id], i can see its an "Multidimensional Array", but i cant seem to get it right...
This is the print_r from all session userdata:
Array (
[session_id] => b7e721332248
[ip_address] => ::1
[user_agent] => Mozilla/5.0
[last_activity] => 1409104940
[user_data] => [name] => 2 [uniq] => 2
[flexi_auth] => Array ( [user_identifier] => mail.com [user_id] => 2 [admin] => 1
[group] => Array ( [3] => Master Admin )
[privileges] => Array ( )
[logged_in_via_password] => 1
[login_session_token] => 11017021313jhbjh1h2j3b213mab913269d95 ) )
if i type:
print_r($this->session->all_userdata()); // i will get all
echo $this->session->userdata('uniq'); //returns 2
echo $this->session->userdata('user_id'); //returns nothing(THIS IS THE PROBLEM)
Ive tried something like this:
$this->session->userdata(1,1); //1,1 would be array 2 and number 2 which would be user_id
Is it because i can only print out if I loop through them somehow?
You're trying to call the data directly, if you're want to access user_data or flexi_auth you need to assign the data to a variable then target it since they're arrays.
$session_data = $this->session->all_userdata();
echo $session_data['user_data']['uniq']; // 2
$user_data = $this->session->userdata('user_data');
echo $user_data['uniq']; /// 2
$flexi_auth = $this->session->userdata('flexi_auth');
echo $flexi_auth['user_id']; /// 2
If you're trying to target a string directly
echo $this->session->userdata('last_activity');
You can simply access user name stored in session like this
echo $this->session->userdata['user_data']['name'];
Be sure you have some userdata in session or use like this to avoid any errors
echo #$this->session->userdata['user_data']['name'];
adding # does not generate any errors. hope you got the answer you were looking for.

Resources