/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { return $user; } } return null; }
/** * Finds user by [[username]] * * @return User|null */ protected function getUser() { if ($this->_user === null) { $this->_user = User::findByUsername($this->username); } return $this->_user; }
public function actionLogout() { $user = User::findIdentity(Yii::$app->user->id); $user->generateAuthKey(); if ($user->save() === false) { throw new ServerErrorHttpException('Failed to logout for unknown reason.'); } Yii::$app->getResponse()->setStatusCode(204); }
/** * Creates a form model given a token. * * @param string $token * @param array $config name-value pairs that will be used to initialize the object properties * @throws \yii\base\InvalidParamException if token is empty or not valid */ public function __construct($token, $config = []) { if (empty($token) || !is_string($token)) { throw new InvalidParamException('Password reset token cannot be blank.'); } $this->_user = User::findByPasswordResetToken($token); if (!$this->_user) { throw new InvalidParamException('Wrong password reset token.'); } parent::__construct($config); }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /* @var $user User */ $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } if ($user->save()) { return \Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send(); } } return false; }
/** * @param ProfileRequest $request * @param int $id * * @return mixed */ public function update(ProfileRequest $request, $id) { $User = User::find($id); if ($request->get('name')) { $User->name = $request->get('name'); } if ($request->get('email')) { $User->email = $request->get('email'); } if ($request->get('password') && env('APP_ENV') != 'homolog') { $User->password = bcrypt($request->get('password')); } if ($User->save()) { $this->flash()->success('Data has changed!'); } else { $this->flash()->error('Whooops! Could not change data.'); } return Redirect::back(); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $User = User::find($id); if ($User->delete()) { return Redirect::back()->with('message', 'Successfully deleted record!')->with('message-class', 'success'); } else { return Redirect::back()->with('message', 'Whooops! Could not delete the record.')->with('message-class', 'error')->withInputs(); } }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $record = User::find($id); return view('back::scope.system.users.edit', compact('record')); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $User = User::find($id); if (Gate::denies('delete', $User)) { return Redirect::route('back.system.users.index')->with('message', 'Not Allowed!')->with('message-class', 'danger'); } else { if ($User->delete()) { return Redirect::route('back.system.users.index')->with('message', 'Successfully deleted record!')->with('message-class', 'success'); } else { return Redirect::route('back.system.users.create')->with('message', 'Whooops! Could not delete the record.')->with('message-class', 'error'); } } }
public function run() { DB::table('users')->delete(); User::create(['name' => 'Admin', 'email' => '*****@*****.**', 'password' => bcrypt('admin')]); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]); }