2011-02-01 37 views
0

我有興趣使用TankAuth for CodeIgniter批量創建批量用戶/密碼。我問的CI論壇這個問題,但沒有得到答覆:Codeigniter/PHP:使用TankAuth批量創建用戶

http://codeigniter.com/forums/viewthread/110993/P330/#837327

谷歌搜索不露面太多,除了我的線程作爲第三結果和一堆不相關的網站。

http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=create+batch+users+tankauth

有沒有人成功地做到了這一點使用遞歸算法?如果是這樣,你可以發佈一些代碼讓我走上正確的道路嗎?謝謝!軟件

版本:

CI 1.7.3

TankAuth 1.0.7

PHP 5.x的

編輯2/15:

以防萬一任何人都在尋找解決方案,這裏有一個基本上與我使用的相同的功能(還有一些其他參數s,但這應該讓你去):

function batchReg() 
{ 
    $this->load->model('mymodel'); 

    // connect to the database 
    $this->mymodel->dbconnect(); 

    // build it 
    $query = "SELECT user, email, pass from newusers ORDER BY user ASC"; 

    // ship it 
    $result = mysql_query($query); 

    // loop it 
    while ($row = mysql_fetch_array($result)) 
    { 
     $data = $this->tank_auth->create_user($row['user'], $row['email'], $row['pass'], FALSE); 
     print_r($data); 
     echo "<p>"; 
    } 

} 

只需ping從控制器batchReg()將其付諸行動!

+0

隨機用戶名和隨機密碼?或者你有一個清單嗎? – jondavidjohn 2011-02-01 22:49:47

+0

我有一個列表。 Ilya(TankAuth的創建者)迴應如下: 「新用戶正在通過調用庫的create_user方法進行註冊(controller auth.php,第149行)。要爲一羣用戶創建登錄,您必須從數據庫中逐一檢索它們,併爲其中的每個人調用此方法,該方法具有以下參數:用戶登錄,電子郵件,密碼和電子郵件激活標誌(具有通過單擊特殊鏈接確認的電子郵件)。 我打算在接下來的幾天裏嘗試寫一個腳本;如果我成功的話,我會更新這張票。 – 2011-02-01 23:13:39

回答

3

聽起來像一個簡單的循環操作來我

不知何故(不論來源)讓你的用戶名在迭代形式類似於數組$user_list

我們會說,它看起來像這樣

Array(
    Array(
     [username] => '...', 
     [email] => '...', 
     [password] => '',  //leave password empty 
    ), 
    Array(
     [username] => '...', 
     [email] => '...', 
     [password] => '',  //leave password empty 
    ), 
    ... etc. 
) 

然後創建一個簡單的循環例程來處理新的註冊,將密碼存回陣列,這樣你就可以得到一個完整的登錄列表,新的(隨機)密碼和電子郵件列表。

//loop by referance in order to properly store the generated password 
foreach($user_list as &$user) { 

    //generate 8 char password and store it 
    $user['password'] = substr(uniqid(),2,8); 

    //run register routine (not sure on tank auth's specific syntax 
    $this->tankauth->register($user['username'],$user['email'],$user['password'],FALSE); 
} 

那麼,在年底你$user_list包含所有用戶新密碼。