Jump to content

Register user from another PW instance


fredbob
 Share

Recommended Posts

Is it possible to create users from another ProcessWire instance.

 

This is my code for a registration page, it creates the user, but doesn't update it with the username, password and email.

I presume this is because $u is on the current page, and not in the instance, and when $u is saved its not updating it on the other instance.

I can't figure it out, if anyone has any ideas thy would be greatly appreciated. 

<?php
if ($input->post->submit) {
    $username = $sanitizer->username($input->post->username);
    $email = $sanitizer->email($input->post->email);
    $password = $input->post->password;
    
    echo $username;
    echo $email;

    $clientbp = new ProcessWire('/path/', 'http://domain.com');

    $u = $clientbp->wire(new User());
    $u->of(false);
    $u->name = $username;
    $u->email = $email;
    $u->pass = $password;
    $u->addRole("guest");
    $u->save();
    $u->of(true);
}
?>
<form action="./" accept-charset="UTF-8" autocomplete="off" method="post">
        <input type="text" name="username" placeholder="Username">
        <input type="text" name="email" placeholder="Email">
        <input type="password" name="password" placeholder="Password">
    <button type="submit" name="submit" value="register">Register</button>
</form>

 

Link to comment
Share on other sites

  • 3 weeks later...

That's likely the reason. Using the generator method instead of the normal constructor to create the user object should work, though I haven't tested it:

    $u = $clientbp->users->newUser();

 

Link to comment
Share on other sites

  • 4 months later...

I left this for a while, and have just come back to it.

@BitPoet That creates the user okay, but doesn't allow to change the name, email, pass etc (in my testing anyway), it just created the user with today's date and time.

For anyone who is interested, this is my solution.

$u = $pw2->wire(new User());
$u->of(false);
$u->name = $username;
$u->email = $email;
$u->pass = $password;
$u->addRole("client");
$u->admin_theme = ("AdminThemeUikit");
$u->save();
$u->of(true); 

Credit from 

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...