-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force create of admin user. #4604
Conversation
There is a conflict with eg. Spark. Users can't set the password during create. I changed to `forceCreate` and added a check if the user exists already. I hope that fixes the issue for the future 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never used Spark so not sure what's the problem but you should move your check.
src/Commands/AdminCommand.php
Outdated
@@ -123,6 +123,13 @@ protected function getUser($create = false) | |||
|
|||
// If we need to create a new user go ahead and create it | |||
if ($create) { | |||
// check if user with given email exists | |||
$User = $model::where('email', $email)->first(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should move this check later on because at this point you might still not have the email.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it further down, after the check for the email.
Ensure that the command asked for the email before running the check.
@@ -2,12 +2,13 @@ | |||
|
|||
namespace TCG\Voyager\Commands; | |||
|
|||
use App\User; | |||
use Illuminate\Support\Str; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid committing changes like these (rearranging "use" statements). They provide no benefit, and simply make StyleCI unhappy. I realize it likely wasn't intentional, so don't worry about it. StyleCI will auto-fix it after merge anyway.
src/Commands/AdminCommand.php
Outdated
@@ -2,12 +2,13 @@ | |||
|
|||
namespace TCG\Voyager\Commands; | |||
|
|||
use App\User; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to include this line. You're not using it anywhere, and it's not guaranteed to exist.
src/Commands/AdminCommand.php
Outdated
@@ -131,6 +132,13 @@ protected function getUser($create = false) | |||
if (!$email) { | |||
$email = $this->ask('Enter the admin email'); | |||
} | |||
|
|||
// check if user with given email exists | |||
$User = $model::where('email', $email)->first(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use lowercase (camel-case, though it doesn't matter here) for variable names.
Also, can't you use ->exists()
on the model instead since you're not using the object anywhere. This will allow you to combine this line with the conditional below it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. Updated it.
src/Commands/AdminCommand.php
Outdated
|
||
// check if user with given email exists | ||
$User = $model::where('email', $email)->first(); | ||
if ($User) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
Codecov Report
@@ Coverage Diff @@
## 1.4 #4604 +/- ##
============================================
- Coverage 62.96% 62.91% -0.05%
- Complexity 1372 1374 +2
============================================
Files 194 194
Lines 4007 4010 +3
============================================
Hits 2523 2523
- Misses 1484 1487 +3
Continue to review full report at Codecov.
|
Baam ... half a year later it is merged ... Not sure if I should party or complain 😅 |
Sorry for the long delay, but we are quite busy with v2 at the moment. |
There is a conflict with eg. Spark. Users can't set the password during create. I changed to
forceCreate
and added a check if the user exists already. I hope that fixes the issue for the future 😃