diff --git a/app/api/common.php b/app/api/common.php new file mode 100644 index 0000000..8ebffca --- /dev/null +++ b/app/api/common.php @@ -0,0 +1,14 @@ +renderSuccess([ 'userId' => $userInfo['uid'], 'token' => $model->getToken() - ], '登录成功'); + ], ''); } + + /** + * 用户注册 + * @return Json + */ + public function register():Json + { + if (!$this->request->isPost()) { + return $this->renderError('不支持GET请求'); + } + $data = $this->postData(); + $model = new UserService; + // + $data = $this->postData(); + if (($userInfo = $model->register($data['uname'],$data['upass'])) === false) { + return $this->renderSuccess("登录成功"); + } + } + } \ No newline at end of file diff --git a/app/api/service/UserService.php b/app/api/service/UserService.php index 3b4da7a..e41e670 100644 --- a/app/api/service/UserService.php +++ b/app/api/service/UserService.php @@ -33,4 +33,21 @@ class UserService { } return false; } +/** + * 注册用户 + * @param array $arr 传递过来的注册数组 + */ + public function register(array $arr){ + // 密码加密 + $arr['password'] = password($arr['password']); + // 生成salt + $arr['salt'] = makeSalt(6); + $dtime =time(); + $arr['create_time'] = $dtime; + $arr['update_time'] = $dtime; + + $user = new User(); + $user->save($arr); + return true; + } } \ No newline at end of file