/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { try { return Purina::init()->resetPassword($this->email); } catch (\Exception $e) { return false; } }
/** * Logs in a user using the provided username and password. * * @return boolean whether the user is logged in successfully */ public function login() { if ($this->validate()) { try { if (!Purina::init()->login($this->email, $this->password)) { $db_user = User::findByEmail($this->email); if ($db_user) { $db_user->status = User::STATUS_DISABLED; $db_user->save(); } $data = Purina::getData(); if ($data->message) { $this->addError('password', Yii::t('frontend/base', $data->message)); } else { $this->addError('password', 'Не верный логин или пароль.'); } return false; } else { $user = Purina::getData(); $db_user = User::findByEmail($this->email); if (!$db_user) { $db_user = new User(); $db_user->id = $user->id; $db_user->firstname = $user->firstname; $db_user->lastname = $user->lastname; $db_user->email = $user->email; $db_user->token = $user->token->key; $db_user->token_expire = $user->token->expire; $db_user->created_at = Yii::$app->formatter->asTimestamp($user->register_date); $db_user->updated_at = $db_user->created_at; $db_user->setPassword($this->password); } else { $db_user->token = $user->token->key; $db_user->token_expire = $user->token->expire; } $db_user->status = User::STATUS_ACTIVE; if (!$db_user->save()) { return false; } $duration = $user->token->expire - Yii::$app->formatter->asTimestamp('now'); if (!Yii::$app->user->login($db_user, $duration)) { $this->addError('password', 'Не удалось авторизоваться.'); return false; } else { return true; } } } catch (\Exception $e) { $this->addError('password', 'Не удалось авторизоваться.'); return false; } } return false; }
public function actionAddPetBreed() { Yii::$app->response->format = Response::FORMAT_JSON; try { if (Purina::init()->getBreeds()) { $breeds = []; foreach (Purina::getData() as $breed) { $breeds[] = ['id' => $breed->system_name, 'name' => $breed->name]; } return ['status' => true, 'content' => $breeds]; } } catch (\Exception $e) { } return ['status' => false]; }
/** * @return bool */ public function signup() { if ($this->validate()) { try { if (!Purina::init()->signup($this->firstname, $this->lastname, $this->email, $this->password)) { $data = Purina::getData(); if ($data->message) { Yii::$app->session->setFlash('error', Yii::t('frontend/base', $data->message)); } else { Yii::$app->session->setFlash('error', "Не удалось зарегистрироваться"); } } else { $login = new LoginForm(); $login->email = $this->email; $login->password = $this->password; return $login->login(); } } catch (\Exception $e) { Yii::$app->session->setFlash('error', "Не удалось зарегистрироваться"); return false; } } return false; }
/** * @param $name * @param $gender * @param null|int $year * @param null|int $month * @return bool */ public static function createUserPet($name, $gender, $year = null, $month = null) { return parent::createUserPet(Yii::$app->user->id, $name, $gender, $year, $month); }
/** * Resets password. * * @return boolean if password was reset. */ public function resetPassword() { return Purina::init()->resetPasswordConfirm($this->uid, $this->token, $this->password); }