Codeigniter/PHP:使用 TankAuth 批量创建用户

发布于 2024-10-15 05:55:51 字数 1359 浏览 5 评论 0原文

我有兴趣使用 TankAuth for CodeIgniter 批量创建批量用户/密码。我在 CI 论坛上问了这个问题,但没有得到回复:

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:

以防万一有人正在寻找解决方案,这里有一个与我基本相同的功能使用(还有一些其他参数,但这应该可以帮助您继续):

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() 即可将其付诸实践!

I am interested in creating bulk users/passwords in a batch using TankAuth for CodeIgniter. I asked this question on the CI forums but got no responses:

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

Google searches don't turn up much besides my thread as the third result and a bunch of unrelated sites.

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

Has anyone successfully done this using a recursion algorithm? If so, can you post some code to get me going on the right path? Thanks!

Versions of software:

CI 1.7.3

TankAuth 1.0.7

PHP 5.x

EDIT 2/15:

Just in case anyone is looking for a solution to this, here's a function that is basically the same one I used (there were some other parameters, but this should get you going):

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>";
    }

}

Just ping batchReg() from the controller to put it into action!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以心动 2024-10-22 05:55:51

对我来说,听起来像是一个简单的循环操作

(无论来源如何)以可迭代的形式(如数组$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 包含您用户的所有新密码。

Sounds like a simple loop operation to me

somehow (whatever the source) get your usernames in a iterable form like an array $user_list

we'll say it looks like this

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

Then create a simple looping routine to process the new registrations, storing the password back into the array, so you will then have a complete list of logins, new (randomized) passwords and emails.

//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);
}

Then at the end your $user_list contains all the new passwords for your users.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文