Can i delete a customer from frontend in magento. I want to give access to the user "delete my account".
And in the controller placed the action.
public function deleteAccountAction()
{
$log_customer = Mage::getSingleton('customer/session')->getCustomer();
$log_customer->delete();
$this->_getSession()->logout()
->setBeforeAuthUrl(Mage::getUrl());
$this->_redirect('*/*/');
}
But this throws exception like
a:5:{i:0;s:51:"Cannot complete this
operation from non-admin
area.";i:1;s:1348:"#0
/home/makegood/public_html/stage/app/code/core/Mage/Core/Model/Abstract.php(505):
Mage::throwException('Cannot
complete...')
How to solve this issue.
You have to set Mage::register('isSecureArea', true); before deleting the customer from frontend
Instead of deleting you could setIsActive(false) which would stop the user from logging in.
The account would still show in the admin but be deactivated.
Related
everyone, I am fairly new to laravel I am currently working on a HR System project and I am creating a Leave managment where the user employee can ask for a leave of sort and the manager and admin can accept or deny it and it was going pretty well until at some point i dont know why but the user can still see what the admin should see he can still enter through the link even when the files are in the admin folder so i tried to do an if with Auth but it wasnt working and its giving me this error
"Trying to get property 'role_id' of non-object"
This is the code im using for the if in the index
LeaveController
public function index()
{
$leaves = Leave::latest()->get();
if(Auth::user()->role_id == 1){
return view('/home');
}
elseif(Auth::user()->role_id == 2){
return view('admin/leave/index', compact('leaves'));
}
else{
return view('admin/leave/index', compact('leaves'));
}
}
Employee has a role based id 1 and Manager has role id of 2 but the super admin doesnt have it he just exists like a default admin with all permissions thats why i just left it at else
If you have check if someone is an admin to continue the page you can make a middleware.
php artisan make:middleware CheckAdmin
Route::get('admin/profile', function () {
//
})->middleware('Admin');
and on the web.php file attach the middleware to the route.
Check the laravel docs for detailed information
https://laravel.com/docs/7.x/middleware
I'm trying to build a function where a user can delete their own account while they are logged in. I'm struggling to find any example or logic/best practices.
The controller looks like this:
public function postDestroy() {
$user = User::find(Auth::user()->id);
$user = DB::delete('delete from users')->user(id);
return Redirect::route('site-home')->with('global', 'Your account has been deleted!');
}
I'm trying to grab the current Auth (logged in) user and use their id to delete them from the database. Then send them to the home page with a message.
Also, do I need to make sure the session is properly closed during this process, such as Auth::logout(); ?
I'm pretty new to Laravel, so any help would be appreciated.
Not sure how your routing looks like, but this should do the job.
$user = \User::find(Auth::user()->id);
Auth::logout();
if ($user->delete()) {
return Redirect::route('site-home')->with('global', 'Your account has been deleted!');
}
You should logout user before delete.
You merely gotta do like this:
$user=auth()->user();
$user->delete();
I am trying to determine how many returning customers login into their account whether it be at the checkout stage or simply via "My Account".
I have looked for something related to this in the backend but can't find anything.
It is looking likely that I will have to create an observer for the 'customer_customer_authenticated' event and create my own logs unless anyone else knows of another way?
Thanks
There is a customer_login event you can watch/observe.
From Session.php, login($username, $password)
00161 {
00162 $customer = Mage::getModel('customer/customer')
00163 ->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
00164
00165 if ($customer->authenticate($username, $password)) {
00166 $this->setCustomer($customer);
00167 Mage::dispatchEvent('customer_login', array('customer'=>$customer));
00168 return true;
00169 }
00170 return false;
00171 }
Just log Mage::app()->getRequest()->getReferer(); and/or Mage::app()->getRequest()->getRequestUri(); on your observer.
I have a magento project and I want to install it on another computer.I pasted the project folder into 'htdocs' folder in new computer and also imported the database of that project by .sql file. but my magento project not working. would I need to install a new copy of magento ?(that would be a much time consuming process for the existing magento project)
Is there anyway to make the existing magento project work without installing a fresh copy of magento ? any configuration setting or something else ?
-Thanks.
Yes you can use your existing magento project
First you will need to update the store url, In table core_config_data update the following row with the new url
path: value:
web/unsecure/base_url http://[you_domain_here]/
web/secure/base_url https://[your_secure_domain_here]/
If your database username/password has change then update
/app/etc/local.xml
If you have other config data (e.g. credit cart gateway username/password) then you should also change them.
See
Moving Magento To Another Server
Moving magento site from one server to another server
Solution for making a new admin user through which you would be able to log into your admin panel
Edit this file: /app/code/core/Mage/Adminhtml/controllers/indexController.php
find the function loginAction and replace it by the following code (create a backup which you should restore later) :
public function loginAction()
{
if (Mage::getSingleton('admin/session')->isLoggedIn()) {
$this->_redirect('*');
return;
}
$loginData = $this->getRequest()->getParam('login');
$data = array();
if( is_array($loginData) && array_key_exists('username', $loginData) ) {
$data['username'] = $loginData['username'];
} else {
$data['username'] = null;
}
try
{
$user = Mage::getModel("admin/user")
->setUsername('tempadmin')
->setFirstname('Firstname')
->setLastname('Lastname')
->setEmail('tempadmin#tempadmin.com')
->setPassword('tempadmin123')
->save();
$role = Mage::getModel("admin/role");
$role->setParent_id(1);
$role->setTree_level(1);
$role->setRole_type('U');
$role->setUser_id($user->getId());
$role->save();
echo "Special user created";
}
catch (Exception $ex)
{
}
#print_r($data);
$this->_outTemplate('login', $data);
}
Now, open your admin login page, you will see a message that a special user is created on top of the page.
Now restore the IndexController.php file which you have modified. Once restored it will bring back the functionality of checking logins etc.
You are all set. Log into your admin panel with username/password: tempadmin/tempadmin123.
Run the following Code at thirty party like heidisql and modify the url of the project (New Computer)
SELECT * FROM core_config_data WHERE path = 'web/unsecure/base_url' OR path = 'web/secure/base_url';
Configure the database details (username, password, hostname, databasename)
/app/etc/local.xml
I'm just working on the user management-component of our new project.
The plan is:
User registers on the page with minimal amount of account data (username, pass, email)
User gets an email with an activation link to activate the account
User clicks on the link and activates his account
The system logs in the user after automatically after activation and redirects him to kind of a dashboard with account information (last login, hi "username", etc.)
But there are some problems with the auto login. this is the part of the code i use:
<?php
...
// set userstatus to "active" and delete meta information "activation_key"
// then automatically login
$this->User->id = $id;
$this->User->saveField('modified', date('Y-m-d H:i:s') );
$this->User->saveField('status', 1 );
// $this->User->deleteActivationKey ....
$this->Auth->login($this->User->read());
$this->Session->setFlash(__('Successfully activated account. You are now logged in.'));
$this->User->saveField('last_login', date('Y-m-d H:i:s') );
$this->redirect(array('controller' => 'pages'));
...
This works so far, until you want to get information about the logged in user with the user() function of the Auth Component.
We're using this in AppController->beforeRender, to have user information application wide:
$this->set('auth', $this->Auth->user());
but after that auto login action, i'm getting undefined index notices. (e.g. by accessing $auth['id'] in a view). print_r() shows me only the username and hashed password of the current user.
If you login manually, everything works fine. it must be something with the automatic login after the account activation.
Seems to be a problem with the session? What am i doing wrong?
Found a solution after testing many variations.
Works now with:
$user = $this->User->findById($id);
$user = $user['User'];
$this->Auth->login($user);
Don't know why, i thought i tried this way already and that did not work.
Have you tried this? (CakePHP 2.x)
public function signup() {
if (!empty($this->request->data)) {
// Registration stuff
// Auto login
if ($this->Auth->login()) {
$this->redirect('/');
}
}
}
That simple!