Is there any way to check if the admin is logged in at front-end in Opencart? I would like to show a notice bar with content "Admin Logged In" when I open my store.
To be precise, in the controller of my module, i would like to add:
$data['admin_logged'] = some_function;
and when I echo it in my .tpl to get 1 if admin is logged in or 0 if not.
Actually i got it done by:
// Check if admin is logged in - frontend
$this->user = new User($this->registry);
$data['admin_logged']=($this->user->isLogged())
Now you can use if($admin_logged) /* do stuff here */
Thank you anyway
Yes, you can check it, using the User class:
$data['admin_logged'] = $this->user->isLogged() ? 1 : 0;
Related
Hi I have written an app using storyboards and decided to look at writing it in SwiftUI. So far so good. When it comes to showing (or not showing the login page) based on the users logged in status what is the best way to achieve this? Most examples just show the login page but never do checks if the user is already logged in.
For simplicity, you can use UserDefaults to check if the user already logged in or not. Or you can use Core Data to keep your record.
This is an example code using UserDefaults:
If the user has logged in, you can declare this when user has
entered the login data and enter
let defaults = UserDefaults.standard
defaults.setValue(true, forKey: "skipTutorialPages")
defaults.synchronize()
In the AppDelegate, add this to didFinishLaunchingWithOptions
let defaults = UserDefaults.standard
let skipTutorialPages = defaults.bool(forKey: "skipLoginPages")
if skipLoginPages
{
// Skip to your login pages
}
I am working with a Delayed Job that, after its completion, sends an email to the admin user that requested it. So, to do this, I need to know who is the admin user that launched it inside the Spree::Order model.
I've tried with try_spree_current_user and spree_current_user but they don't work returning:
NameError (undefined local variable or method `try_spree_current_user' for #<Spree::Order:0x007f93811d7240>):
app/models/spree/order_decorator.rb:30:in `after_cancel'
app/controllers/spree/admin/orders_controller_decorator.rb:4:in `cancel'
Some how you need to make sure that an admin can launch the order:
# Is this user an admin
if spree_current_user.admin?
# Do some delayed job
# send the email
# because spree_current_user.id is the one that sends it
else
flash[:error] = "You need to be an admin to do this."
redirect_back_or_default(spree.root_path)
end
The above should do what you want to do. You need to test if the current user is an admin then do what he/she needs to do.
I'm sure you meant the OrdersController? Not model.
Checkout page.
Not registered user.
I need to put first/last user name on custom template (this is custom payment tpl of some small bank).
I now, how do it for registered users, it is easy:
$this->data['firstname'] = $this->customer->getFirstName();
But how to do it for not registerd user?
I can't put first/last name.
Presumably your template will only be displayed after they have placed their order but the order is still in the session?
If this is the case, you can get their details from the payment details (or shipping details depending on which one you want) in the session cookie.
So it would be something like:
$this->data['firstname'] = $this->session->data['guest']['payment']['firstname'];
This is true too:
echo ($this->data['firstname'] = $this->session->data['guest']['firstname']);
echo ($this->data['lastname'] = $this->session->data['guest']['lastname']);
echo ($this->data['email'] = $this->session->data['guest']['email']);
echo ($this->data['telephone'] = $this->session->data['guest']['telephone']);
How can I check in sitecore that the current user is an administrator?
something like:
if(User.Current.Name == "extranet\Admin")
// then do some thing ??
Sitecore.Security.Accounts.User class has built in property IsAdministrator:
Sitecore.Context.User.IsAdministrator
You can actually just call Sitecore.Context.IsAdministrator
This should do what you wanted:
Sitecore.Context.User.IsInRole("extranet\admin")
You can try this code :
var result = Sitecore.Context.User.IsAdministrator;
If admin is logged in result is true, otherwise result is false.
A remark \ is a escape in c# use "extranet\\Admin" and the CMS admin is sitecore\admin
I assum you need to know your extranet admin. it's a good idea to do role-based, there can be multiple admin's (not sure if the IsAdministrator property is good working for a extranet)
Sitecore.Context.User.IsInRole("extranet\\your extranet admin rol");
If you do not have a Extranet admin rol and don't want it, then you can use what you already have if (Sitecore.Context.User.Name == "extranet\\Admin")
Im new to Pimcore and I'm trying to use Zend Auth with pimcore objects. I assume this is a wise approach and it seems more or less logical to me. I've done the initial setup of the object within pimcore itself. Now I'm trying to work out how to connect it to zend auth, that is, for example when I extend zend auth and have my own login function, how do i check if the login is valid in my object?
Does someone have a guide that I could use on this perhaps? otherwise if someone could point me in the right direction that would be great
Jason
You can follow this guide: http://www.pimcore.org/forum/discussion/419/zend_auth_adapter-for-pimcore-objects , it worked well for me.
UPDATE: The link above has been taken away, so laying out the full answer here:
First, you need to put ObjectAdapter.php in website/lib/Website/Auth/ObjectAdapter.php .
Then, this is how you login your user (use as you prefer, for example in your controller init function):
$authAdapter = new Website_Auth_ObjectAdapter('Object_Users', 'o_key', 'password', '/users/');
// The parameters are 1. object you keep your users in, 2. the field that contains their username (I use o_key which is the name of the object itself, to keep unique usernames without fuzz), and 3. the password field in the user object.
// Setup auth adapter
$authAdapter->setIdentity($username)->setCredential($password);
$auth = Zend_Auth::getInstance();
// Authenticate
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
// Login successful
} else {
// Login failed
}
To check for a login-session, use:
$this->auth = Zend_Auth::getInstance();
if ($this->auth->hasIdentity()) {
// We have a login session (user is logged in)
$userObject = $this->auth->getIdentity();
}
To kill a session:
Zend_Auth::getInstance()->clearIdentity();