public function run() { $type = $this->getDataItem('type', null); $number = $this->getDataItem('number', null); if (empty($type) || empty($number) || !preg_match("/^1\\d{10}/", $number)) { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, ''); } // 验证手机号码是否存在 if (in_array($type, ['register', 'update_password', 'update_mobile'])) { $exist = UserBase::query()->where('user_account = :m:', ['m' => $number])->execute()->getFirst(); if ($type == 'register' && $exist == true) { $this->setResult(['id' => 0, 'success' => 2, 'errmsg' => '手机号码已经注册过了!']); return false; } if ($type == 'update_password' && $exist == false) { $this->setResult(['id' => 0, 'success' => 3, 'errmsg' => '手机号码还未注册!']); return false; } } $id = MobileSMS::Send($type, $number, $this->apiAccessToken->id); if ($id === false) { $this->setResult(['id' => 0, 'success' => 0, 'errmsg' => '发送失败,请重试!']); } else { $this->setResult(['id' => $id, 'success' => 1, 'errmsg' => '']); } }
public function run() { if (false == $this->verifyUserAuth()) { return false; } $mobile = $this->getDataItem('mobile', ''); //帐号 $smsCode = $this->getDataItem('sms_code', ''); //短信验证 $password = $this->getDataItem('password', ''); if (empty($mobile) || empty($smsCode) || empty($password)) { return $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, '缺少必传参数或者参数格式错误!'); } if ($this->userInfoByAccount($mobile)) { $this->setResult(['success' => 100, 'message' => '手机号码已经使用过了.']); return false; } if (!MobileSMS::Check('update_mobile', $smsCode, $mobile, $this->apiAccessToken->id)) { $this->setResult(['success' => 101, 'message' => '短信验证码错误']); return false; } $UserBase = UserBase::findFirst('user_id = ' . $this->getUserAuth()->userId); if ($UserBase->user_account) { return $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, '已经绑定过的账号无法初始化账号信息!'); } $UserBase->user_account = $mobile; $UserBase->bind_phone = $mobile; $UserBase->user_password = $this->hashPassword($password); if ($UserBase->save()) { $this->setResult(['success' => 1, 'message' => '绑定手机号码成功.']); } else { $this->setResult(['success' => 0, 'message' => '保存数据异常.']); } }
public function run() { $mobile = $this->getDataItem('mobile'); $password = $this->getDataItem('password'); $smsCode = $this->getDataItem('sms_code'); if (empty($mobile) || empty($password) || empty($smsCode)) { if (!$this->userInfoByAccount($mobile)) { $this->setResult(['success' => 0, 'message' => '手机号码不存在.']); return; } } if (!MobileSMS::Check('update_password', $smsCode, $mobile, $this->apiAccessToken->id)) { $this->setResult(['success' => 0, 'message' => '短信验证码错误.']); return; } $newPassword = $this->hashPassword($password); if (UserBase::SetPassword($mobile, $newPassword)) { $this->setResult(['success' => 1, 'message' => '']); } else { $this->setResult(['success' => 0, 'message' => '保存数据异常.']); } }
public function run() { $account = $this->getDataItem('account', 1); //帐号 $password = $this->getDataItem('password', 1); //密码 $nickname = Keyword::Filter($this->getDataItem('nickname', 1)); //昵称 $smsCode = $this->getDataItem('sms_code', ''); //短信验证 if ($this->userInfoByAccount($account)) { $this->setResult(['success' => $this->success, 'user_token' => $this->userToken, 'message' => '账户名已存在']); return; } if (!MobileSMS::Check('register', $smsCode, $account, $this->apiAccessToken->id)) { $this->setResult(['success' => $this->success, 'user_token' => $this->userToken, 'message' => '短信验证码错误']); return; } if (empty($password) || empty($nickname)) { $this->setResult(['success' => $this->success, 'user_token' => $this->userToken, 'message' => '密码和昵称不能为空']); return; } $this->userInfo = new UserBase(); $this->userInfo->user_account = $account; $this->userInfo->user_password = $this->hashPassword($password); $this->userInfo->user_nickname = $nickname; $this->userInfo->user_cover = $this->getConfig()->defaultCover; //'default.jpg'; if ($this->userInfo->save()) { $this->success = 1; $this->message = '注册成功'; $this->saveUserAuth($this->apiAccessToken->id, $this->userInfo->user_id); $this->userToken = $this->getUserAuth()->userToken; } else { $this->message = '注册失败'; $this->databaseErrorLog($this->userInfo); } $this->setResult(['success' => $this->success, 'user_token' => $this->userToken, 'message' => $this->message, 'user_id' => $this->userInfo->user_id]); }
public function run() { if (false == $this->verifyUserAuth()) { return false; } $mobile = $this->getDataItem('mobile', ''); //帐号 $smsCode = $this->getDataItem('sms_code', ''); //短信验证 if ($this->userInfoByAccount($mobile)) { $this->setResult(['success' => $this->success, 'message' => '手机号码已经使用过了.']); return false; } if (!MobileSMS::Check('update_mobile', $smsCode, $mobile, $this->apiAccessToken->id)) { $this->setResult(['success' => $this->success, 'message' => '短信验证码错误']); return false; } // 修改用户手机号码 if (UserBase::SetMobile($this->getUserAuth()->userId, $mobile)) { $this->setResult(['success' => 1, 'message' => '绑定手机号码成功.']); } else { $this->setResult(['success' => 0, 'message' => '保存数据异常.']); } }
public function run() { $account = $this->getDataItem('account', 1); //帐号 $password = $this->getDataItem('password', 1); //密码 $nickname = Keyword::Filter($this->getDataItem('nickname', 1)); //昵称 $smsCode = $this->getDataItem('sms_code', ''); //短信验证 if ($this->userInfoByAccount($account)) { $this->setResult(['success' => 101, 'user_token' => $this->userToken, 'message' => '账户名已存在']); return; } if (empty($password) || empty($nickname)) { $this->setResult(['success' => 103, 'user_token' => $this->userToken, 'message' => '密码和昵称不能为空']); return; } if (empty($smsCode)) { $this->setResult(['success' => 102, 'user_token' => $this->userToken, 'message' => '短信验证码必填']); return; } if (!MobileSMS::Check('register', $smsCode, $account, $this->apiAccessToken->id)) { $this->setResult(['success' => 102, 'user_token' => $this->userToken, 'message' => '短信验证码错误']); return; } $this->userInfo = new UserBase(); $this->userInfo->user_account = $account; $this->userInfo->user_password = $this->hashPassword($password); $this->userInfo->user_nickname = $nickname; $this->userInfo->user_cover = $this->getConfig()->defaultCover; //'default.jpg'; $this->userInfo->bind_phone = $account; if ($this->userInfo->save()) { $this->success = 1; $this->message = '注册成功'; $this->saveUserAuth($this->apiAccessToken->id, $this->userInfo->user_id); $this->userToken = $this->getUserAuth()->userToken; } else { $this->message = '注册失败'; $this->databaseErrorLog($this->userInfo); } if ($this->success == 1) { if ($model = UserBase::findFirst('user_id = ' . $this->userInfo->user_id)) { $info = $model->toArray(); } else { $info = []; } $info['user_mobile'] = $info['bind_phone']; $info['user_cover'] = $info['user_cover'] ? PicUrl::UserCover($info['user_cover'], $this->getDi()) : ''; // 获取城市信息 $SysAreaZipDistrictPhonecode = new SysAreaZipDistrictPhonecode(); $city = $SysAreaZipDistrictPhonecode->getOne($info['user_district']); $info['user_district'] = $city['FULL_NAME'] ?: ''; // 删除不要的字段 unset($info['user_account'], $info['user_password'], $info['user_state'], $info['user_addtime'], $info['is_manage']); $this->setResult(array_merge($info, ['success' => $this->success, 'user_token' => $this->userToken, 'message' => $this->message])); } else { $this->setResult(['success' => $this->success, 'user_token' => $this->userToken, 'message' => $this->message, 'user_id' => $this->userInfo->user_id]); } }