本文整理汇总了PHP中App\Modules\User\Module::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Module::model方法的具体用法?PHP Module::model怎么用?PHP Module::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Modules\User\Module
的用法示例。
在下文中一共展示了Module::model方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendForgotEmail
/**
* Send forgot email
* @return bool
*/
public function sendForgotEmail()
{
/** @var Mailer $mailer */
/** @var Message $message */
/** @var \app\modules\user\models\UserToken $userToken */
if ($this->validate()) {
// get user
$user = $this->getUser();
// calculate expireTime
$expireTime = $this->module->resetExpireTime;
$expireTime = $expireTime ? gmdate("Y-m-d H:i:s", strtotime($expireTime)) : null;
// create userToken
$userToken = $this->module->model("UserToken");
$userToken = $userToken::generate($user->id, $userToken::TYPE_PASSWORD_RESET, null, $expireTime);
// modify view path to module views
$mailer = Yii::$app->mailer;
$oldViewPath = $mailer->viewPath;
$mailer->viewPath = $this->module->emailViewPath;
// send email
$subject = Yii::$app->id . " - " . Yii::t("user", "Forgot password");
$result = $mailer->compose('forgotPassword', compact("subject", "user", "userToken"))->setTo($user->email)->setSubject($subject)->send();
// restore view path and return result
$mailer->viewPath = $oldViewPath;
return $result;
}
return false;
}
示例2: setInfoVkontakte
/**
* Set info for vkontakte registration
*
* @author Ilya Sheershoff <sheershoff@gmail.com>
* @param array $attributes
* @return array [$user, $profile]
*/
protected function setInfoVkontakte($attributes)
{
/** @var \app\modules\user\models\User $user */
/** @var \app\modules\user\models\Profile $profile */
$user = $this->module->model("User");
$profile = $this->module->model("Profile");
foreach ($_SESSION as $k => $v) {
if (is_object($v) && get_class($v) == "yii\\authclient\\OAuthToken") {
/** @var \yii\authclient\OAuthToken $v */
$user->email = $v->getParam('email');
}
}
// set email/username if they are set
// note: email may be missing if user signed up using a phone number
if (!empty($attributes["email"])) {
$user->email = $attributes["email"];
}
if (!empty($attributes["first_name"]) && !empty($attributes["last_name"])) {
$user->username = "{$attributes["first_name"]} {$attributes["last_name"]}";
}
// use vkontakte_id name as username as fallback
if (empty($attributes["email"]) && empty($attributes["username"])) {
$user->username = "vkontakte_{$attributes["id"]}";
}
$profile->full_name = "{$attributes["first_name"]} {$attributes["last_name"]}";
return [$user, $profile];
}
示例3: findModel
/**
* Find the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param string $id
* @return User the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
/** @var \app\modules\user\models\User $user */
$user = $this->module->model("User");
$user = $user::findOne($id);
if ($user) {
return $user;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
示例4: getUser
/**
* Get user based on email and/or username
* @return \app\modules\user\models\User|null
*/
public function getUser()
{
// check if we need to get user
if ($this->user === false) {
// build query based on email and/or username login properties
$user = $this->module->model("User");
$user = $user::find();
if ($this->module->loginEmail) {
$user->orWhere(["email" => $this->username]);
}
if ($this->module->loginUsername) {
$user->orWhere(["username" => $this->username]);
}
$this->user = $user->one();
}
return $this->user;
}
示例5: sendEmail
/**
* Send forgot email
* @return bool
*/
public function sendEmail()
{
if (!$this->validate()) {
return false;
}
/** @var \app\modules\user\models\UserToken $userToken */
$user = $this->getUser();
$userToken = $this->module->model("UserToken");
// calculate type based on user status
if ($user->status == $user::STATUS_INACTIVE) {
$type = $userToken::TYPE_EMAIL_ACTIVATE;
} else {
$type = $userToken::TYPE_EMAIL_CHANGE;
}
// generate userToken and send email confirmation
$userToken = $userToken::generate($user->id, $type);
return $user->sendEmailConfirmation($userToken);
}
示例6: actionReset
/**
* Reset password
*/
public function actionReset($token)
{
/** @var \app\modules\user\models\User $user */
/** @var \app\modules\user\models\UserToken $userToken */
// get user token and check expiration
$userToken = $this->module->model("UserToken");
$userToken = $userToken::findByToken($token, $userToken::TYPE_PASSWORD_RESET);
if (!$userToken) {
return $this->render('reset', ["invalidToken" => true]);
}
// get user and set "reset" scenario
$success = false;
$user = $this->module->model("User");
$user = $user::findOne($userToken->user_id);
$user->setScenario("reset");
// load post data and reset user password
if ($user->load(Yii::$app->request->post()) && $user->save()) {
// delete userToken and set success = true
$userToken->delete();
$success = true;
}
return $this->render('reset', compact("user", "success"));
}
示例7: getUser
/**
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
$user = $this->module->model("User");
return $this->hasOne($user::className(), ['id' => 'user_id']);
}
示例8: getUserTokens
/**
* @return \yii\db\ActiveQuery
*/
public function getUserTokens()
{
$userToken = $this->module->model("UserToken");
return $this->hasMany($userToken::className(), ['user_id' => 'id']);
}
示例9: getUsers
/**
* @return \yii\db\ActiveQuery
*/
public function getUsers()
{
$user = $this->module->model("User");
return $this->hasMany($user::className(), ['role_id' => 'id']);
}