1
This commit is contained in:
parent
618ab1ce61
commit
d67479e07b
36
doc/ActivationCode.py
Normal file
36
doc/ActivationCode.py
Normal file
@ -0,0 +1,36 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import _common
|
||||
|
||||
class ActivationCode(object):
|
||||
|
||||
def __init__(self):
|
||||
self.apis = [
|
||||
{
|
||||
'name': 'bindActivationCode',
|
||||
'desc': '绑定激活码',
|
||||
'group': 'ActivationCode',
|
||||
'url': 'webapp/index.php?c=ActivationCode&a=bindActivationCode',
|
||||
'params': [
|
||||
_common.ReqHead(),
|
||||
['code', 0, '激活码']
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
]
|
||||
},{
|
||||
'name': 'getActivationCodeBindState',
|
||||
'desc': '激活码绑定状态',
|
||||
'group': 'ActivationCode',
|
||||
'url': 'webapp/index.php?c=ActivationCode&a=getActivationCodeBindState',
|
||||
'params': [
|
||||
_common.ReqHead(),
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['state', 0, '1:已激活 0:未激活']
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
|
29
webapp/controller/ActivationCodeController.class.php
Normal file
29
webapp/controller/ActivationCodeController.class.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
require_once('models/ActivationCode.php');
|
||||
|
||||
use models\ActivationCode;
|
||||
use phpcommon\SqlHelper;
|
||||
class ActivationCodeController extends BaseAuthedController {
|
||||
|
||||
public function bindActivationCode(){
|
||||
$code = getReqVal('code', 0);
|
||||
if (!ActivationCode::verifyCode($code)){
|
||||
$this->_rspErr(1, "activation code error");
|
||||
return;
|
||||
}
|
||||
if (ActivationCode::verifyAccountBind()){
|
||||
$this->_rspErr(1, "The activation code has been bind");
|
||||
return;
|
||||
}
|
||||
ActivationCode::addBindCode($code);
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
public function getActivationCodeBindState(){
|
||||
$state = ActivationCode::verifyAccountBind() ? 1 :0;
|
||||
$this->_rspData(array(
|
||||
'state' => $state
|
||||
));
|
||||
}
|
||||
|
||||
}
|
@ -3,8 +3,54 @@
|
||||
|
||||
namespace models;
|
||||
|
||||
|
||||
class ActivationCode
|
||||
use mt;
|
||||
use phpcommon\SqlHelper;
|
||||
class ActivationCode extends BaseModel
|
||||
{
|
||||
public static function verifyCode($code){
|
||||
$row = SqlHelper::ormSelectOne(
|
||||
myself()->_getAccountMysql(),
|
||||
't_activation_code',
|
||||
array(
|
||||
'activation_code' => $code,
|
||||
)
|
||||
);
|
||||
if ($row){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function addBindCode($code){
|
||||
SqlHelper::upsert(
|
||||
myself()->_getAccountMysql(),
|
||||
't_activation_code_bind',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
),
|
||||
array(
|
||||
|
||||
),
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'activation_code' =>$code,
|
||||
'createtime' =>myself()->_getNowTime(),
|
||||
'modifytime' =>myself()->_getNowTime(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function verifyAccountBind(){
|
||||
$row = SqlHelper::ormSelectOne(
|
||||
myself()->_getAccountMysql(),
|
||||
't_activation_code_bind',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
)
|
||||
);
|
||||
if ($row){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user