i am beginner to code igniter. i am creating web service for android application that will have thousands of users. In admin panel i want to know which users are currently active. is it possible using sessions?
$newdata = array(
'phone' => $phone,
'pass' => $pass,
'logged_in' => TRUE
);
$this->session->set_userdata($newdata);
storing user data in session like this but don't know how to check later
To track online users you can add one flag(field) like "is_loggedin".
When any user login update this value to 1
When any user logout date this flag to 0
So you can check any time in database that user's with flag 1 are online.
Related
I am working on a laravel app and I would like to send meeting/calendar invites that go directly to the users calendar. For example, how calendly does it. The invite should automatically appear on the recipients calendars. Currently I have been able to attach them to the email, but not send directly. This may just be something I missed in the Laravel Mail docs and need to send this exact file instead of an email, but not as an attachment. I cannot seem to figure out how to do this either.
I currently looked around stackoverflow and did not find a clean implementation of this for laravel despite it being a pretty common feature. I have tried Spatie, Eluceo, and INSAN packages on github and did not have much luck. The code below works for downloading a .ics file.
I would appreciate any helpful comments! I have spent a long time looking into this already with little progress.
use INSAN\ICS;
$properities = [
'uid' => uniqid(),
'sequence' => 0,
'description' => 'Event Invitation via email.',
'dtstart' => date('2021-05-01 09:00'),
'dtend' => date('2021-05-01 10:00'),
'summary' => 'This is an event invitation sent through email.',
'location' => 'VR Punjab, S.A.S Nagar, Chandigarh',
'url' => 'www.example.com',
];
$ics_file = new ICS($properities);
return $ics_file->toString();
I'm trying to use sessions (i need to save sessions in mySql db) in my application on laravel.
So when i log in (use standart LoginController. It was make with php artisan as my sessions table in db) my session save in db as i need but when i use
$value = $request->session()->all();
in my test controller i get data i don't understand
It is in my db
it is what i get when use session()->all();
and if i want to save it (for test)
$request->session()->put(['user_id'=>889900])
nothing happens
so.
What the data when i use session()->all();?
How can i save data what i need in db and when i need (i mean controllers)?
session.php
'driver' => env('SESSION_DRIVER', 'database'),
'connection' => env('SESSION_CONNECTION', null),
'table' => 'sessions',
.env
SESSION_CONNECTION=mysql
SESSION_DRIVER=database
unfortunately i can't find something use in documentation to my question.
Sorry to my english and thank you in advance
The payload in your db you need to decode and unserialize it so that you can have the same result.
For example:
return Session::all();
and
$data = DB::table('sessions')->get();
return unserialize(base64_decode($data[0]->payload));
For Those two you should have the same result.
For pushing key and value, session(['foo' => 'bar']); should work.
Hopefully, I have answered your question.
I need on my Laravel set-up (which uses the standard Auth models/controller) to allow a logged-in user to create another user account on the site. As a shot in the dark, on my "add user" page, I did an include of the form from auth.register, and it showed up fine on the page (great!), but when I filled out the form and submitted it, it just reloaded the page, with no errors and the new user was not added to the database.
The things I'd need different than the standard auth.register are
1) There will be a column in the users table pairing the two users.
2) I want the verification email to be different than if they signed up on their own.
3) I was also thinking to not let the creating user choose a password, but have the new user reset their password via the initial email.
Is there any Laravel way of doing all this or will I have to write it myself?
1) There will be a column in the users table pairing the two users.
Take a look in your RegisterController and check out the use RegisterUsers trait included. Whatever you copy from this trait and move it to RegisterController, it gets overwritten by your logic rather than trait logic.
For the pairing, you can utilise create() method. A really pseudo way:
protected function create(array $data) {
$pair = // find a random user
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'pair_id' => $pair->id
]);
}
2) I want the verification email to be different than if they signed up on their own.
For this, I am not sure where you trigger it already, but the email event lives in EventServiceProvider by default:
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
]
];
Change it your custom email and you should be good.
3) I was also thinking to not let the creating user choose a password, but have the new user reset their password via the initial email.
Again, in create() method, you can just assign a random password, and with your email, redirect them to the ResetPassword actions somehow. This needs some time to figure out for me now but see reset-password routes (with php artisan route:list), so what it accepts and in your custom email, place the button with necessary link.
Make sure you don't login the user right after registering in that case.
So, bottomline - the auth default logics live in their traits, and if you want to overwrite some, just copy/paste the method to your controller and tweak it as you wish.
I've created a couple of pages they are users, groups and permissions.
I would like the admin to be able to create groups and set what those groups can do via the permissions page.
So on the permissions page I would have a list of things a user could do e.g.: add content, delete content.
And if I check the add content box then the group can only add content and not delete content.
The problem I'm having is that I don't know where to go to look for information on how to go about it. I've already got my database set up and I'm thinking maybe sessions and routes is the way to go, but I'm not sure.
Frameworks is the way to go for something this complex. I'm working on a very similar project for my work (a dashboard to do different things based on User Role/Permissions) and I found it incredibly difficult to manage without the use of a framework. I would highly recommend Cartalyst/Sentry for this. It turns complex database operations like checking permissions, update permissions, creating groups etc into simple one. Here is a link to the manual:
Cartalyst/Sentry
It has a database backend already created (and modifiable) for you, so you simply follow the installation instructions and go over the documentation to get a better understanding. In your example, it would be as simple as creating a group and it's permissions:
// Define permissions (1 is allowed, 0 is not allowed)
$permissions = array('content.create' => 1, 'content.delete' => 1, etc etc...));
$group = Sentry::createGroup(array('name' => 'Admin', 'permissions' => $permissions));
Creating a user and adding them to the group:
$user = Sentry::createUser(array('email' => 'test#test.com', 'first_name' => ..., etc));
$group = Sentry::findGroupByName('Admin');
$user->addGroup($group);
And then checking their permissions during routing:
$user = Sentry::check(); // Aka get the current user.
if($user->hasAccess('content.create'){
// Continue
} else {
// Redirect to error page, etc
}
Now that's a brief overview of the system, and I assume you know how to use controllers and routes, but play around with it and I'm sure you'll come to see how powerful this Framework is when working with Laravel.
Hope that helps!
Then checking whether or not a user
I had a custom utility task that allowed users to choose an image to accompany the gift card notice that is sent to the recipient when a gift card is purchased at the magento run shop. In the template, there is an assortment of variables available so you can customize the email that is sent. However, in order to add the correct image, I need to have access to the gift card sku number since my method for handling this was to simply create many gift cards and apply separate images for each one, then use javascript to swap the sku numbers when the user clicks the images. Simple enough.
In the app/code/core/Enterprise/GiftCard/Model/Observer.php file, the variables are set:
$templateData = array(
'name' => $item->getProductOptionByCode('giftcard_recipient_name'),
'email' => $item->getProductOptionByCode('giftcard_recipient_email'),
'sender_name_with_email' => $sender,
'sender_name' => $senderName,
'gift_message' => $item->getProductOptionByCode('giftcard_message'),
'giftcards' => $codeList->toHtml(),
'balance' => $balance,
'is_multiple_codes' => 1 < $goodCodes,
'store' => $order->getStore(),
'store_name' => $order->getStore()->getName(), // #deprecated after 1.4.0.0-beta1
'is_redeemable' => $isRedeemable,
);
So I could add the product sku to this array and it would be available in the template system. Problem is, I don't know where to trace this back to even know how to get the Sku. I assume it is somehow available in the $item var, but magento has no documentation on this particular case and I can't guess since there is no method for testing. The email script is activated when the card is purchased so I can't just click a "Send test" button to see what comes out in the email that is sent to the user. The preview button dismisses variables.
Anyone happen to know about this? Possibly something like $item->getSku()
Any input helps.
Thanks
That snippet is from the method Enterprise_GiftCard_Model_Observer::generateGiftCardAccounts() which is registered as a handler for sales_order_save_after event. That event is passed the same 'order' object as the "new order placed" emails have. You can experiment by altering that email template and triggering a new email by resending from the order page in admin.
$item->getSku() is almost certainly right.