Rob Posted January 14, 2013 Share Posted January 14, 2013 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 More sharing options...
arjen Posted January 14, 2013 Share Posted January 14, 2013 I believe you have to disable Output Formatting: $u->setOutputFormatting(false); Link to comment Share on other sites More sharing options...
WillyC Posted January 14, 2013 Share Posted January 14, 2013 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(); 1 Link to comment Share on other sites More sharing options...
arjen Posted January 14, 2013 Share Posted January 14, 2013 Or that! Link to comment Share on other sites More sharing options...
Rob Posted January 15, 2013 Author Share Posted January 15, 2013 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 More sharing options...
arjen Posted January 15, 2013 Share Posted January 15, 2013 I'm sorry Rob, setOutputFormatting should only be used when modifying data. When creating a new user following WillyC's method there is no need. Link to comment Share on other sites More sharing options...
Rob Posted January 15, 2013 Author Share Posted January 15, 2013 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 More sharing options...
arjen Posted January 15, 2013 Share Posted January 15, 2013 Does this conversation between nik and ryan has something to do with it? 1 Link to comment Share on other sites More sharing options...
Rob Posted January 15, 2013 Author Share Posted January 15, 2013 Yes that looks like the case I've upgraded to the latest dev version and that seems to have fixed the problem. Thanks! 2 Link to comment Share on other sites More sharing options...
arjen Posted January 15, 2013 Share Posted January 15, 2013 Glad you figured it out! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now