-
Notifications
You must be signed in to change notification settings - Fork 145
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
Fixed a few field entries #116
Conversation
These would not save otherwise.
Wouldn’t save when importing from phpvms classic.
Change arguments to ask in terminal Fixed table_prefix names in Importer.php Added the ability to import users from phpvms classic (tested on simpilot’s 5.5.x) and when importing, it will then reset the user’s password to a temporary hash and then email it to the user to then change when they first log in.
And also, could you check this commit out I added the functionality to import users from simpilot's 5.5.x classic version to this version. The way it works is that it takes all the pilots from the classic DB, adds them into the new DB, generates their API key & temporary password hash and finally emails them this info to log in. When they first log in, they should be on their edit profile page to change their password. Saves them going through the effort of requesting a password change first up, although either way they still have to check their emails. EDIT: It seems it actually made it into this one (thanks Github), you can remove it if you wish. |
@@ -57,6 +57,12 @@ protected function sendLoginResponse(Request $request) | |||
$request->session()->regenerate(); | |||
$this->clearLoginAttempts($request); | |||
|
|||
# Check if it's their first login to reset their password | |||
if($user->created_at == $user->updated_at) { |
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.
This will have to end up being changed anyway, just thought that now anyone who has registered after the import will have to change their password which isn't ideal.
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.
Leave this bit out for now, lemme think about this one. It might make more sense to add a boolean column of reset_password
, and check against that. That way we can use it in other cases, like a lockout. There's also the reset password function that uses a token. Maybe checking if there's a token filled, I have to look at the forgot password code.
@@ -7,7 +7,7 @@ | |||
|
|||
class Importer extends BaseCommand | |||
{ | |||
protected $signature = 'phpvms:importer {db_host} {db_name} {db_user} {db_pass?}'; |
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.
Not sure where my comment went, change this one back for now, I'll probably change this to use a config file, since I think there will be more settings to add. For testing, though, it's a pain with the ask()
every time
app/Console/Services/Importer.php
Outdated
@@ -68,6 +72,7 @@ public function __construct($db_creds) | |||
'name' => '', | |||
'user' => '', | |||
'pass' => '', | |||
'table_prefix' => '' |
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.
set to 'table_prefix' => 'phpvms_'
as the default
app/Console/Services/Importer.php
Outdated
@@ -163,7 +172,7 @@ protected function saveModel($model) | |||
$model->save(); | |||
return true; | |||
} catch (QueryException $e) { | |||
#$this->error($e->getMessage()); | |||
#return $this->error($e->getMessage()); |
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.
Leave this in for now, still debugging and working on this
app/Console/Services/Importer.php
Outdated
$offset = 0; | ||
$total_rows = $this->getTotalRows($table); | ||
$total_rows = intval($this->getTotalRows($table)); |
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 wouldn't put this here. In the getTotalRows()
method, do the return (int) $rows
I believe it would be
app/Console/Services/Importer.php
Outdated
|
||
$name = $row->firstname.' '.$row->lastname; | ||
$airlineid = Airline::where('icao', $row->code)->first()->id; |
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.
We don't need to do lookups here. When populating the airport and ranks, I filled out $this->airports
and $this->ranks
(see those import functions). So we can do a lookup in those arrays, vs having to do a DB call every time.
$airline_id = $this->airlines[$row->code)
$rank_id = $this->ranks[$row->rank]
app/Console/Services/Importer.php
Outdated
foreach($allusers as $user) | ||
{ | ||
# Generate New User Password | ||
# TODO: Increase Security? |
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.
Nah, this is fine
app/Console/Services/Importer.php
Outdated
$apikey = Utils::generateApiKey(); | ||
|
||
# Update Info in DB | ||
$user->password = bcrypt($newpw); |
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.
If you look in the registration code, there's a Hash::make()
or something like that which will salt. Just to make sure that the password check works properly. That might use bcrypt under the hood but let's still call that one to make sure we're 100% compat
app/Console/Services/Importer.php
Outdated
$user->save(); | ||
|
||
# Send E-Mail to User with new login details | ||
$email = new \App\Mail\NewLoginDetails($user, $newpw, 'New Login Details | '.config('app.name')); |
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.
Don't email for now. We'll have to figure this bit out. Might be a separate option to do it, and we'll do it at the end, in a batched manner, after the import has completed. Otherwise it slows the user import down considerably
'api_key', | ||
'home_airport_id', | ||
'curr_airport_id', | ||
'last_pirep_id', | ||
'rank_id', | ||
'flights', |
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.
Good catch on these!
app/Console/Services/Importer.php
Outdated
*/ | ||
protected function getUserState($state) | ||
{ | ||
// Decide which state they will be in accordance with v7 |
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.
This looks good... one small change, I like to be explicit. Maybe add an array here,
$phpvms_classic_states = [
'ACTIVE' => 0,
...
];
And then check against those.
app/Console/Services/Importer.php
Outdated
'rank_id' => $rankid, | ||
'home_airport_id' => $row->hub, | ||
'curr_airport_id' => $row->hub, | ||
'flights' => intval($row->totalflights), |
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.
It's more efficient to use (int) $row->totalflights
app/Console/Services/Importer.php
Outdated
'home_airport_id' => $row->hub, | ||
'curr_airport_id' => $row->hub, | ||
'flights' => intval($row->totalflights), | ||
'flight_time' => intval($row->totalhours), |
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.
This actually needs to be converted to minutes. There's a Utils::hoursToMinutes()
Hey, this looks mostly good, just a bunch of changes. Thanks a ton, man! I'm glad for the help. Also, if you want to split the PRs, you need to create new branches in your local repo, push those, and then that will let you create PRs against master |
Another thing that needs to be done (if you want to), in the user import, we need to get all of the groups, specifically, making sure that the users in the https://github.com/nabeelio/phpvms/blob/master/app/Services/UserService.php#L35 I'd make that a separate PR, since that'll need some changing to the save code and stuff, and making sure the |
app/Console/Services/Importer.php
Outdated
$newpw = substr(md5(date('mdYhs')), 0, 10); | ||
|
||
# Generate API Key | ||
$apikey = Utils::generateApiKey(); |
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 don't mean to nitpick :) But can you change these all to $api_key
, etc, just keep the underscores in there. I just want the variables and everything to be uniform across the code
Yep, I'll make those changes, the way you've made v7 is different to the way I would've, but it's a fun learning experience. |
@web541 cool, thanks! If you hop on Discord, I'd like to hear about what you would've done differently, there might be some ideas in there as well |
|
||
$name = $row->firstname.' '.$row->lastname; | ||
$airline_id = $this->airlines[$row->code]; | ||
$rank_id = $this->ranks[$row->rank]; |
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.
This gets the rank before it's imported, so the id remains as rankid in the old DB. Any ideas on how to change this to get the imported rank in the new DB?
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.
Ah good point! You can put it back to the DB lookup. I'll think of something more efficient tonight
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.
D'oh, I remember what I was meaning to do. I was gonna set the value to the new ID from the insert. I'll fix it later.
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.
All good, this might be the same with airlines as well (only tested with the one that was already there, so not sure).
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.
Yeah, I'll fix it. Good to merge?
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 think so, I'll add the admin permissions thingo in another branch after so it doesn't stuff the current stuff up.
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.
And also for that, importUsers function or separate function?
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.
Umm I gotta thing about that. I might have to do a bit of refactoring for the ID mapping stuff. Probably makes sense to go into the method that's resetting the password/api key, etc. But that too will likely be once I refactor the mapping thing in a couple of hours
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.
np, I'll leave it for now.
Some more small issues I've found.