密码更新后用户登录不起作用

时间:2019-02-14 08:46:29

标签: symfony symfony-3.1

我正在尝试在Symphony 3.1应用程序中创建一个忘记密码的功能。

我有一个发送带有URL的电子邮件的表单,用于重置密码和安全令牌。 然后,您进入包含密码输入的简单表单。

在提交时,我用用户提交的密码更新了用户密码,但是当我尝试登录时,它说凭据是错误的。

我可以看到密码正在数据库中更新,但是我不明白为什么我尝试登录时密码不起作用。

这是更新密码的代码:

def STAcondition (row):
   if row['e'] > A :
      return 0
   if row['e'] < A :
      return 1
   return 'Other'

df['f'] =  df.apply (lambda row: STAcondition (row),axis=1)

我的security.yaml文件中设置了一个编码器:

var res =  {"matchObject":"{\"data\":[{\"id\":\"jack1\",\"firstname\":\"jack\",\"lastname\":\"hudson\",\"dob\":\"1990-01-01T00:00:00.000Z\",\"email\":\"jack1@yahoo.com\",\"phone\":null,\"orgid\":\"001\"},{\"id\":\"jack2\",\"firstname\":\"Jack\",\"lastname\":\"Clinton\",\"dob\":\"1991-01-01T00:00:00.000Z\",\"email\":\"jack.clinton@yahoo.com\",\"phone\":\"+16464922600\",\"orgid\":\"002\"}]}"};
var parsedObj = JSON.parse(res.matchObject);

let op = parsedObj.data.reduce((out,{id,email,phone})=>{
  if(email){
    out.push({matchedRes:email,id,type:`email`})
  } 
  if(phone){
  out.push({matchesRes:phone,id,type:`phone`})
  }
  return out
},[])

console.log(op)

security.yaml中的防火墙:

// retrieve the user
 $user = $this->getDoctrine()->getRepository("AppBundle:User")->findOneBy(array('username' => "admin", "token" => $token));

//the password posted from the form
$password = $request->get('new_password');

$em      = $this->getDoctrine()->getManager();

//encoding it according to the symfony doc
//see https://symfony.com/doc/3.1/security/password_encoding.html
$encoder = $this->container->get('security.password_encoder');
$encoded = $encoder->encodePassword($user, $password);

//updating the password in the database
$user->setPassword($encoded);
$em->persist($user);
$em->flush();

User.php类中的密码属性:

encoders:
    Symfony\Component\Security\Core\User\User:
        algorithm: bcrypt
    AppBundle\Entity\User:
        algorithm: bcrypt

config / doctrine / User.orm.xml中的密码字段:

firewalls:
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        anonymous: ~
        form_login:
            login_path: /admin/connexion
            check_path: /admin/connexion
        logout:
            path:   /logout
            target: /

1 个答案:

答案 0 :(得分:0)

问题出在我的提供程序上:我有两个提供程序,一个用于数据库中的用户,一个用于硬编码的用户in_memory,而我忘记创建链式提供程序,如下所述:symfony.com/doc/3.1/security/multiple_user_providers.html

相关问题