0

我有一个关于在 Laravel 中使用 Sentry 更新用户信息的问题。

我在我的控制器中得到了这个:

public function update()
{
    try{
        $user = $this->sentry->getUser();

        $user->username     = $this->input->get('username');
        $user->first_name   = $this->input->get('first_name');
        $user->last_name    = $this->input->get('last_name');
        $user->email        = $this->input->get('email');
        $user->description  = $this->input->get('description');

        if (!$this->hash->check($this->input->get('password'), $user->password))
        {
            $user->password = $user->password;
        } else {
            $user->password = $this->input->get('password');
        }

        if($user->save())
        {
            return $this->redirect->to('admin');
        } else {
            return $this->redirect->to('admin/'.$user->username.'/');
        }
    }
    catch (\Exception $e)
    {
        return $this->redirect->to('user/'.$user->username.'/profile/edit')->withErrors(array('login'=> $e->getMessage()));
    }
}

这将在提交表单时进行处理。但是,如果我没有在输入字段中填写密码,而是更新用户信息的其他内容并提交表单。它还采用“空”密码字段,并与它完全不同,因此我无法再使用原始密码登录。

我知道这hash->check部分有问题,但是什么?我不知道。帮助将不胜感激。

编辑:我正在尝试检查密码字段是否已填写,如果未填写,请保持密码不变,如果已填写,请检查其是否与当前密码不同,是否不同,改变它,否则保持原样

4

1 回答 1

0

改变

    if (!$this->hash->check($this->input->get('password'), $user->password))
    {
        $user->password = $user->password;
    } else {
        $user->password = $this->input->get('password');
    }

    if ($this->input->get('password'))
    {
        $user->password = $this->input->get('password');
    }
于 2014-03-28T15:41:22.730 回答