I want to login user programmatically log in a user with a custom controller. I want to pass my data with $_POST$_POST
to the route (you suppose II pass data from a mobile application) , then I want; if userusername and pass ispassword are correct return true and else, the method/function should return falseTRUE
.
My Router The route is the following one.
tcdev.login:
path: '/tclogin'
defaults:
_controller: 'Drupal\tcdev\Controller\MYCenterController::login'
_title: 'Login call back'
requirements:
_permission: 'access content'
my Controller The code for the controller is the following one.
namespace Drupal\tcdev\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MyController extends ControllerBase {
/**
* \Drupal\user\UserAuth definition.
*
* @var \Drupal\user\UserAuth
*/
protected $userAuth;
/**
* {@inheritdoc}
*/
public function __construct(UserAuth $user_auth) {
$this_>userAuth$this->userAuth = $user_auth;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container_>get$container->get('user.auth')
);
}
}
public function login() {
$uid = $this_>userAuth_>authenticate($$this-POST['user']>userAuth->authenticate($_POST['user'], $_POST['pass']);
$acc = User::load($uid);
//return new Response('Hi ' . $uid);
}
}
but it returnIt returns me TypeError: Argument 1 passed to Drupal\tcdev\Controller\MyController::__construct() must be an instance of Drupal\tcdev\Controller\UserAuth, instance of Drupal\user\UserAuth given, called in /Users/yms/Sites/devdesktop/gttc/modules/tcdev/src/Controller/MyController.php on line 32 in Drupal\tcdev\Controller\MyController_>__construct() (line 23 of modules/tcdev/src/Controller/MyController.php
the following error:
TypeError: Argument 1 passed to
Drupal\tcdev\Controller\MyController::__construct()
must be an instance ofDrupal\tcdev\Controller\UserAuth
, instance ofDrupal\user\UserAuth
given, called in /Users/yms/Sites/devdesktop/gttc/modules/tcdev/src/Controller/MyController.php on line 32 inDrupal\tcdev\Controller\MyController::__construct()
(line 23 of modules/tcdev/src/Controller/MyController.php)
whereWhere is my mistake?