mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 22:55:36 +00:00
fix:修复用户默认的头像URL可能被入库的问题
This commit is contained in:
parent
96a3f0964c
commit
1c36f210d3
@ -5,7 +5,6 @@ namespace app\admin\model;
|
||||
use ba\Random;
|
||||
use think\Model;
|
||||
use think\facade\Db;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* Admin模型
|
||||
@ -50,7 +49,12 @@ class Admin extends Model
|
||||
|
||||
public function getAvatarAttr($value): string
|
||||
{
|
||||
return full_url($value, true, Config::get('buildadmin.default_avatar'));
|
||||
return full_url($value, true, config('buildadmin.default_avatar'));
|
||||
}
|
||||
|
||||
public function setAvatarAttr($value): string
|
||||
{
|
||||
return $value == full_url($value, true, config('buildadmin.default_avatar')) ? '' : $value;
|
||||
}
|
||||
|
||||
public function getLastLoginTimeAttr($value): string
|
||||
|
@ -15,7 +15,12 @@ class User extends Model
|
||||
|
||||
public function getAvatarAttr($value): string
|
||||
{
|
||||
return htmlspecialchars_decode($value);
|
||||
return full_url($value, true, config('buildadmin.default_avatar'));
|
||||
}
|
||||
|
||||
public function setAvatarAttr($value): string
|
||||
{
|
||||
return $value == full_url($value, true, config('buildadmin.default_avatar')) ? '' : $value;
|
||||
}
|
||||
|
||||
public function getMoneyAttr($value): string
|
||||
|
@ -58,15 +58,17 @@ class Account extends Frontend
|
||||
$data = $this->request->only(['id', 'avatar', 'username', 'nickname', 'gender', 'birthday', 'motto']);
|
||||
if (!isset($data['birthday'])) $data['birthday'] = null;
|
||||
|
||||
// 避免默认头像入库
|
||||
if (isset($data['avatar']) && $data['avatar'] == full_url('', true, config('buildadmin.default_avatar'))) unset($data['avatar']);
|
||||
try {
|
||||
$validate = new AccountValidate();
|
||||
$validate->scene('edit')->check($data);
|
||||
} catch (Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$model = $this->auth->getUser();
|
||||
$model->startTrans();
|
||||
try {
|
||||
$validate = new AccountValidate();
|
||||
$validate->scene('edit')->check($data);
|
||||
$model->where('id', $this->auth->id)->update($data);
|
||||
$model->save($data);
|
||||
$model->commit();
|
||||
} catch (Throwable $e) {
|
||||
$model->rollback();
|
||||
|
@ -4,7 +4,6 @@ namespace app\common\model;
|
||||
|
||||
use ba\Random;
|
||||
use think\Model;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 会员公共模型
|
||||
@ -23,7 +22,12 @@ class User extends Model
|
||||
|
||||
public function getAvatarAttr($value): string
|
||||
{
|
||||
return full_url(htmlspecialchars_decode($value), true, Config::get('buildadmin.default_avatar'));
|
||||
return full_url($value, true, config('buildadmin.default_avatar'));
|
||||
}
|
||||
|
||||
public function setAvatarAttr($value): string
|
||||
{
|
||||
return $value == full_url($value, true, config('buildadmin.default_avatar')) ? '' : $value;
|
||||
}
|
||||
|
||||
public function resetPassword($uid, $newPassword): int|User
|
||||
|
Loading…
Reference in New Issue
Block a user