鼠笼管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

198 lines
12 KiB

<?php
/**
* 鼠笼前台登录接口
* @author YS
* @version 1.0
*/
class Api_LoginController extends Ctrl_Api{
public $Usermodel;
public $POST;
public function init() {
$this->Usermodel = new UserModel();
$this->POST =json_decode(file_get_contents('php://input'),true);
}
/**
* 鼠笼系统登录接口
* @param $Username 用户名
* @param $Password 密码
* @param $type 用户类型
* @return
* {
* "errorcode": "200",
* "message": "登陆成功",
* "data": {
* "username": "用户名",
* "type": "1",用户类型
* "realname": "真实姓名",
* "faculties": "1",院系
* "specialized": "1",专业
* "group": "1",课题组
* "teacher": "1",导师
* "phone": "13566987478",手机号
* "status": "1",审核状态
* "is_delete": "0"是否删除
* }
* }
*/
public function indexAction(){
//用户名
$Username = empty($this->POST['Username'])||!isset($this->POST['Username'])? Tool_Fnc::apiMsg('账号密码错误', '500'):Tool_fnc::safe_string($this->POST['Username']);
//密码
$Password = empty($this->POST['Password'])||!isset($this->POST['Password'])? Tool_Fnc::apiMsg('账号密码错误', '500'):Tool_fnc::safe_string($this->POST['Password']);
$Type = empty($this->POST['Type'])||!isset($this->POST['Type'])? Tool_Fnc::apiMsg('选择人员类型', '500'):Tool_fnc::safe_string($this->POST['Type']);
$Userinfo = $this->Usermodel->field('*')->where("username='{$Username}' and type={$Type} and is_delete=0")->fRow();
empty($Userinfo)?Tool_Fnc::apiMsg('账号密码错误', '500'):$Userinfo;
$Userinfo['password']!=md5($Password.Yaf_Registry::get("config")->psd->default->appsecret)?Tool_Fnc::apiMsg('账号密码错误', '500'):$Userinfo['password'];
unset($Userinfo['password']);
$Userinfo['uid'] = $Userinfo['id'];
unset($Userinfo['id']);
if($Userinfo['status']!=1) Tool_Fnc::apiMsg('等待管理审核', '500');
Tool_Fnc::apiMsg('登陆成功', '200',$Userinfo);
}
/**
* 鼠笼系统注册接口
* @param username 用户名
* @param password 密码
* @param type 用户类型
* @param realname 用户类型
* @param faculties 用户类型
* @param specialized 用户类型
* @param group 用户类型
* @param teacher 用户类型
* @return
* {
* "errorcode": "200",
* "message": "注册成功",
* "data": {
* "username": "用户名",
* "password": "1",密码
* "type": "用户类型",
* "realname": "1",真实姓名
* "faculties": "1",院系
* "specialized": "1",专业
* "group": "1",课题组
* "teacher": "13566987478",导师
* }
* }
*/
public function registerAction(){
//用户名
$username = empty($this->POST['username'])||!isset($this->POST['username'])? Tool_Fnc::apiMsg('请输入用户名', '500'):Tool_fnc::safe_string($this->POST['username']);
//密码
$password = empty($this->POST['password'])||!isset($this->POST['password'])? Tool_Fnc::apiMsg('请输入密码', '500'):Tool_fnc::safe_string($this->POST['password']);
//用户类型
$type = empty($this->POST['type'])||!isset($this->POST['type'])? Tool_Fnc::apiMsg('请选择用户类型', '500'):Tool_fnc::safe_string($this->POST['type']);
//真实姓名
$realname = empty($this->POST['realname'])||!isset($this->POST['realname'])? Tool_Fnc::apiMsg('请输入真实姓名', '500'):Tool_fnc::safe_string($this->POST['realname']);
//院系
$faculties = empty($this->POST['faculties'])||!isset($this->POST['faculties'])? Tool_Fnc::apiMsg('请选择院系', '500'):Tool_fnc::safe_string($this->POST['faculties']);
//专业
$specialized = empty($this->POST['specialized'])||!isset($this->POST['specialized'])? Tool_Fnc::apiMsg('请选择专业', '500'):Tool_fnc::safe_string($this->POST['specialized']);
//课题组
$group = empty($this->POST['group'])||!isset($this->POST['group'])? Tool_Fnc::apiMsg('请选择课题组', '500'):Tool_fnc::safe_string($this->POST['group']);
//导师
$teacher = empty($this->POST['teacher'])||!isset($this->POST['teacher'])? Tool_Fnc::apiMsg('请选择导师', '500'):Tool_fnc::safe_string($this->POST['teacher']);
$phone = empty($this->POST['phone'])||!isset($this->POST['phone'])? Tool_Fnc::apiMsg('请输入手机号', '500'):Tool_fnc::safe_string($this->POST['phone']);
//查询用户名是否存在
$Userinfo = $this->Usermodel->field('*')->where("username='{$username}' and type={$type} and is_delete=0")->fRow();
if(!empty($Userinfo)) Tool_Fnc::apiMsg('当前选择人员类型已存在此用户名,请重新填写用户名', '500');
$data['username'] = $username;
$data['password'] = md5($password.Yaf_Registry::get("config")->psd->default->appsecret);
$data['realname'] = $realname;
$data['type'] = $type;
$data['faculties'] = $faculties;
$data['specialized'] = $specialized;
$data['group'] = $group;
$data['teacher'] = $teacher;
$data['phone'] = $phone;
$ret = $this->Usermodel->save($data);
if(!$ret) Tool_Fnc::apiMsg('注册失败', '500');
Tool_Fnc::apiMsg('注册成功,等待管理员审核通过', '200');
}
public function editinfoAction(){
$data['id'] = empty($this->POST['id'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['id'];
//用户名
$username = empty($this->POST['username'])||!isset($this->POST['username'])? Tool_Fnc::apiMsg('请输入用户名', '500'):Tool_fnc::safe_string($this->POST['username']);
//密码
// $password = empty($this->POST['password'])||!isset($this->POST['password'])? Tool_Fnc::apiMsg('请输入密码', '500'):Tool_fnc::safe_string($this->POST['password']);
//用户类型
// $type = empty($this->POST['type'])||!isset($this->POST['type'])? Tool_Fnc::apiMsg('请选择用户类型', '500'):Tool_fnc::safe_string($this->POST['type']);
//真实姓名
$realname = empty($this->POST['realname'])||!isset($this->POST['realname'])? Tool_Fnc::apiMsg('请输入真实姓名', '500'):Tool_fnc::safe_string($this->POST['realname']);
//院系
$faculties = empty($this->POST['faculties'])||!isset($this->POST['faculties'])? Tool_Fnc::apiMsg('请选择院系', '500'):Tool_fnc::safe_string($this->POST['faculties']);
//专业
$specialized = empty($this->POST['specialized'])||!isset($this->POST['specialized'])? Tool_Fnc::apiMsg('请选择专业', '500'):Tool_fnc::safe_string($this->POST['specialized']);
//课题组
$group = empty($this->POST['group'])||!isset($this->POST['group'])? Tool_Fnc::apiMsg('请选择课题组', '500'):Tool_fnc::safe_string($this->POST['group']);
//导师
$teacher = empty($this->POST['teacher'])||!isset($this->POST['teacher'])? Tool_Fnc::apiMsg('请选择导师', '500'):Tool_fnc::safe_string($this->POST['teacher']);
//查询用户名是否存在
$phone = empty($this->POST['phone'])||!isset($this->POST['phone'])? Tool_Fnc::apiMsg('请输入手机号', '500'):Tool_fnc::safe_string($this->POST['phone']);
$Userinfo = $this->Usermodel->field('*')->where("username='{$username}' and is_delete=0 and id!={$data['id']}")->fRow();
if(!empty($Userinfo)) Tool_Fnc::apiMsg('当前选择人员类型已存在此用户名,请重新填写用户名', '500');
$data['username'] = $username;
// $data['password'] = md5($password.Yaf_Registry::get("config")->psd->default->appsecret);
$data['realname'] = $realname;
// $data['type'] = $type;
$data['faculties'] = $faculties;
$data['specialized'] = $specialized;
$data['group'] = $group;
$data['teacher'] = $teacher;
$data['phone'] = $phone;
$ret = $this->Usermodel->save($data);
if(!$ret) Tool_Fnc::apiMsg('信息未变更', '500');
Tool_Fnc::apiMsg('编辑成功', '200');
}
public function sendcodeAction(){
$phone = empty($this->POST['phone'])||!isset($this->POST['phone'])? Tool_Fnc::apiMsg('请输入手机号', '500'):Tool_fnc::safe_string($this->POST['phone']);
// 验证系统是否存在该手机号
$userinfo = $this->Usermodel->field('username')->where("phone='{$phone}' and is_delete=0 and status=1")->fRow();
if(empty($userinfo)) Tool_Fnc::apiMsg('当前手机号不存在', '500');
// 短信接口
$accessKeyId = Yaf_Registry::get("config")->aliyun->sms->accessKeyId;
$smsModel = new SmscodeModel();
$accessKeySecret = Yaf_Registry::get("config")->aliyun->sms->accessKeySecret;
$signName = Yaf_Registry::get("config")->aliyun->sms->signName;
$templateCode = Yaf_Registry::get("config")->aliyun->sms->templateCode;
$sms = new AliyunSms($accessKeyId, $accessKeySecret, $signName, $templateCode);
$code = substr(str_shuffle('0123456789'),0,6);
$templateParam = array(
'code' => $code // 模板中变量的值
);
$result = $sms->sendSMS($phone, $templateParam);
if(!$result) Tool_Fnc::apiMsg('短信发送失败', '500');
$data['phone'] = $phone;
$data['code'] = $code;
$data['created'] = date("Y-m-d H:i:s",time());
$smsModel->save($data);
Tool_Fnc::apiMsg('短信发送成功', '200');
}
public function ValidationAction(){
$phone = empty($this->POST['phone'])||!isset($this->POST['phone'])? Tool_Fnc::apiMsg('请输入手机号', '500'):Tool_fnc::safe_string($this->POST['phone']);
$code = empty($this->POST['code'])||!isset($this->POST['code'])? Tool_Fnc::apiMsg('请输入验证码', '500'):Tool_fnc::safe_string($this->POST['code']);
$smsModel = new SmscodeModel();
$userinfo = $this->Usermodel->field('id')->where("phone='{$phone}' and is_delete=0 and status=1")->fRow();
$codedata = $smsModel->field('id')->where("phone='{$phone}' and code='{$code}' and status=0")->fRow();
if(empty($codedata))Tool_Fnc::apiMsg('验证码不正确', '500');
$codedata['status']=1;
$smsModel->save($codedata);
Tool_Fnc::apiMsg('验证成功', '200',$userinfo);
}
public function changePwdAction(){
$id = empty($this->POST['id'])||!isset($this->POST['id'])? Tool_Fnc::apiMsg('非法调用', '500'):Tool_fnc::safe_string($this->POST['id']);
$password = empty($this->POST['password'])||!isset($this->POST['password'])? Tool_Fnc::apiMsg('非法调用', '500'):Tool_fnc::safe_string($this->POST['password']);
$tpassword = empty($this->POST['tpassword'])||!isset($this->POST['tpassword'])? Tool_Fnc::apiMsg('非法调用', '500'):Tool_fnc::safe_string($this->POST['tpassword']);
if($password!=$tpassword) Tool_Fnc::apiMsg('两次密码不一致', '500');
$data['password'] = md5($password.Yaf_Registry::get("config")->psd->default->appsecret);
$data['id'] = $id;
if(!$this->Usermodel->update($data)){
Tool_Fnc::apiMsg('新密码与原密码一致', '500');
}
Tool_Fnc::apiMsg('修改成功', '200');
}
}