double0201 2015-05-20 21:07
浏览 56

如何通过URL登录symfony

I research on cookbook the chapter relative of security and the most near is the part How to Authenticate Users with API Keys. I'm not sure if is possible to login in synfony through URL. I try to develop a service that permit login and I want to use a URL like this:

mysite.com/login/user/password/token

Before to make the complete code I try to make a test and be sure thats works and I pass my var with value in the same code in controller:

$_username="user";
$_password="password";

$this->redirect($this->generateUrl('subscriber_login_check'));

if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
    $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} else {
    $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
    $session->remove(SecurityContext::AUTHENTICATION_ERROR);
}

When I try to do this on controller I have the follow error :

Unable to find the controller for path "/login_check/". Maybe you forgot to add the matching route in your routing configuration?

I don't know if I need to so something else in others files or this is not possible to do it.

Thank you

  • 写回答

1条回答 默认 最新

  • drqwbh2150 2015-05-21 20:42
    关注

    I can find a solution to implement my login with URL like this: mysite.com/user/password.

    This is the code:

    $path_info = $request->getPathInfo();
    $router_parts = explode("/", $path_info);
    $routerAux = $router_parts[1];
    $routerAux2 = $router_parts[2];
    if ($routerAux != ""){
        $_username=$routerAux;
        $user = $em->getRepository('myBundle:Entity')->findOneBy(array('field' => $_username));
        if($user){
            $token = new UsernamePasswordToken($user, $user->getPassword(), "public", $user->getRoles());
            if($token){
                if ($routerAux2  != ""){
                    $_password=$routerAux2;
                    $pass = $user->getPassword();
                    $pass1 =""; 
                    $factory = $this->get('security.encoder_factory');
                            $encoder = $factory->getEncoder($user);
                            $pass1 = $encoder->encodePassword($_password, $user->getSalt());
                    if($pass==$pass1){
                        $var= 1;
                            }
                        }
                    }
                }
            }     
        }
        return $this->render('Bundle:Pages:page.html.twig',array('var'=>$var));
    }
    

    Basically, the service is implemented by sending the username and password by URL, and initially locate the username in my database, then if the user exists got the password. Because the password is encrypted, proceeded to encrypt the value of the past password URL. Once encrypted value that a comparison between the two values is performed to return true if both are equal and false if they are different.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog