Jump to content

Setting password via api


Rob
 Share

Recommended Posts

I have been experimenting with using the API when in PHP interactive mode, as it seems it can be a lot quicker for some tasks and also a good way to recover in the event of DB problems/corruption and other problems.

So I tried to create a user purely on command-line with the following series of commands, each typed in series in PHP interactive mode.

include "admin/index.php";
wire('users')->add('testuser1');
$u = wire('users')->get('testuser1');
$u->pass = 'test123';
$u->addRole('superuser');
$u->save();

What I was expecting, at this point, was to be able to log into the CMS web interface with the above credentials, but it rejects me.

Is there anything I'm doing wrong?  I logged in with another user and confirmed that the user had been created and had a superuser role assigned.

I am somewhat stumped!

Link to comment
Share on other sites

why u.use add.whens you no take result

u.try this?

$u = wire('users')->add('testuser1');
$u->pass = 'test123';
$u->addRole('superuser');
$u->save();

or.this

$u = new User();
$u->name = 'testuser1';
$u->pass = 'test123';
$u->save();
  • Like 1
Link to comment
Share on other sites

Thanks for the help gentlemen, but no luck yet!

I tried this...

$u = new User();
$u->setOutputFormatting(false);
$u->name = 'testuser';
$u->addRole('superuser');
$u->pass = 'test123';
$u->save();

...and yet again the user is created and is displayed, with correct superuser role, in the CMS, but I cannot log in with it.

Worth mentioning - I am using version 2.2.9.

This is going to drive me mad!

Link to comment
Share on other sites

The plot thickens....

I created a user in the CMS and I can't login with that one either.

I have created new users this way before (through CMS) and had no problems, so I can't think what the problem could be.

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...