接口基类完善

This commit is contained in:
2017-11-10 11:31:22 +08:00
parent 4b020b8710
commit 477cd0b3ef
3 changed files with 88 additions and 25 deletions

View File

@@ -0,0 +1,35 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\Api\controller;
use app\common\controller\Api;
class Auth extends Api {
public function login(){
if (!$this->request->post('username')) {
$this->data['msg'] = "用户名不能为空!";
return $this->data;
}
if (!$this->request->post('password')) {
$this->data['msg'] = "密码不能为空!";
return $this->data;
}
$user = model('User')->feild('uid,username,password,salt')->where('username', $this->request->post('username'))->find();
if ($user['password'] === md5($this->request->post('password').$user['salt'])) {
$this->data['code'] = 1;
$user['access_token'] = authcode($user['uid'].'|'.$user['username'].'|'.$user['password'], 'ENCODE');
$this->data['data'] = $user;
}else{
$this->data['msg'] = "密码错误!";
}
return $this->data;
}
}

View File

@@ -12,14 +12,9 @@ use app\common\controller\Api;
class User extends Api {
public function login(){
//$this->data['code'] = 1;
return $this->data;
}
public function getuser(\think\Request $request){
public function getuser(){
$this->data['code'] = 1;
$this->data['data'] = db('Member')->where('uid', $request->param('uid'))->find();
$this->data['data'] = db('Member')->where('uid', $this->request->param('uid'))->find();
return $this->data;
}
}