|
@@ -86,18 +86,21 @@ class User extends Base
|
|
|
{
|
|
|
$user = $this->auth->getUser();
|
|
|
$params = $this->request->param();
|
|
|
+ // 字段不传就报错 所以默认给值
|
|
|
+ $username = $params['username'] ?? '';
|
|
|
+ $avatar = $params['avatar'] ?? '';
|
|
|
+ $nickname = $params['nickname'] ?? '';
|
|
|
+ $bio = $params['bio'] ?? '';
|
|
|
+ $age = $params['age'] ?? '';
|
|
|
+ $gender = $params['gender'] ?? '';
|
|
|
// 验证器
|
|
|
+ // 替换有域名的头像
|
|
|
+ $avatar = str_replace(cdnurl('', true), '', $avatar);
|
|
|
+ $params['avatar'] = $avatar;
|
|
|
$validate = new \app\api\validate\User();
|
|
|
if (!$validate->check($params, [], 'profile')) {
|
|
|
$this->error($validate->getError());
|
|
|
}
|
|
|
- $username = $params['username'] ?? '';
|
|
|
- // $avatar = $params['avatar'];
|
|
|
- $nickname = $params['nickname'];
|
|
|
- $bio = $params['bio'] ??'';
|
|
|
- $age = $params['age'];
|
|
|
- $gender = $params['gender'];
|
|
|
- // $avatar = str_replace(cdnurl('', true), '', $avatar);
|
|
|
// username 不传,则不修改
|
|
|
if ($username) {
|
|
|
$user->username = $username;
|
|
@@ -106,11 +109,10 @@ class User extends Base
|
|
|
$this->error(__('Username already exists'));
|
|
|
}
|
|
|
}
|
|
|
- if ($bio) {
|
|
|
- $user->bio = $bio;
|
|
|
- }
|
|
|
+ $user->bio = $bio;
|
|
|
$user->nickname = $nickname;
|
|
|
- // $user->avatar = $avatar;
|
|
|
+ $user->username = $username;
|
|
|
+ $user->avatar = $avatar;
|
|
|
$user->age = $age;
|
|
|
$user->gender = $gender;
|
|
|
$user->save();
|