Example #1
0
 /**
  * @dataProvider getInValidateUsers
  */
 public function testAddInValidateUsers($phone, $name, $address, $password, $repassword, $img, $downlineID)
 {
     $data['phone'] = $phone;
     $data['nickname'] = $name;
     $data['address'] = $address;
     $data['password'] = $password;
     $data['repassword'] = $repassword;
     $data['img'] = $img;
     $data['downline_id'] = $downlineID;
     $table = new UserModel();
     $ret = $table->addUser($data);
     if (empty($data['phone'])) {
         $this->assertTrue('手机号码必须填写' == $table->getError()['phone']);
     } else {
         if (empty($data['nickname'])) {
             $this->assertTrue('昵称必须填写' == $table->getError()['nickname']);
         } else {
             if ($data['nickname'] == '手机号重复') {
                 $this->assertTrue('手机号码已被注册' == $table->getError()['phone']);
             } else {
                 if ($data['nickname'] == '密码不一致') {
                     $this->assertTrue('两次输入密码不一致' == $table->getError()['repassword']);
                 } else {
                     $this->assertTrue(is_numeric($ret));
                 }
             }
         }
     }
 }
Example #2
0
 public function login()
 {
     //header('content-type:text/html;charset=utf-8');
     $qq = new QQLogin(self::QQAppid, self::QQCallback, self::QQAppkey);
     $openId = $qq->getOpenId();
     $user = new UserModel();
     if ($row = $user->getUserByOpenId($openId)) {
         //echo 123;
         $_SESSION['qq'] = $row;
         header('location:' . $qq->state);
     } else {
         //echo 456;
         //var_dump($qq->state);
         $arr = $qq->getUserInfo();
         //var_dump($arr);
         $data['openId'] = $openId;
         $data['userName'] = Data::filter($arr['nickname'], 9);
         $data['face'] = $arr['figureurl_qq_1'];
         $data['source'] = 'QQ';
         //var_dump($data);
         $row = $user->addUser($data);
         //var_dump($row);
         //var_dump($qq->state);
         if ($row) {
             $array = $user->getUserByOpenId($openId);
             $_SESSION['qq'] = $array;
             header('location:' . $qq->state);
         } else {
             E('对不起,亲,注册失败了');
         }
     }
 }
Example #3
0
 /**
  * 注册
  */
 public function registerAction()
 {
     $username = trim($this->getRequest()->getPost('username', ''));
     $password = trim($this->getRequest()->getPost('password', ''));
     $email = trim($this->getRequest()->getPost('email', ''));
     //校验参数是否为空
     if (empty($username) || empty($password) || empty($email)) {
         $this->getView->assign('message', '参数不能为空');
         $this->getView->render('/user/index.phtml');
     }
     $userModel = new UserModel();
     //校验用户名是否存在
     $isExistUsername = $userModel->getUserByUsername($username);
     if ($isExistUsername) {
         $this->getView->assign('message', '用户名已存在');
         $this->getView->render('/user/index.phtml');
     }
     //校验邮箱是否存在
     $isExistEmail = $userModel->getUserByEmail($email);
     if ($isExistEmail) {
         $this->getView()->assign('message', '邮箱已存在');
         $this->getView()->render('/user/index.phtml');
     }
     //进行注册
     $flag = $userModel->addUser($username, $password, $email);
     //如果成功,登录返回首页
     if ($flag) {
         Yaf_Session::getInstance()->set('userId', $flag);
         $this->getView()->render('/index/index.phtml');
     } else {
         $this->getView()->assign('message', '注册失败');
         $this->getView()->render('/user/index.phtml');
     }
 }
Example #4
0
 private function addUser()
 {
     $data = array('name' => $_POST['name'], 'email' => $_POST['email'], 'type' => $_POST['type']);
     $model = new UserModel();
     $model->addUser($data);
     show_json();
 }
 public static function register()
 {
     $fields = self::get_fields();
     if (!self::validation($fields)) {
         return false;
     }
     if (!UserModel::addUser($fields)) {
         return false;
     }
     return true;
 }
 /**
  * @dataProvider getValidateUsers
  */
 public function testAddValidateUser($phone, $name, $address, $password, $repassword, $img, $downlineID)
 {
     $data['phone'] = $phone;
     $data['nickname'] = $name;
     $data['address'] = $address;
     $data['password'] = $password;
     $data['repassword'] = $repassword;
     $data['img'] = $img;
     $data['downline_id'] = $downlineID;
     $table = new UserModel();
     $ret = $table->addUser($data);
     $this->assertTrue(is_numeric($ret));
 }
 public static function ActionRegistration()
 {
     if (isset($_POST['login']) and isset($_POST['email']) and isset($_POST['password']) and isset($_POST['passwordConfirm']) and isset($_POST['g-recaptcha-response'])) {
         $login = Validator::clear($_POST['login']);
         $email = $_POST['email'];
         $password = $_POST['password'];
         $passwordConfirm = $_POST['passwordConfirm'];
         $userId = UserModel::addUser($login, $email, $password);
         $path = root . '/application/data/users/' . $userId;
         mkdir($path);
         copy(root . '/images/avatar.jpg', $path . '/avatar.jpg');
         UserModel::setUser($userId, $login, 1);
         exit(json_encode(['status' => 'ok']));
     }
     exit(json_encode(['status' => 'false']));
 }
Example #8
0
 $objUser = new UserModel(DB::GetDBH());
 // тест получения данных по ID
 //print_r ( $objUser->selectUserByID('30')->toArray() );
 // получаем структуру таблицы пользователей, для определения ID и доступных полей
 $arr = $objUser->getTableStructure()->toArray();
 echo '<br>' . "Структура таблицы" . '<br>';
 print_r($arr);
 echo '<br>';
 echo '<br>' . "тест создания пользователей" . '<br>';
 try {
     for ($i = 0; $i < 20; $i++) {
         $userArr = array();
         $userArr['login'] = "******" . $i;
         $userArr['nick'] = "userNick" . $i;
         $userArr['email'] = "user" . $i . "@mail.ru";
         echo "Новый пользователь создан, ID = " . $objUser->addUser($userArr) . '<br>';
     }
 } catch (Exception $e) {
     echo $e->getMessage() . '<br>';
 }
 echo '<br>' . "тест получения списка пользователей" . '<br>';
 try {
     foreach ($objUser->selectUsers()->toArray() as $userArray) {
         foreach ($userArray as $key => $val) {
             echo " [" . $key . " = " . $val . "] ";
         }
         echo '<br>';
     }
 } catch (Exception $e) {
     echo $e->getMessage() . '<br>';
 }
Example #9
0
/**
 * Upgrades a Version 19 version of the Yioop! database to a Version 20 version
 * This is a major upgrade as the user table have changed. This also acts
 * as a cumulative since version 0.98. It involves a web form that has only
 * been localized to English
 * @param object $db datasource to use to upgrade
 */
function upgradeDatabaseVersion20(&$db)
{
    if (!isset($_REQUEST['v20step'])) {
        $_REQUEST['v20step'] = 1;
    }
    $upgrade_check_file = WORK_DIRECTORY . "/v20check.txt";
    if (!file_exists($upgrade_check_file)) {
        $upgrade_password = substr(sha1(microtime() . AUTH_KEY), 0, 8);
        file_put_contents($upgrade_check_file, $upgrade_password);
    } else {
        $v20check = trim(file_get_contents($upgrade_check_file));
        if (isset($_REQUEST['v20step']) && $_REQUEST['v20step'] == 2 && (!isset($_REQUEST['upgrade_code']) || $v20check != trim($_REQUEST['upgrade_code']))) {
            $_REQUEST['v20step'] = 1;
            $data['SCRIPT'] = "doMessage('<h1 class=\"red\" >" . "v20check.txt not typed in correctly!</h1>')";
        }
    }
    switch ($_REQUEST['v20step']) {
        case "2":
            /** Get base class for profile_model.php*/
            require_once BASE_DIR . "/models/model.php";
            /** For ProfileModel::createDatabaseTables method */
            require_once BASE_DIR . "/models/profile_model.php";
            /** For UserModel::addUser method */
            require_once BASE_DIR . "/models/user_model.php";
            $profile_model = new ProfileModel(DB_NAME, false);
            $profile_model->db = $db;
            $save_tables = array("ACTIVE_FETCHER", "CURRENT_WEB_INDEX", "FEED_ITEM", "MACHINE", "MEDIA_SOURCE", "SUBSEARCH", "VERSION");
            $dbinfo = array("DBMS" => DBMS, "DB_HOST" => DB_HOST, "DB_USER" => DB_USER, "DB_PASSWORD" => DB_PASSWORD, "DB_NAME" => DB_NAME);
            $creation_time = microTimestamp();
            $profile = $profile_model->getProfile(WORK_DIRECTORY);
            $new_profile = $profile;
            $new_profile['AUTHENTICATION_MODE'] = NORMAL_AUTHENTICATION;
            $new_profile['FIAT_SHAMIR_MODULUS'] = generateFiatShamirModulus();
            $new_profile['MAIL_SERVER'] = "";
            $new_profile['MAIL_PORT'] = "";
            $new_profile['MAIL_USERNAME'] = "";
            $new_profile['MAIL_PASSWORD'] = "";
            $new_profile['MAIL_SECURITY'] = "";
            $new_profile['REGISTRATION_TYPE'] = 'disable_registration';
            $new_profile['USE_MAIL_PHP'] = true;
            $new_profile['WORD_SUGGEST'] = true;
            $profile_model->updateProfile(WORK_DIRECTORY, $new_profile, $profile);
            //get current users (assume can fit in memory and doesn't take long)
            $users = array();
            $sha1_of_upgrade_code = bchexdec(sha1($v20check));
            $temp = bcpow($sha1_of_upgrade_code . '', '2');
            $zkp_password = bcmod($temp, $new_profile['FIAT_SHAMIR_MODULUS']);
            $user_tables_sql = array("SELECT USER_NAME FROM USER", "SELECT USER_NAME, FIRST_NAME, LAST_NAME, EMAIL FROM USERS");
            $i = 0;
            foreach ($user_tables_sql as $sql) {
                $result = $db->execute($sql);
                if ($result) {
                    while ($users[$i] = $db->fetchArray($result)) {
                        $setup_user_fields = array();
                        if ($users[$i]["USER_NAME"] == "root" || $users[$i]["USER_NAME"] == "public") {
                            continue;
                        }
                        $users[$i]["FIRST_NAME"] = isset($users[$i]["FIRST_NAME"]) ? $users[$i]["FIRST_NAME"] : "FIRST_{$i}";
                        $users[$i]["LAST_NAME"] = isset($users[$i]["LAST_NAME"]) ? $users[$i]["LAST_NAME"] : "LAST_{$i}";
                        $users[$i]["EMAIL"] = isset($users[$i]["EMAIL"]) ? $users[$i]["EMAIL"] : "user{$i}@dev.null";
                        /* although not by default using zkp set up so
                              accounts would work on switch
                           */
                        $users[$i]["PASSWORD"] = $v20check;
                        $users[$i]["STATUS"] = INACTIVE_STATUS;
                        $users[$i]["CREATION_TIME"] = $creation_time;
                        $users[$i]["UPS"] = 0;
                        $users[$i]["DOWNS"] = 0;
                        $users[$i]["ZKP_PASSWORD"] = $zkp_password;
                        $i++;
                    }
                    unset($users[$i]);
                    $result = NULL;
                }
            }
            $dbinfo = array("DBMS" => DBMS, "DB_HOST" => DB_HOST, "DB_USER" => DB_USER, "DB_PASSWORD" => DB_PASSWORD, "DB_NAME" => DB_NAME);
            $profile_model->initializeSql($db, $dbinfo);
            $database_tables = array_diff(array_keys($profile_model->create_statements), $save_tables);
            $database_tables = array_merge($database_tables, array("BLOG_DESCRIPTION", "USER_OLD", "ACCESS"));
            foreach ($database_tables as $table) {
                if (!in_array($table, $save_tables)) {
                    $db->execute("DROP TABLE " . $table);
                }
            }
            if ($profile_model->migrateDatabaseIfNecessary($dbinfo, $save_tables)) {
                $user_model = new UserModel(DB_NAME, false);
                $user_model->db = $db;
                foreach ($users as $user) {
                    $user_model->addUser($user["USER_NAME"], $user["PASSWORD"], $user["FIRST_NAME"], $user["LAST_NAME"], $user["EMAIL"], $user["STATUS"], $user["ZKP_PASSWORD"]);
                }
                $user = array();
                $user['USER_ID'] = ROOT_ID;
                $user['PASSWORD'] = $v20check;
                $user["ZKP_PASSWORD"] = $zkp_password;
                $user_model->updateUser($user);
                $db->execute("DELETE FROM VERSION WHERE ID < 19");
                $db->execute("UPDATE VERSION SET ID=20 WHERE ID=19");
                return;
            }
            $data['SCRIPT'] = "doMessage('<h1 class=\"red\" >" . "Couldn't migrate database tables from defaults!</h1>')";
        case "1":
        default:
            ?>
            <!DOCTYPE html>
            <html lang='en-US'>
            <head>
            <title>Yioop Upgrade Detected</title>
            <meta name="ROBOTS" content="NOINDEX,NOFOLLOW" />
            <meta name="Author" content="Christopher Pollett" />
            <meta charset="utf-8" />
            <?php 
            if (MOBILE) {
                ?>
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <?php 
            }
            ?>
            <link rel="stylesheet" type="text/css"
                 href="<?php 
            e(BASE_URL);
            ?>
/css/search.css" />
            </head>
            <body class="html-ltr <?php 
            if (MOBILE) {
                e('mobile');
            }
            ?>
" >
            <div id="message" ></div>
            <div class='small-margin-current-activity'>
            <h1 class='center green'>Yioop Upgrade Detected!</h1>
            <p>Upgrading to Version 1 of Yioop from an earlier version
            is a major upgrade. The way passwords are stored and the
            organization of the Yioop database has changed. Here is
            what is preserved by this upgrade:</p>
            <ol>
            <li>Existing crawls and archive data.</li>
            <li>Machines known if this instance is a name server.</li>
            <li>Media sources and subsearches.</li>
            <li>Feed items.</li>
            </ol>
            <p>Here is what happens during the upgrade which might
            result in data loss:</p>
            <ol>
            <li>Root and user account passwords are changed to the contents of
            v20check.txt.</li>
            <li>User accounts other than root are marked as inactived,
            so will have tobe activated under Manage Users before that person
            can sign in.</li>
            <li>All roles except Admin and User are deleted. Root
            will be given Admin role, all other users will receive
            User role.</li>
            <li>All existing groups are deleted.</li>
            <li>Existing crawl mixes will be deleted.</li>
            <li>Any customized translations that begin with the prefix db_.
            Other still in use translations will be preserved.</li>
            </ol>
            <p>If given the above you don't want to upgrade, merely replace
            this folder with the contents of your old Yioop instance and
            you should be able to continue to use Yioop as before.</p>
            <p>If you decide to proceed with the upgrade, please back up
            both your existing database and work directory.</p>
            <form method="post" action="?">
            <p><label for="upgrade-code">
            <b>In the field below enter the string found in the file:<br />
            <span class="green"><?php 
            e(WORK_DIRECTORY . "/v20check.txt");
            ?>
</span>
            </b></label></p>
            <input id='upgrade-code' class="extra-wide-field"
                name="upgrade_code" type="text" />
            <input type="hidden" name="v20step" value="2" />
            <button class="button-box" type="submit">Upgrade</button>
            </form>
            <?php 
            break;
    }
    ?>
    </div>
    <script type="text/javascript" src="<?php 
    e(BASE_URL);
    ?>
/scripts/basic.js" ></script>
    <script type="text/javascript" >
    <?php 
    if (isset($data['SCRIPT'])) {
        e($data['SCRIPT']);
    }
    ?>
</script>
    </body>
    </html>
   <?php 
    exit;
}
Example #10
0
/** For UserModel::addUser method*/
require_once BASE_DIR . "/models/user_model.php";
/** To create groups that can add users to */
require_once BASE_DIR . "/models/group_model.php";
/** To create roles that can add users to */
require_once BASE_DIR . "/models/role_model.php";
/** To create a set of crawl mixes */
require_once BASE_DIR . "/models/crawl_model.php";
/** For crawlHash function */
require_once BASE_DIR . "/lib/utility.php";
$user_model = new UserModel();
//Add lots of users
$user_ids = array();
for ($i = 0; $i < 500; $i++) {
    echo "Adding User {$i}\n";
    $id = $user_model->addUser("User{$i}", "test", "First{$i}", "Last{$i}", "user{$i}@email.net", ACTIVE_STATUS);
    if ($id === false) {
        echo "Problem inserting user into DB, aborting...\n";
        exit(1);
    }
    $user_ids[$i] = $id;
}
// add lots of groups
$group_model = new GroupModel();
$group_ids = array();
for ($i = 0; $i < 100; $i++) {
    echo "Creating Group {$i}\n";
    $group_ids[$i] = $group_model->addGroup("Group{$i}", $user_ids[$i], PUBLIC_JOIN, GROUP_READ_WRITE);
}
// add lots of users to group 1
for ($i = 0; $i < 100; $i++) {