/** * 判定用户session 是否失效 * @param $sessionkey * @return bool */ public static function sessionkey_istimeout($sessionkey) { $is_timeout = Sessionkey::find()->where(['sessionkey' => $sessionkey, 'status' => Sessionkey::STATUS_DELETED])->asArray()->one(); if ($is_timeout) { return true; } else { return false; } }
/** * 用户忘记密码,需要重置密码 * @param $phone 用户手机号 * @param $new_pwd 新密码 * @param $rep_pwd 重复密码 * @param $phone_code 手机验证码 * @param string $name 真实姓名 * @param string $idcard 身份证号 * @return array * @throws \yii\base\Exception * @throws \yii\base\InvalidConfigException */ public static function resetwechatPassword($phone, $new_pwd, $rep_pwd, $phone_code, $name = "", $idcard = "") { $is_reg = self::phoneIsRegister($phone); if ($is_reg) { $is_aut = self::isAuthentic($is_reg); //用户进行了实名认证 if (!$is_aut['errorNum']) { //验证手机验证码 if ($new_pwd != $rep_pwd) { $return = array('errorNum' => '1', 'errorMsg' => '两次密码不一致', 'data' => null); return $return; } elseif (strlen($new_pwd) < 5) { $return = array('errorNum' => '1', 'errorMsg' => '密码长度不能小于6位', 'data' => null); return $return; } elseif (!preg_match('/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)[0-9a-zA-Z]{6,16}$/', $new_pwd)) { $return = array('errorNum' => '1', 'errorMsg' => '密码应该是数字、字母组成的6到16位字符', 'data' => null); return $return; } else { $check = Port::checkPhnoe($phone, $phone_code); if ($check['errorNum']) { return $check; } $member = UcenterMember::findOne($is_reg); if ($member) { $app_pwd = md5(sha1($new_pwd) . time()); $hash_pwd = Yii::$app->security->generatePasswordHash($new_pwd); $member->password_hash = $hash_pwd; $member->app_pwd = $app_pwd; $res = $member->save(); //修改密码成功---对登陆状态做判定 if ($res) { $key = Sessionkey::find()->where(['uid' => $is_reg, 'status' => self::STATUS_ACTIVE])->one(); //如果用户是在登陆状态进行的操作-----让用户重新登陆 if ($key) { $key->status = self::STATUS_DELETE; if ($key->save()) { $return = array('errorNum' => '0', 'errorMsg' => "success", 'data' => null); return $return; } else { $return = array('errorNum' => '1', 'errorMsg' => "用户下线失败", 'data' => null); return $return; } } else { $return = array('errorNum' => '0', 'errorMsg' => "success", 'data' => null); return $return; } } else { $return = array('errorNum' => '1', 'errorMsg' => "修改密码失败", 'data' => null); return $return; } } } } else { if ($new_pwd != $rep_pwd) { $return = array('errorNum' => '1', 'errorMsg' => '两次密码不一致', 'data' => null); return $return; } elseif (strlen($new_pwd) < 5) { $return = array('errorNum' => '1', 'errorMsg' => '密码长度不能小于6位', 'data' => null); return $return; } elseif (!preg_match('/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)[0-9a-zA-Z]{6,16}$/', $new_pwd)) { $return = array('errorNum' => '1', 'errorMsg' => '密码应该是数字、字母组成的6到16位字符', 'data' => null); return $return; } else { $check = Port::checkPhnoe($phone, $phone_code); if ($check['errorNum']) { return $check; } $member = UcenterMember::findOne($is_reg); if ($member) { $app_pwd = md5(sha1($new_pwd) . time()); $hash_pwd = Yii::$app->security->generatePasswordHash($new_pwd); $member->password_hash = $hash_pwd; $member->app_pwd = $app_pwd; $res = $member->save(); //修改密码成功---对登陆状态做判定 if ($res) { $key = Sessionkey::find()->where(['uid' => $is_reg, 'status' => self::STATUS_ACTIVE])->one(); //如果用户是在登陆状态进行的操作-----让用户重新登陆 if ($key) { $key->status = self::STATUS_DELETE; if ($key->save()) { $return = array('errorNum' => '0', 'errorMsg' => "success", 'data' => null); return $return; } else { $return = array('errorNum' => '1', 'errorMsg' => "用户下线失败", 'data' => null); return $return; } } else { $return = array('errorNum' => '0', 'errorMsg' => "success", 'data' => null); return $return; } } else { $return = array('errorNum' => '1', 'errorMsg' => "修改密码失败", 'data' => null); return $return; } } } } } else { $return = array('errorNum' => '1', 'errorMsg' => "用户不存在", 'data' => null); return $return; } }