Browse Source

注册接口

master
xyiege 1 year ago
parent
commit
c1b2511f05
  1. 4
      app/api/common.php
  2. 8
      app/api/controller/Passport.php
  3. 14
      app/api/service/UserService.php

4
app/api/common.php

@ -1,8 +1,8 @@
<?php
/**
* 生成随机字符串
* make salt
* 随机盐值
* @param int $len
* @return string
*/
function makeSalt(int $len){
$ss = "abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";

8
app/api/controller/Passport.php

@ -40,13 +40,11 @@ class Passport extends ApiController{
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("登录成功");
if (($userInfo = $model->register($this->postData())) === false) {
return $this->renderError($model->getError() ?: '注册失败');
}
return $this->renderSuccess("注册成功");
}
}

14
app/api/service/UserService.php

@ -1,4 +1,5 @@
<?php
declare (strict_types=1);
namespace app\api\service;
use app\api\model\User;
@ -33,9 +34,10 @@ class UserService {
}
return false;
}
/**
* 注册用户
* @param array $arr 传递过来的注册数组
* @param array $arr
* @return bool
*/
public function register(array $arr){
// 密码加密
@ -45,9 +47,9 @@ class UserService {
$dtime =time();
$arr['create_time'] = $dtime;
$arr['update_time'] = $dtime;
$user = new User();
$user->save($arr);
return true;
// 保存
$model = new User;
$uid = $model->save($arr);
return isset($uid)?true:false;
}
}
Loading…
Cancel
Save