public function run() { $request = Yii::$app->request; $ident = Yii::$app->user->getIdentity(); $form = new PasswordForm(); $form->screen_name = $ident->screen_name; if ($request->isPost) { $form->load($request->bodyParams); $form->screen_name = $ident->screen_name; if ($form->validate()) { $transaction = Yii::$app->db->beginTransaction(); try { $ident->password = Password::hash($form->new_password); if ($ident->save()) { $transaction->commit(); $this->controller->redirect(['user/profile']); return; } } catch (\Exception $e) { } $transaction->rollback(); } } return $this->controller->render('edit-password.tpl', ['user' => $ident, 'form' => $form]); }
public function toUserModel() { $u = new User(); $u->name = $this->name == '' ? $this->screen_name : $this->name; $u->screen_name = $this->screen_name; $u->password = Password::hash($this->password); $u->api_key = User::generateNewApiKey(); $u->join_at = new Now(); return $u; }
public function rehashPasswordIfNeeded($password) { if (!Password::needsRehash($this->password)) { return false; } $this->password = Password::hash($password); return true; }