【问题标题】:Updating user info with Laravel and Sentry使用 Laravel 和 Sentry 更新用户信息
【发布时间】:2014-05-08 03:06:35
【问题描述】:

我有一个关于在 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 部分有问题,但是什么?我不知道。帮助将不胜感激。

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

【问题讨论】:

    标签: laravel user-input cartalyst-sentry


    【解决方案1】:

    改变

        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');
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多