去除username
This commit is contained in:
parent
a6bdf9e7ad
commit
e5e7d2d052
@ -157,7 +157,6 @@ class UsersController extends AbstractController
|
|||||||
"identity": [ ],
|
"identity": [ ],
|
||||||
"az": "",
|
"az": "",
|
||||||
"email": "admin@admin.com",
|
"email": "admin@admin.com",
|
||||||
"username": "admin@admin.com",
|
|
||||||
"nickname": "admin",
|
"nickname": "admin",
|
||||||
"userimg": "",
|
"userimg": "",
|
||||||
"loginnum": 10,
|
"loginnum": 10,
|
||||||
@ -328,14 +327,13 @@ class UsersController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function search()
|
public function search()
|
||||||
{
|
{
|
||||||
$builder = User::select(['userid', 'email', 'username', 'nickname', 'userimg']);
|
$builder = User::select(['userid', 'email', 'nickname', 'userimg']);
|
||||||
//
|
//
|
||||||
$keys = Request::input('where');
|
$keys = Request::input('where');
|
||||||
if (is_array($keys)) {
|
if (is_array($keys)) {
|
||||||
if ($keys['key']) {
|
if ($keys['key']) {
|
||||||
$builder->where(function($query) use ($keys) {
|
$builder->where(function($query) use ($keys) {
|
||||||
$query->where('email', 'like', '%,' . $keys['key'] . ',%')
|
$query->where('email', 'like', '%,' . $keys['key'] . ',%')
|
||||||
->orWhere('username', 'like', '%,' . $keys['key'] . ',%')
|
|
||||||
->orWhere('nickname', 'like', '%,' . $keys['key'] . ',%');
|
->orWhere('nickname', 'like', '%,' . $keys['key'] . ',%');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ use Cache;
|
|||||||
* @property array $identity 身份
|
* @property array $identity 身份
|
||||||
* @property string|null $az A-Z
|
* @property string|null $az A-Z
|
||||||
* @property string|null $email 邮箱
|
* @property string|null $email 邮箱
|
||||||
* @property string|null $username 用户名
|
|
||||||
* @property string $nickname 昵称
|
* @property string $nickname 昵称
|
||||||
* @property string|null $userimg 头像
|
* @property string|null $userimg 头像
|
||||||
* @property string|null $encrypt
|
* @property string|null $encrypt
|
||||||
@ -50,7 +49,6 @@ use Cache;
|
|||||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereUserid($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|User whereUserid($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereUserimg($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|User whereUserimg($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereUsername($value)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereUserpass($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|User whereUserpass($value)
|
||||||
* @mixin \Eloquent
|
* @mixin \Eloquent
|
||||||
*/
|
*/
|
||||||
@ -72,13 +70,7 @@ class User extends AbstractModel
|
|||||||
*/
|
*/
|
||||||
public function getNicknameAttribute($value)
|
public function getNicknameAttribute($value)
|
||||||
{
|
{
|
||||||
if ($value) {
|
return $value ?: Base::cardFormat($this->email);
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
if ($this->username) {
|
|
||||||
return $this->username;
|
|
||||||
}
|
|
||||||
return Base::cardFormat($this->email);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,19 +141,6 @@ class User extends AbstractModel
|
|||||||
return Base::retSuccess('success', $user);
|
return Base::retSuccess('success', $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* userid获取用户名
|
|
||||||
* @param $userid
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function userid2username($userid)
|
|
||||||
{
|
|
||||||
if (empty($userid)) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return self::whereUserid(intval($userid))->value('username');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邮箱获取userid
|
* 邮箱获取userid
|
||||||
* @param $email
|
* @param $email
|
||||||
@ -172,20 +151,7 @@ class User extends AbstractModel
|
|||||||
if (empty($email)) {
|
if (empty($email)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return intval(self::whereUsername($email)->value('userid'));
|
return intval(self::whereEmail($email)->value('userid'));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户名获取userid
|
|
||||||
* @param $username
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public static function username2userid($username)
|
|
||||||
{
|
|
||||||
if (empty($username)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return intval(self::whereUsername($username)->value('userid'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,12 +164,12 @@ class User extends AbstractModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* token获取会员账号
|
* token获取会员邮箱
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function token2username()
|
public static function token2email()
|
||||||
{
|
{
|
||||||
return self::authFind('username', Base::getToken());
|
return self::authFind('email', Base::getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -226,10 +192,10 @@ class User extends AbstractModel
|
|||||||
if ($token === null) {
|
if ($token === null) {
|
||||||
$token = Base::getToken();
|
$token = Base::getToken();
|
||||||
}
|
}
|
||||||
list($userid, $username, $encrypt, $timestamp) = explode("@", base64_decode($token) . "@@@@");
|
list($userid, $email, $encrypt, $timestamp) = explode("#$", base64_decode($token) . "#$#$#$#$");
|
||||||
$array = [
|
$array = [
|
||||||
'userid' => intval($userid),
|
'userid' => intval($userid),
|
||||||
'username' => $username ?: '',
|
'email' => $email ?: '',
|
||||||
'encrypt' => $encrypt ?: '',
|
'encrypt' => $encrypt ?: '',
|
||||||
'timestamp' => intval($timestamp),
|
'timestamp' => intval($timestamp),
|
||||||
];
|
];
|
||||||
@ -259,7 +225,7 @@ class User extends AbstractModel
|
|||||||
$loginValid = floatval(Base::settingFind('system', 'loginValid')) ?: 720;
|
$loginValid = floatval(Base::settingFind('system', 'loginValid')) ?: 720;
|
||||||
$loginValid *= 3600;
|
$loginValid *= 3600;
|
||||||
if ($authInfo['timestamp'] + $loginValid > time()) {
|
if ($authInfo['timestamp'] + $loginValid > time()) {
|
||||||
$row = self::whereUserid($authInfo['userid'])->whereUsername($authInfo['username'])->whereEncrypt($authInfo['encrypt'])->first();
|
$row = self::whereUserid($authInfo['userid'])->whereEmail($authInfo['email'])->whereEncrypt($authInfo['encrypt'])->first();
|
||||||
if ($row) {
|
if ($row) {
|
||||||
$upArray = [];
|
$upArray = [];
|
||||||
if (Base::getIp() && $row->lineip != Base::getIp()) {
|
if (Base::getIp() && $row->lineip != Base::getIp()) {
|
||||||
@ -305,7 +271,7 @@ class User extends AbstractModel
|
|||||||
*/
|
*/
|
||||||
public static function token($userinfo)
|
public static function token($userinfo)
|
||||||
{
|
{
|
||||||
return base64_encode($userinfo->userid . '@' . $userinfo->username . '@' . $userinfo->encrypt . '@' . time() . '@' . Base::generatePassword(6));
|
return base64_encode($userinfo->userid . '#$' . $userinfo->email . '#$' . $userinfo->encrypt . '#$' . time() . '#$' . Base::generatePassword(6));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -367,30 +333,11 @@ class User extends AbstractModel
|
|||||||
if (isset($_A["__static_userid2basic_" . $userid])) {
|
if (isset($_A["__static_userid2basic_" . $userid])) {
|
||||||
return $_A["__static_userid2basic_" . $userid];
|
return $_A["__static_userid2basic_" . $userid];
|
||||||
}
|
}
|
||||||
$fields = ['userid', 'email', 'username', 'nickname', 'userimg'];
|
$fields = ['userid', 'email', 'nickname', 'userimg'];
|
||||||
$userInfo = self::whereUserid($userid)->select($fields)->first();
|
$userInfo = self::whereUserid($userid)->select($fields)->first();
|
||||||
return $_A["__static_userid2basic_" . $userid] = ($userInfo ?: []);
|
return $_A["__static_userid2basic_" . $userid] = ($userInfo ?: []);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* username 获取 基本信息
|
|
||||||
* @param string $username 用户名
|
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public static function username2basic(string $username)
|
|
||||||
{
|
|
||||||
global $_A;
|
|
||||||
if (empty($username)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (isset($_A["__static_username2basic_" . $username])) {
|
|
||||||
return $_A["__static_username2basic_" . $username];
|
|
||||||
}
|
|
||||||
$fields = ['userid', 'email', 'username', 'nickname', 'userimg'];
|
|
||||||
$userInfo = self::whereUsername($username)->select($fields)->first();
|
|
||||||
return $_A["__static_username2basic_" . $username] = ($userInfo ?: []);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* email 获取 基本信息
|
* email 获取 基本信息
|
||||||
* @param string $email 邮箱地址
|
* @param string $email 邮箱地址
|
||||||
@ -405,14 +352,14 @@ class User extends AbstractModel
|
|||||||
if (isset($_A["__static_email2basic_" . $email])) {
|
if (isset($_A["__static_email2basic_" . $email])) {
|
||||||
return $_A["__static_email2basic_" . $email];
|
return $_A["__static_email2basic_" . $email];
|
||||||
}
|
}
|
||||||
$fields = ['userid', 'email', 'username', 'nickname', 'userimg'];
|
$fields = ['userid', 'email', 'nickname', 'userimg'];
|
||||||
$userInfo = self::whereEmail($email)->select($fields)->first();
|
$userInfo = self::whereEmail($email)->select($fields)->first();
|
||||||
return $_A["__static_email2basic_" . $email] = ($userInfo ?: []);
|
return $_A["__static_email2basic_" . $email] = ($userInfo ?: []);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户头像,不存在时返回默认
|
* 用户头像,不存在时返回默认
|
||||||
* @param string $var 头像地址 或 会员用户名
|
* @param string $var 头像地址 或 会员邮箱
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function userimg(string $var)
|
public static function userimg(string $var)
|
||||||
@ -421,7 +368,7 @@ class User extends AbstractModel
|
|||||||
if (empty($var)) {
|
if (empty($var)) {
|
||||||
$var = "";
|
$var = "";
|
||||||
} else {
|
} else {
|
||||||
$userInfo = self::username2basic($var);
|
$userInfo = self::email2basic($var);
|
||||||
if ($userInfo) {
|
if ($userInfo) {
|
||||||
$var = $userInfo->userimg;
|
$var = $userInfo->userimg;
|
||||||
}
|
}
|
||||||
@ -436,7 +383,7 @@ class User extends AbstractModel
|
|||||||
*/
|
*/
|
||||||
public static function AZUpdate($userid)
|
public static function AZUpdate($userid)
|
||||||
{
|
{
|
||||||
$row = self::whereUserid($userid)->select(['email', 'username', 'nickname'])->first();
|
$row = self::whereUserid($userid)->select(['email', 'nickname'])->first();
|
||||||
if ($row) {
|
if ($row) {
|
||||||
$row->az = Base::getFirstCharter($row->nickname);
|
$row->az = Base::getFirstCharter($row->nickname);
|
||||||
$row->save();
|
$row->save();
|
||||||
@ -445,10 +392,10 @@ class User extends AbstractModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否需要验证码
|
* 是否需要验证码
|
||||||
* @param $username
|
* @param $email
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function needCode($username)
|
public static function needCode($email)
|
||||||
{
|
{
|
||||||
$loginCode = Base::settingFind('system', 'loginCode');
|
$loginCode = Base::settingFind('system', 'loginCode');
|
||||||
switch ($loginCode) {
|
switch ($loginCode) {
|
||||||
@ -459,7 +406,7 @@ class User extends AbstractModel
|
|||||||
return Base::retError('no');
|
return Base::retError('no');
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (Cache::get("code::" . $username) == 'need') {
|
if (Cache::get("code::" . $email) == 'need') {
|
||||||
return Base::retSuccess('need');
|
return Base::retSuccess('need');
|
||||||
} else {
|
} else {
|
||||||
return Base::retError('no');
|
return Base::retError('no');
|
||||||
|
158
resources/assets/js/functions/web.js
vendored
158
resources/assets/js/functions/web.js
vendored
@ -181,11 +181,6 @@
|
|||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (res.ret === 1) {
|
if (res.ret === 1) {
|
||||||
$A.app.$store.commit('setUserInfo', res.data);
|
$A.app.$store.commit('setUserInfo', res.data);
|
||||||
$A.updateUserBasic({
|
|
||||||
username: res.data.username,
|
|
||||||
nickname: res.data.nickname,
|
|
||||||
userimg: res.data.userimg,
|
|
||||||
});
|
|
||||||
typeof callback === "function" && callback(res.data, $A.app.$store.state.userToken);
|
typeof callback === "function" && callback(res.data, $A.app.$store.state.userToken);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -194,159 +189,6 @@
|
|||||||
return $A.app.$store.state.userInfo;
|
return $A.app.$store.state.userInfo;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据用户名获取用户基本信息
|
|
||||||
* @param params Object{username,callback,listenerName,cacheTime}
|
|
||||||
*/
|
|
||||||
getUserBasic(params) {
|
|
||||||
if (typeof params !== 'object' || params === null) return;
|
|
||||||
if (typeof params.listenerName === 'undefined') params.listenerName = $A.randomString(16);
|
|
||||||
if (typeof params.cacheTime === 'undefined') params.cacheTime = 300;
|
|
||||||
|
|
||||||
if (typeof params.callback !== "function") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!params.username) {
|
|
||||||
params.callback({}, false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
$A.__userBasicFuncUpdate.push({
|
|
||||||
listenerName: params.listenerName,
|
|
||||||
username: params.username,
|
|
||||||
callback: params.callback
|
|
||||||
});
|
|
||||||
//
|
|
||||||
let keyName = '__userBasic:' + params.username.substring(0, 1) + '__';
|
|
||||||
let localData = $A.jsonParse(window.localStorage[keyName]);
|
|
||||||
if ($A.getObject(localData, params.username + '.success') === true) {
|
|
||||||
params.callback(localData[params.username].data, true);
|
|
||||||
if (localData[params.username].update + params.cacheTime > Math.round(new Date().getTime() / 1000)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
|
||||||
$A.__userBasicFuncAjax.push({
|
|
||||||
username: params.username,
|
|
||||||
callback: params.callback
|
|
||||||
});
|
|
||||||
//
|
|
||||||
$A.__userBasicTimeout++;
|
|
||||||
let timeout = $A.__userBasicTimeout;
|
|
||||||
setTimeout(() => {
|
|
||||||
timeout === $A.__userBasicTimeout && $A.__userBasicEvent();
|
|
||||||
}, 100);
|
|
||||||
},
|
|
||||||
__userBasicEvent() {
|
|
||||||
if ($A.__userBasicLoading === true) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$A.__userBasicLoading = true;
|
|
||||||
//
|
|
||||||
let userArray = [];
|
|
||||||
$A.__userBasicFuncAjax.some((item) => {
|
|
||||||
userArray.push(item.username);
|
|
||||||
if (userArray.length >= 30) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//
|
|
||||||
$A.apiAjax({
|
|
||||||
url: 'users/basic',
|
|
||||||
data: {
|
|
||||||
username: $A.jsonStringify(userArray),
|
|
||||||
},
|
|
||||||
error: () => {
|
|
||||||
userArray.forEach((username) => {
|
|
||||||
let tmpLists = $A.__userBasicFuncAjax.filter((item) => item.username == username);
|
|
||||||
tmpLists.forEach((item) => {
|
|
||||||
if (typeof item.callback === "function") {
|
|
||||||
item.callback({}, false);
|
|
||||||
item.callback = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
//
|
|
||||||
$A.__userBasicLoading = false;
|
|
||||||
$A.__userBasicFuncAjax = $A.__userBasicFuncAjax.filter((item) => typeof item.callback === "function");
|
|
||||||
if ($A.__userBasicFuncAjax.length > 0) {
|
|
||||||
$A.__userBasicEvent();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
success: (res) => {
|
|
||||||
if (res.ret === 1) {
|
|
||||||
res.data.forEach((data) => {
|
|
||||||
let keyName = '__userBasic:' + data.username.substring(0, 1) + '__';
|
|
||||||
let localData = $A.jsonParse(window.localStorage[keyName]);
|
|
||||||
localData[data.username] = {
|
|
||||||
success: true,
|
|
||||||
update: Math.round(new Date().getTime() / 1000),
|
|
||||||
data: data
|
|
||||||
};
|
|
||||||
window.localStorage[keyName] = $A.jsonStringify(localData);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
userArray.forEach((username) => {
|
|
||||||
let tmpLists = $A.__userBasicFuncAjax.filter((item) => item.username == username);
|
|
||||||
tmpLists.forEach((item) => {
|
|
||||||
if (typeof item.callback === "function") {
|
|
||||||
let info = res.data.filter((data) => data.username == username);
|
|
||||||
if (info.length === 0) {
|
|
||||||
item.callback({}, false);
|
|
||||||
} else {
|
|
||||||
item.callback(info[0], true);
|
|
||||||
}
|
|
||||||
item.callback = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
//
|
|
||||||
$A.__userBasicLoading = false;
|
|
||||||
$A.__userBasicFuncAjax = $A.__userBasicFuncAjax.filter((item) => typeof item.callback === "function");
|
|
||||||
if ($A.__userBasicFuncAjax.length > 0) {
|
|
||||||
$A.__userBasicEvent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
__userBasicTimeout: 0,
|
|
||||||
__userBasicLoading: false,
|
|
||||||
__userBasicFuncAjax: [],
|
|
||||||
__userBasicFuncUpdate: [],
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主动更新缓存
|
|
||||||
* @param params Object{username,....}
|
|
||||||
*/
|
|
||||||
updateUserBasic(params) {
|
|
||||||
if (typeof params !== 'object' || params === null) return;
|
|
||||||
|
|
||||||
if (!params.username) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let keyName = '__userBasic:' + params.username.substring(0, 1) + '__';
|
|
||||||
let localData = $A.jsonParse(window.localStorage[keyName]);
|
|
||||||
if ($A.getObject(localData, params.username + '.success') === true) {
|
|
||||||
localData[params.username].data = Object.assign(localData[params.username].data, params);
|
|
||||||
window.localStorage[keyName] = $A.jsonStringify(localData);
|
|
||||||
//
|
|
||||||
let tmpLists = $A.__userBasicFuncUpdate.filter((item) => item.username == params.username);
|
|
||||||
tmpLists.forEach((item) => {
|
|
||||||
if (typeof item.callback === "function") {
|
|
||||||
item.callback(localData[params.username].data, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 销毁监听
|
|
||||||
* @param listenerName
|
|
||||||
*/
|
|
||||||
destroyUserBasicListener(listenerName) {
|
|
||||||
$A.__userBasicFuncUpdate = $A.__userBasicFuncUpdate.filter((item) => item.listenerName != listenerName);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打开登录页面
|
* 打开登录页面
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user