Skip to content
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

Merged
merged 6 commits into from
Jan 3, 2018
Merged

Fixed a few field entries #116

merged 6 commits into from
Jan 3, 2018

Conversation

web541
Copy link
Contributor

@web541 web541 commented Jan 3, 2018

Some more small issues I've found.

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.
@web541
Copy link
Contributor Author

web541 commented Jan 3, 2018

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.
Didn't want to push it through just yet in case you had other ideas yourself, in that case I'll just discard it, no issues.

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) {
Copy link
Contributor Author

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.

Copy link
Owner

@nabeelio nabeelio Jan 3, 2018

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?}';
Copy link
Owner

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

@@ -68,6 +72,7 @@ public function __construct($db_creds)
'name' => '',
'user' => '',
'pass' => '',
'table_prefix' => ''
Copy link
Owner

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

@@ -163,7 +172,7 @@ protected function saveModel($model)
$model->save();
return true;
} catch (QueryException $e) {
#$this->error($e->getMessage());
#return $this->error($e->getMessage());
Copy link
Owner

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

$offset = 0;
$total_rows = $this->getTotalRows($table);
$total_rows = intval($this->getTotalRows($table));
Copy link
Owner

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


$name = $row->firstname.' '.$row->lastname;
$airlineid = Airline::where('icao', $row->code)->first()->id;
Copy link
Owner

@nabeelio nabeelio Jan 3, 2018

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]

foreach($allusers as $user)
{
# Generate New User Password
# TODO: Increase Security?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, this is fine

$apikey = Utils::generateApiKey();

# Update Info in DB
$user->password = bcrypt($newpw);
Copy link
Owner

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

$user->save();

# Send E-Mail to User with new login details
$email = new \App\Mail\NewLoginDetails($user, $newpw, 'New Login Details | '.config('app.name'));
Copy link
Owner

@nabeelio nabeelio Jan 3, 2018

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',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on these!

*/
protected function getUserState($state)
{
// Decide which state they will be in accordance with v7
Copy link
Owner

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.

'rank_id' => $rankid,
'home_airport_id' => $row->hub,
'curr_airport_id' => $row->hub,
'flights' => intval($row->totalflights),
Copy link
Owner

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

'home_airport_id' => $row->hub,
'curr_airport_id' => $row->hub,
'flights' => intval($row->totalflights),
'flight_time' => intval($row->totalhours),
Copy link
Owner

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()

@nabeelio
Copy link
Owner

nabeelio commented Jan 3, 2018

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

@nabeelio
Copy link
Owner

nabeelio commented Jan 3, 2018

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 Administrators group are added to the admin role. And all of the users need to be added to the users role. See

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 saveModel() works by-reference (I believe it does by default, unless IntelliJ is lying to me)

$newpw = substr(md5(date('mdYhs')), 0, 10);

# Generate API Key
$apikey = Utils::generateApiKey();
Copy link
Owner

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

@web541
Copy link
Contributor Author

web541 commented Jan 3, 2018

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.
+1 on the branch in the fork, I didn't think of it that way.

@nabeelio
Copy link
Owner

nabeelio commented Jan 3, 2018

@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];
Copy link
Contributor Author

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?

Copy link
Owner

@nabeelio nabeelio Jan 3, 2018

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

Copy link
Owner

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.

Copy link
Contributor Author

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

Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Owner

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

Copy link
Contributor Author

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.

@nabeelio nabeelio merged commit 08df20d into nabeelio:master Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants