diff --git a/backend/web/src/custom-menu/index.js b/backend/web/src/custom-menu/index.js index a969cdd..0c39148 100644 --- a/backend/web/src/custom-menu/index.js +++ b/backend/web/src/custom-menu/index.js @@ -18,6 +18,7 @@ const IconFont = Icon.createFromIconfontCN({ }); const { data: initMenuList = [] } = window; +const { sourceUrl } = window;console.log(sourceUrl); function getActiveMenu(menuList, activeMenuInfo) { const activeParent = menuList.find(menu => menu.id === activeMenuInfo.id); @@ -130,7 +131,7 @@ function App() { return ( - + 'Asia/Shanghai', 'language' => 'zh-CN', 'components' => [ - 'userLogic' => ['class' => 'iron\logic\UserManager'], 'cache' => [ 'class' => 'yii\caching\FileCache', ], diff --git a/common/models/User.php b/common/models/User.php index 07e5162..6647e90 100644 --- a/common/models/User.php +++ b/common/models/User.php @@ -1,71 +1,50 @@ 255], - [['auth_key', 'wx_openid', 'mini_openid'], 'string', 'max' => 32], - [['name', 'nickname', 'session_key'], 'string', 'max' => 120], - [['phone'], 'string', 'max' => 13], - [['unionid'], 'string', 'max' => 60], - [['member_code'], 'string', 'max' => 20], + ['status', 'default', 'value' => self::STATUS_INACTIVE], + ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_INACTIVE, self::STATUS_DELETED]], ]; } /** * {@inheritdoc} */ - public function attributeLabels() + public static function findIdentity($id) { - return [ - 'id' => 'id', - 'username' => 'username', - 'auth_key' => 'auth_key', - 'password_hash' => 'password_hash', - 'password_reset_token' => 'password_reset_token', - 'name' => 'name', - 'sex' => 'sex', - 'phone' => '联系方式', - 'email' => 'email', - 'role' => 'role', - 'status' => 'status', - 'access_token' => 'access_token', - 'expire_at' => 'expire_at', - 'nickname' => 'nickname', - 'avatar' => 'avatar', - 'wx_openid' => '公众号openid', - 'mini_openid' => '小程序openid', - 'unionid' => 'unionid', - 'session_key' => '小程序解密密钥', - 'member_code' => '会员编号', - 'exp_point' => '经验值', - 'consume_point' => '消费积分', - 'created_at' => '创建时间', - 'updated_at' => '更新时间', - ]; + return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]); } + /** + * {@inheritdoc} + */ + public static function findIdentityByAccessToken($token, $type = null) + { + throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.'); + } /** - * @author linyao - * @email 602604991@qq.com - * @created Nov 8, 2019 + * Finds user by username * - * 行为存储创建时间和更新时间 + * @param string $username + * @return static|null */ - public function behaviors() + public static function findByUsername($username) { - return [ - [ - 'class' => TimestampBehavior::className(), - 'createdAtAttribute' => 'created_at', - 'updatedAtAttribute' => 'updated_at', - 'value' => function () { - return time(); - }, - ], - ]; + return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]); } /** - * @inheritDoc + * Finds user by password reset token + * + * @param string $token password reset token + * @return static|null */ - public static function findIdentity($id) + public static function findByPasswordResetToken($token) { - return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]); + if (!static::isPasswordResetTokenValid($token)) { + return null; + } + + return static::findOne([ + 'password_reset_token' => $token, + 'status' => self::STATUS_ACTIVE, + ]); } /** - * @param mixed $token - * @param null $type - * @return array|\yii\db\ActiveRecord|IdentityInterface|null - * @throws NotFoundHttpException - * @throws UnauthorizedHttpException + * Finds user by verification email token + * + * @param string $token verify email token + * @return static|null */ - public static function findIdentityByAccessToken($token, $type = null) + public static function findByVerificationToken($token) { + return static::findOne([ + 'verification_token' => $token, + 'status' => self::STATUS_INACTIVE + ]); + } + + /** + * Finds out if password reset token is valid + * + * @param string $token password reset token + * @return bool + */ + public static function isPasswordResetTokenValid($token) { - $user = static::find() - ->where(['access_token' => $token, 'status' => self::STATUS_ACTIVE]) - ->one(); - if (!$user) { - throw new NotFoundHttpException('user not found'); - } - if ($user->expire_at < time()) { - throw new UnauthorizedHttpException('access - token expired ', -1); - } else { - return $user; + if (empty($token)) { + return false; } + + $timestamp = (int) substr($token, strrpos($token, '_') + 1); + $expire = Yii::$app->params['user.passwordResetTokenExpire']; + return $timestamp + $expire >= time(); } /** - * @inheritDoc + * {@inheritdoc} */ public function getId() { @@ -179,7 +142,7 @@ class User extends \yii\db\ActiveRecord implements IdentityInterface } /** - * @inheritDoc + * {@inheritdoc} */ public function getAuthKey() { @@ -187,10 +150,60 @@ class User extends \yii\db\ActiveRecord implements IdentityInterface } /** - * @inheritDoc + * {@inheritdoc} */ public function validateAuthKey($authKey) { return $this->getAuthKey() === $authKey; } -} + + /** + * Validates password + * + * @param string $password password to validate + * @return bool if password provided is valid for current user + */ + public function validatePassword($password) + { + return Yii::$app->security->validatePassword($password, $this->password_hash); + } + + /** + * Generates password hash from password and sets it to the model + * + * @param string $password + */ + public function setPassword($password) + { + $this->password_hash = Yii::$app->security->generatePasswordHash($password); + } + + /** + * Generates "remember me" authentication key + */ + public function generateAuthKey() + { + $this->auth_key = Yii::$app->security->generateRandomString(); + } + + /** + * Generates new password reset token + */ + public function generatePasswordResetToken() + { + $this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time(); + } + + public function generateEmailVerificationToken() + { + $this->verification_token = Yii::$app->security->generateRandomString() . '_' . time(); + } + + /** + * Removes password reset token + */ + public function removePasswordResetToken() + { + $this->password_reset_token = null; + } +} \ No newline at end of file