<?php
namespace App\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Pimcore\Model\User;
class DefaultController extends FrontendController
{
public function defaultAction()
{
// $user = new User();//'admin';
// $userName = 'admin';
// $password = 'admin';
// $password = $passwordHasher->hashPassword($user, $password);
// $dbConnection = \Pimcore\Db::get();
// $isValidate = $dbConnection->fetchOne(" SELECT * FROM users WHERE name = '$userName' AND password = '$password'");
// echo '<pre>'; print_r($isValidate); die;
// echo pimcore_csrf.getCsrfToken(); die;
$user = \Pimcore\Tool\Session::getReadonly()->get("user");
if(!$user) {
return $this->redirect('admin/login');
}
// $userAuthn = $this->checkLoginUserOrNot();
// if($userAuthn == false) {
// return $this->redirect('admin/login');
// }
// echo $userAuthn; die;
return $this->render('default/default.html.twig');
}
public function checkCustomerLogin()
{
$userName = 'admin';//'user@itc.com';
$password = 'admin';//'itc@123';
$user = User::getByName($userName);
if($user) {
$validateUser = \Pimcore\Tool\Authentication::authenticatePlaintext($userName,$password);
if($validateUser) {
echo '<pre>'; print_r($validateUser);
echo 'Login successfull';
} else {
echo 'Wrong password';
}
} else {
echo 'User not found';
}
die;
}
public function checkLoginUserOrNot()
{
// echo 'kk'; die;
$userAuthn = false;
$user = \Pimcore\Tool\Session::getReadonly()->get("user");
if($user) {
$userAuthn = true;
}
}
public function homeAction()
{
$user = \Pimcore\Tool\Session::getReadonly()->get("user");
if(!$user) {
return $this->redirect('admin/login');
}
return $this->render('default/home.html.twig');
}
}