Skip to main content
2 of 8
edited tags; edited title
Yuseferi
  • 22.2k
  • 22
  • 118
  • 218

login user programmatically

I want to login user with ajax,I create custom login user route

tcdev.login:
  path: '/tclogin/{username}/{pass}'
  defaults:
    _controller: 'Drupal\tcdev\Controller\MYCenterController::login'
    _title: 'Login call back'
  requirements:
    _permission: 'access content'

and in controller

namespace  Drupal\tcdev\Controller;

use Drupal\Core\Controller\ControllerBase;

class MyCenterController extends ControllerBase{


    public function login($username,$pass){
        // do authentication process
        return new Response('Hi ' . $username);
    }
}

what is best solution for authentication user in controller?

Yuseferi
  • 22.2k
  • 22
  • 118
  • 218