|
@@ -191,28 +191,34 @@ class User extends Api
|
|
|
*/
|
|
|
public function profile()
|
|
|
{
|
|
|
- $user = $this->auth->getUser();
|
|
|
- $username = input('username');
|
|
|
- $nickname = input('nickname');
|
|
|
- $bio = input('bio');
|
|
|
- $avatar = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
|
|
|
- if ($username) {
|
|
|
- $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
|
|
|
- if ($exists) {
|
|
|
- $this->error(__('Username already exists'));
|
|
|
+ $field_array = ['firstname','lastname','height','age','weight','address','avatar'];
|
|
|
+
|
|
|
+ $data = [];
|
|
|
+ foreach($field_array as $key => $field){
|
|
|
+
|
|
|
+ //前端传不了post,改了
|
|
|
+ /*if(!request()->has($field,'post')){
|
|
|
+ continue;
|
|
|
+ }*/
|
|
|
+ if(!input('?'.$field)){
|
|
|
+ continue;
|
|
|
}
|
|
|
- $user->username = $username;
|
|
|
- }
|
|
|
- if ($nickname) {
|
|
|
- $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
|
|
|
- if ($exists) {
|
|
|
- $this->error(__('Nickname already exists'));
|
|
|
+
|
|
|
+ $newone = input($field);
|
|
|
+
|
|
|
+ if($field == 'avatar'){
|
|
|
+ $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
|
|
|
}
|
|
|
- $user->nickname = $nickname;
|
|
|
+
|
|
|
+ $data[$field] = $newone;
|
|
|
}
|
|
|
- $user->bio = $bio;
|
|
|
- $user->avatar = $avatar;
|
|
|
- $user->save();
|
|
|
+
|
|
|
+ if(empty($data)){
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::name('user')->where('id',$this->auth->id)->update($data);
|
|
|
+
|
|
|
$this->success();
|
|
|
}
|
|
|
|
|
@@ -223,7 +229,7 @@ class User extends Api
|
|
|
* @param string $email 邮箱
|
|
|
* @param string $captcha 验证码
|
|
|
*/
|
|
|
- public function changeemail()
|
|
|
+ /*public function changeemail()
|
|
|
{
|
|
|
$user = $this->auth->getUser();
|
|
|
$email = input('email');
|
|
@@ -249,7 +255,7 @@ class User extends Api
|
|
|
|
|
|
Ems::flush($email, 'changeemail');
|
|
|
$this->success();
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
/**
|
|
|
* 修改手机号
|
|
@@ -258,7 +264,7 @@ class User extends Api
|
|
|
* @param string $mobile 手机号
|
|
|
* @param string $captcha 验证码
|
|
|
*/
|
|
|
- public function changemobile()
|
|
|
+ /*public function changemobile()
|
|
|
{
|
|
|
$user = $this->auth->getUser();
|
|
|
$mobile = input('mobile');
|
|
@@ -284,7 +290,7 @@ class User extends Api
|
|
|
|
|
|
Sms::flush($mobile, 'changemobile');
|
|
|
$this->success();
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -297,11 +303,9 @@ class User extends Api
|
|
|
*/
|
|
|
public function resetpwd()
|
|
|
{
|
|
|
- $type = input("type");
|
|
|
- $mobile = input("mobile");
|
|
|
$email = input("email");
|
|
|
+ $captcha = input("emailcaptcha");
|
|
|
$newpassword = input("newpassword");
|
|
|
- $captcha = input("captcha");
|
|
|
if (!$newpassword || !$captcha) {
|
|
|
$this->error(__('Invalid parameters'));
|
|
|
}
|
|
@@ -309,33 +313,20 @@ class User extends Api
|
|
|
if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
|
|
|
$this->error(__('Password must be 6 to 30 characters'));
|
|
|
}
|
|
|
- if ($type == 'mobile') {
|
|
|
- if (!Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
- $this->error(__('Mobile is incorrect'));
|
|
|
- }
|
|
|
- $user = \app\common\model\User::getByMobile($mobile);
|
|
|
- if (!$user) {
|
|
|
- $this->error(__('User not found'));
|
|
|
- }
|
|
|
- $ret = Sms::check($mobile, $captcha, 'resetpwd');
|
|
|
- if (!$ret) {
|
|
|
- $this->error(__('Captcha is incorrect'));
|
|
|
- }
|
|
|
- Sms::flush($mobile, 'resetpwd');
|
|
|
- } else {
|
|
|
- if (!Validate::is($email, "email")) {
|
|
|
- $this->error(__('Email is incorrect'));
|
|
|
- }
|
|
|
- $user = \app\common\model\User::getByEmail($email);
|
|
|
- if (!$user) {
|
|
|
- $this->error(__('User not found'));
|
|
|
- }
|
|
|
- $ret = Ems::check($email, $captcha, 'resetpwd');
|
|
|
- if (!$ret) {
|
|
|
- $this->error(__('Captcha is incorrect'));
|
|
|
- }
|
|
|
- Ems::flush($email, 'resetpwd');
|
|
|
+
|
|
|
+ if (!Validate::is($email, "email")) {
|
|
|
+ $this->error(__('Email is incorrect'));
|
|
|
}
|
|
|
+ $user = \app\common\model\User::getByEmail($email);
|
|
|
+ if (!$user) {
|
|
|
+ $this->error(__('User not found'));
|
|
|
+ }
|
|
|
+ $ret = Ems::check($email, $captcha, 'resetpwd');
|
|
|
+ if (!$ret) {
|
|
|
+ $this->error(__('Captcha is incorrect'));
|
|
|
+ }
|
|
|
+ Ems::flush($email, 'resetpwd');
|
|
|
+
|
|
|
//模拟一次登录
|
|
|
$this->auth->direct($user->id);
|
|
|
$ret = $this->auth->changepwd($newpassword, '', true);
|