UCenter注册流程拆解

调用注册方法

$uid = uc_user_register($_POST['username'], $_POST['password'], $_POST['email']);

uc_client/client.php

...
L:22
define('UC_API_FUNC', UC_CONNECT == 'mysql' ? 'uc_api_mysql' : 'uc_api_post');
...
L:300
function uc_user_register($username, $password, $email, $questionid = '', $answer = '', $regip = '') {
    return call_user_func(UC_API_FUNC, 'user', 'register', array('username'=>$username, 'password'=>$password, 'email'=>$email, 'questionid'=>$questionid, 'answer'=>$answer, 'regip' => $regip));
}

所以也就是调用了方法

uc_api_mysql('user', 'register', array(...))

找到对应方法

L:90
function uc_api_mysql($model, $action, $args=array()) {
    global $uc_controls;
    if(empty($uc_controls[$model])) {
        include_once UC_ROOT.'./lib/db.class.php';
        include_once UC_ROOT.'./model/base.php';
        include_once UC_ROOT."./control/$model.php";  //引入了./control/user.php
        eval("\$uc_controls['$model'] = new {$model}control();");
    }
    if($action{0} != '_') {
        $args = uc_addslashes($args, 1, TRUE);
        $action = 'on'.$action; //调用的方法动作为 onregister
        $uc_controls[$model]->input = $args;
        return $uc_controls[$model]->$action($args);
    } else {
        return '';
    }
}

uc_client/control/user.php

L:63
    function onregister() {
        $this->init_input();
        $username = $this->input('username');
        $password =  $this->input('password');
        $email = $this->input('email');
        $questionid = $this->input('questionid');
        $answer = $this->input('answer');
        $regip = $this->input('regip');

        if(($status = $this->_check_username($username)) < 0) { //L:226
            return $status;
        }
        if(($status = $this->_check_email($email)) < 0) { //L:238
            return $status;
        }
        $uid = $_ENV['user']->add_user($username, $password, $email, 0, $questionid, $answer, $regip); //方法在uc_client/model/user.php:129
        return $uid;
    }
...
L:226
    function _check_username($username) {
        $username = addslashes(trim(stripslashes($username)));
        if(!$_ENV['user']->check_username($username)) { //方法在uc_client/model/user.php:41
            return UC_USER_CHECK_USERNAME_FAILED;
        } elseif(!$_ENV['user']->check_usernamecensor($username)) {
            return UC_USER_USERNAME_BADWORD;
        } elseif($_ENV['user']->check_usernameexists($username)) {
            return UC_USER_USERNAME_EXISTS;
        }
        return 1;
    }
...
L:238
    function _check_email($email, $username = '') {
        if(empty($this->settings)) {
            $this->settings = $this->cache('settings');
        }
        if(!$_ENV['user']->check_emailformat($email)) {
            return UC_USER_EMAIL_FORMAT_ILLEGAL;
        } elseif(!$_ENV['user']->check_emailaccess($email)) {
            return UC_USER_EMAIL_ACCESS_ILLEGAL;
        } elseif(!$this->settings['doublee'] && $_ENV['user']->check_emailexists($email, $username)) {
            return UC_USER_EMAIL_EXISTS;
        } else {
            return 1;
        }
    }

uc_client/model/user.php

L:41
    function check_username($username) {...}
L:74
    function check_usernamecensor($username) {...}
L:87
    function check_usernameexists($username) {...}
L:92
    function check_emailformat($email) {...}
L:96
    function check_emailaccess($email) {...}
L:112
    function check_emailexists($email, $username = '') {...}
L:129
    function add_user($username, $password, $email, $uid = 0, $questionid = '', $answer = '', $regip = '') {...}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容