-
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
Changes from all commits
d7b3b8e
2705609
3cd5dc0
a8fac95
a15dbaf
bcb2ac3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,11 @@ | |
use App\Models\Airport; | ||
use App\Models\Rank; | ||
use App\Models\Subfleet; | ||
use App\Models\User; | ||
use App\Models\Enums\UserState; | ||
use App\Facades\Utils; | ||
use Illuminate\Support\Facades\Mail; | ||
use Illuminate\Support\Facades\Hash; | ||
|
||
/** | ||
* Class Importer | ||
|
@@ -68,6 +73,7 @@ public function __construct($db_creds) | |
'name' => '', | ||
'user' => '', | ||
'pass' => '', | ||
'table_prefix' => 'phpvms_' | ||
], $db_creds); | ||
} | ||
|
||
|
@@ -149,7 +155,11 @@ protected function info($message) | |
*/ | ||
protected function tableName($table) | ||
{ | ||
return 'phpvms_'.$table; | ||
if($this->creds['table_prefix'] !== false) { | ||
return $this->creds['table_prefix'].$table; | ||
} | ||
|
||
return $table; | ||
} | ||
|
||
/** | ||
|
@@ -163,8 +173,8 @@ protected function saveModel($model) | |
$model->save(); | ||
return true; | ||
} catch (QueryException $e) { | ||
#$this->error($e->getMessage()); | ||
return false; | ||
# return false; | ||
return $this->error($e->getMessage()); | ||
} | ||
} | ||
|
||
|
@@ -180,7 +190,7 @@ protected function getTotalRows($table) | |
$rows = $this->conn->query($sql)->fetchColumn(); | ||
|
||
$this->info('Found '.$rows.' rows in '.$table); | ||
return $rows; | ||
return (int) $rows; | ||
} | ||
|
||
/** | ||
|
@@ -190,6 +200,9 @@ protected function getTotalRows($table) | |
*/ | ||
protected function readRows($table) | ||
{ | ||
// Set the table prefix if it has been entered | ||
$this->tableName($table); | ||
|
||
$offset = 0; | ||
$total_rows = $this->getTotalRows($table); | ||
|
||
|
@@ -405,15 +418,41 @@ protected function importPireps() | |
|
||
protected function importUsers() | ||
{ | ||
/*$this->comment('--- USER IMPORT ---'); | ||
$this->comment('--- USER IMPORT ---'); | ||
|
||
$count = 0; | ||
foreach ($this->readRows('pilots') as $row) | ||
{ | ||
# TODO: What to do about pilot ids | ||
|
||
$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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. np, I'll leave it for now. |
||
$state = $this->getUserState($row->retired); | ||
|
||
$attrs = [ | ||
'name' => $name, | ||
'email' => $row->email, | ||
'password' => "", | ||
'api_key' => "", | ||
'airline_id' => $airline_id->id, | ||
'rank_id' => $rank_id->rankid, | ||
'home_airport_id' => $row->hub, | ||
'curr_airport_id' => $row->hub, | ||
'flights' => (int) $row->totalflights, | ||
'flight_time' => Utils::hoursToMinutes($row->totalhours), | ||
'state' => $state, | ||
]; | ||
|
||
if($this->saveModel(new User($attrs))) { | ||
++$count; | ||
} | ||
} | ||
|
||
$this->info('Imported ' . $count . ' users');*/ | ||
$this->info('Imported ' . $count . ' users'); | ||
|
||
// Reset Passwords & Generate API Keys | ||
$this->setupUsers(); | ||
} | ||
|
||
/** | ||
|
@@ -423,4 +462,59 @@ protected function recalculateRanks() | |
{ | ||
/*$this->comment('--- RECALCULATING RANKS ---');*/ | ||
} | ||
|
||
/** | ||
* Generate user's API Key and email them their new password | ||
*/ | ||
protected function setupUsers() | ||
{ | ||
$allusers = User::all(); | ||
foreach($allusers as $user) | ||
{ | ||
# Generate New User Password | ||
$newpw = substr(md5(date('mdYhs')), 0, 10); | ||
|
||
# Generate API Key | ||
$api_key = Utils::generateApiKey(); | ||
|
||
# Update Info in DB | ||
$user->password = Hash::make($newpw); | ||
$user->api_key = $api_key; | ||
$user->save(); | ||
} | ||
|
||
# TODO: Think about how to deliver new password to user, email in batch at the end? | ||
# TODO: How to reset password upon first login only for reset users | ||
} | ||
|
||
/** | ||
* Get the user's new state from their original state | ||
*/ | ||
protected function getUserState($state) | ||
{ | ||
// Declare array of classic states | ||
$phpvms_classic_states = [ | ||
'ACTIVE' => 0, | ||
'INACTIVE' => 1, | ||
'BANNED' => 2, | ||
'ON_LEAVE' => 3 | ||
]; | ||
|
||
// Decide which state they will be in accordance with v7 | ||
if ($state == $phpvms_classic_states['ACTIVE']) | ||
{ | ||
# Active | ||
return UserState::ACTIVE; | ||
} elseif ($state == $phpvms_classic_states['INACTIVE']) { | ||
# Rejected | ||
# TODO: Make an inactive state? | ||
return UserState::REJECTED; | ||
} elseif ($state == $phpvms_classic_states['BANNED']) { | ||
# Suspended | ||
return UserState::SUSPENDED; | ||
} elseif ($state == $phpvms_classic_states['ON_LEAVE']) { | ||
# On Leave | ||
return UserState::ON_LEAVE; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Mail; | ||
|
||
use App\Models\User; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class NewLoginDetails extends Mailable | ||
{ | ||
use Queueable, SerializesModels; | ||
|
||
public $subject, $user, $newpw; | ||
|
||
public function __construct(User $user, $newpw=null, $subject=null) | ||
{ | ||
$this->subject = $subject ?: 'New Login Details'; | ||
$this->newpw = $newpw ?: 'N/A'; | ||
$this->user = $user; | ||
} | ||
|
||
public function build() | ||
{ | ||
return $this->markdown('emails.user.newlogindetails') | ||
->subject($this->subject) | ||
->with(['user' => $this->user, 'newpw' => $this->newpw]); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ class Airport extends BaseModel | |
'icao', | ||
'name', | ||
'location', | ||
'country', | ||
'lat', | ||
'lon', | ||
'hub', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,11 +35,14 @@ class User extends Authenticatable | |
'email', | ||
'password', | ||
'airline_id', | ||
'rank_id', | ||
'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 commentThe reason will be displayed to describe this comment to others. Learn more. Good catch on these! |
||
'flight_time', | ||
'balance', | ||
'timezone', | ||
'state', | ||
'status', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@component('mail::message') | ||
Your new login details for {{ config('app.name') }} follow: | ||
|
||
Do not share this information with anyone else! <br /> | ||
<strong>E-Mail Address:</strong> {!! $user->email !!}<br /> | ||
<strong>Temporary Password:</strong> {!! $newpw !!}<br /><br /> | ||
|
||
Your account is now ready for use.<br /> | ||
Upon first login, please reset your password. | ||
|
||
@component('mail::button', ['url' => url('/login')]) | ||
Login & Reset Password | ||
@endcomponent | ||
|
||
Thanks,<br /> | ||
Management, {{ config('app.name') }} | ||
@endcomponent |
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