使用Laravel和Sentry更新用户信息
我有一个问题,关于更新用户信息使用哨兵在拉威尔 我的控制器里有这个:使用Laravel和Sentry更新用户信息,laravel,user-input,cartalyst-sentry,Laravel,User Input,Cartalyst Sentry,我有一个问题,关于更新用户信息使用哨兵在拉威尔 我的控制器里有这个: public function update() { try{ $user = $this->sentry->getUser(); $user->username = $this->input->get('username'); $user->first_name = $this->input->get('fi
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
部分有问题,但是什么?我不知道。我们将不胜感激
编辑:
我试图检查密码字段是否已填写,如果未填写,请保持原样,如果已填写,请检查其是否与当前密码不同,如果不同,请更改,否则请保持原样更改
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');
}