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 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起