Commit 78039aee by 庄钊鑫

完整注册模块登录模块

parent 5b1320a3
......@@ -93,6 +93,7 @@ class Send extends Base
if ($info === false) {
$this->returnmsg(403, [], [], "", [], "验证码错误");
}
$this->render(200,['success'=>'验证码正确']);
$success['success']['message'] = '验证码正确!';
$this->render(200,$success);
}
}
......@@ -3,12 +3,13 @@
namespace app\api\controller\v1\app;
use app\api\controller\Api;
use app\api\model\UserToken;
use app\api\model\Token;
use app\common\tools\wechatUtil;
use think\Db;
use app\api\logic\app\SendLogic;
use app\api\model\User as UserModel;
use app\api\logic\app\UserLogic;
use think\Cache;
/**
* 所有资源类接都必须继承基类控制器
......@@ -96,16 +97,11 @@ class User extends Base
*/
public function login()
{
$requestData = $this->selectParam(['mobile', 'code','oauth_uuid'=>""]);
$this->check($requestData, 'Base.login');
$requestData['sms_type'] = 'login';
$bool = SendLogic::validateCode($requestData);
if (!$bool) {
self::returnmsg(403, [], [], 'service_message', 'code error.', '验证码错误');
}
$result = UserModel::build()->login($requestData['mobile'],$requestData['oauth_uuid']);
$requestData = $this->selectParam(['mobile', 'password']);
$this->check($requestData, 'Base.cmsLogin');
$result = UserModel::build()->login($requestData);
if ($result) {
$this->render($result);
$this->render(200,$result);
} else {
$this->returnmsg(403, $data = [], $header = [], $type = "", "Login error", $message = "登录失败");
}
......@@ -166,9 +162,14 @@ class User extends Base
*/
public function validateMobile()
{
$requestData = $this->selectParam(['mobile','sms_type' => 'bind']);
$this->check($requestData, 'Base.sendSms');
$this->render(200,['success'=>'手机号码验证成功']);
$request = $this->selectParam(['mobile','sms_type' => 'bind']);
$this->check($request, 'Base.sendSms');
$bool = UserLogic::checkUser($request['mobile']);
if(!empty($bool)){
$this->returnmsg(403, [], [],"", [], "该手机号已注册");
}
$success['success']['message'] = '手机号码验证成功';
$this->render(200,$success);
}
/**
......@@ -190,13 +191,18 @@ class User extends Base
$this->returnmsg(403, [], [],"", [], "该手机号已注册");
}
}
//$info = true;
$info = SendLogic::SendSms($request['mobile'], $request['sms_type']);
if ($info === false) {
$this->returnmsg(403, [], [],"", [], "信息发送出现了一点小问题哟~");
$tokenId = md5(md5(time()));
Cache::set($tokenId,$request['mobile'],1800);
if(Cache::get($tokenId)){
$info = true;
//$info = SendLogic::SendSms($request['mobile'], $request['sms_type']);
if ($info === false) {
$this->returnmsg(403, [], [],"", [], "信息发送出现了一点小问题哟~");
}
$success['success']['token'] = $tokenId;
$success['success']['message'] = '验证码发送成功';
$this->render(200,$success);
}
//发送成功
$this->render(200,['success'=>'验证码发送成功']);
}
/**
......@@ -209,15 +215,21 @@ class User extends Base
*/
public function register()
{
$request = $this->selectParam(['mobile', 'password','password2']);
$request = $this->selectParam(['mobile', 'password','password2','token']);
$this->check($request, 'Base.register');
$result = Token::validateToken2($request['token'],$request['mobile']);
if($result['status'] == 0){
$this->returnmsg(403, [], [],"", [], $result['message']);
}
$bool = UserLogic::checkUser($request['mobile']);
if(!empty($bool)){
$this->returnmsg(403, [], [],"", [], "该手机号已注册");
}
$result = UserModel::build()->register($request);
if ($result) {
$this->render(200,['success'=>'注册成功!']);
Cache::rm($request['token']);
$success['success']['message'] = '注册成功!';
$this->render(200,$success);
} else {
$this->returnmsg(403, $data = [], $header = [], $type = "", "Login error", $message = "注册失败");
}
......
......@@ -3,16 +3,16 @@
namespace app\api\model;
use think\Model;
use think\Cache;
/**
* TOKEN
*/
class UserToken extends Model
class Token extends Model
{
/**
* 表名
*/
protected $table = 'user_token';
protected $table = 'token';
protected $dateFormat = false;
/**
......@@ -55,6 +55,30 @@ class UserToken extends Model
}
/**
* @author:
* @time: 2019年3月
* description
* @param $token
* @return array|bool|false|\PDOStatement|string|Model
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function validateToken2($tokenId,$mobile)
{
$getMobile = Cache::get($tokenId);
if($getMobile){
if($getMobile == $mobile){
return ['status' => 1];
}else{
return ['status' => 0,'message' => '手机号码不一致!'];
}
}
return ['status' => 0,'message' => 'token已失效!'];
}
/**
* @author: Airon
* @time: 2018年5月
* description
......
......@@ -37,55 +37,32 @@ class User extends Model
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function login($mobile,$oauth_uuid)
public function login($requestData)
{
$user = self::build()->where(['mobile' => $mobile])
->field(['nickname','is_deleted','ban_time'],true)->find();
$user = self::build()->where(['mobile' => $requestData['mobile'],'password' => md5(md5($requestData['password']))])
->field(['password'],true)->find();
Db::startTrans();
if ($user) {
if ($user['is_banned']) {
ResponseDirect('当前账号已被禁用',403);
}
if(!empty($oauth_uuid)){
$oauth= UserOauth::build()->where(['uuid'=>$oauth_uuid])->find();
if(!empty($oauth)){
UserOauth::build()->where(['user_uuid'=>$user['uuid']])->update(['user_uuid'=>""]);
UserOauth::build()->where(['uuid'=>$oauth_uuid])->update(['user_uuid'=>$user['uuid']]);
}
}
$token = UserToken::storeToken($user['uuid']);
} else {
//创建新用户
$user['uuid'] = uuid();
$user['mobile'] = $mobile;
$user['name'] = replaceToStar($mobile);
$user['create_time'] = timeToDate(time());
// $user['invite_code'] = $this->get_unique_invite_code();
$result = self::build()->insert($user);
if ($result) {
//创建token
$token = UserToken::storeToken($user['uuid']);
if(!empty($oauth_uuid)){
$oauth= UserOauth::build()->where(['uuid'=>$oauth_uuid])->find();
if(!empty($oauth)){
UserOauth::build()->where(['uuid'=>$oauth_uuid])->update(['user_uuid'=>$user['uuid']]);
}
}
} else {
Db::rollback();
return false;
}
// if ($user['is_banned']) {
// ResponseDirect('当前账号已被禁用',403);
// }
// if(!empty($oauth_uuid)){
// $oauth= UserOauth::build()->where(['uuid'=>$oauth_uuid])->find();
// if(!empty($oauth)){
// UserOauth::build()->where(['user_uuid'=>$user['uuid']])->update(['user_uuid'=>""]);
// UserOauth::build()->where(['uuid'=>$oauth_uuid])->update(['user_uuid'=>$user['uuid']]);
//
// }
// }
$token = Token::storeToken($user['uuid']);
}else{
return false;
}
Db::commit();
$users['token'] = $token;
$users['user_info'] = self::build()
->where(['mobile'=>$mobile])
->field(['nickname','is_deleted','ban_time'],true)
->where(['mobile' => $requestData['mobile'],'password' => md5(md5($requestData['password']))])
->field(['name'],false)
->find();
return $users;
......@@ -107,6 +84,7 @@ class User extends Model
$user['mobile'] = $request['mobile'];
$user['name'] = replaceToStar($request['mobile']);
$user['create_time'] = timeToDate(time());
$user['password'] = md5(md5($request['password']));
$result = self::build()->insert($user);
if (!$result) {
Db::rollback();
......@@ -117,4 +95,6 @@ class User extends Model
return true;
}
}
\ No newline at end of file
......@@ -23,8 +23,8 @@ class Base extends Validate
'sms_type' => 'require|in:login,bind,pay_password,pass',
'partner_sms_type' => 'require|in:pass,set_pay,bind_card',
'code' => 'require|max:6',
'password' => 'require|min:6|confirm:password2',
'password2' => 'require',
'password' => 'require|min:6',
'password2' => 'require|confirm:password',
'message_type' => 'require|in:con,chat,system',
'province' => 'chsAlpha',
'school_name' => 'chsAlpha',
......@@ -38,7 +38,7 @@ class Base extends Validate
'keyword' => 'chsDash',
'refresh_token' => 'require|length:32',
'collect_type' => 'require|in:school,speciality',
'token' => 'require',
'name' => 'require|chsAlphaNum|length:0,64',
'gender' => 'require|in:男,女',
'birth' => 'require|chsAlphaNum|length:0,64',
......@@ -62,7 +62,8 @@ class Base extends Validate
'code' => '验证码格式错误',
'password.require' => '密码必须',
'password.min' => '密码过短',
'password.confirm' => '两次密码输入不一致',
'password2.confirm' => '两次密码输入不一致',
'token.require' => 'token必须',
'message_type' => '消息类型错误',
'province' => '省份设置错误',
'city.json' => '城市设置错误',
......@@ -88,7 +89,7 @@ class Base extends Validate
'id' => ['id'],
'uuid' => ['uuid'],
'sendSms' => ['mobile', 'sms_type'],
'register' => ['mobile','password','password2'],
'register' => ['mobile','password','password2','token'],
'sendPartnerSms' => ['mobile', 'sms_type_partner'],
'validatePartnerCode' => ['mobile', 'sms_type_partner', 'code'],
......@@ -103,7 +104,7 @@ class Base extends Validate
'refresh_token' => ['refresh_token'],
'feedback' => ['content'],
'collect_list' => ['collect_type'],
'cmsLogin' => ['name', 'password'],
'cmsLogin' => ['mobile', 'password'],
'admissionScore' => ['province','school_name'],
'batchCritical' => ['province']
......
<?php
//000000001800
exit();?>
s:11:"13302516724";
\ No newline at end of file
<?php
//000000001800
exit();?>
s:32:"1d6874d9fa1c1288e3cf7ed27fca63d2";
\ No newline at end of file
<?php
//000000001800
exit();?>
s:11:"13302516724";
\ No newline at end of file
<?php
//000000001800
exit();?>
s:32:"062a1c9363e70287295731c632e8efba";
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment