Skip to content

Commit

Permalink
style: format ImportAccounts
Browse files Browse the repository at this point in the history
Signed-off-by: Aisha Tammy <floss@bsd.ac>
  • Loading branch information
epsilon-0 committed May 24, 2022
1 parent 9ff5246 commit 1f58d66
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions app/Console/Commands/ImportAccounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Models\Account\Account;
use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;

class ImportAccounts extends Command
{
Expand Down Expand Up @@ -75,31 +74,36 @@ public function handle()
}

$ldap_conn = ldap_connect($ldap_uri);
if(!$ldap_conn) {
if (! $ldap_conn) {
$this->error('Could not connect to LDAP URI');

return;
}
if(!ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3)) {
if (! ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3)) {
$this->error('Could not set LDAP protocol v3');

return false;
}

try {
$bind = ldap_bind($ldap_conn, $ldap_user, $ldap_pass);
if (!$bind) {
$this->error('Could not bind with given LDAP credentials');
if (! $bind) {
$this->error('Could not bind with given LDAP credentials');

return;
}
} catch (\ErrorException $e) {
} catch (\Exception $e) {
$this->error($e->getMessage());

return;
}

$ldap_res = [];
try {
$ldap_res = ldap_search($ldap_conn, $ldap_base, $ldap_filter, [$ldap_attr_mail, $ldap_attr_firstname, $ldap_attr_lastname]);
} catch (\ErrorException $e) {
} catch (\Exception $e) {
$this->error($e->getMessage());

return;
}

Expand All @@ -119,11 +123,11 @@ public function handle()
if ($ldap_data[$i][$ldap_attr_lastname]['count'] > 0) {
$user_lastname = $ldap_data[$i][$ldap_attr_lastname][0];
}
$this->info('Importing user "' . $user_mail .'"');
$this->info('Importing user "'.$user_mail.'"');
try {
Account::createDefault($user_firstname, $user_lastname, $user_mail, $user_password);
} catch(\Exception $import_error){
$this->warn('Could not import user "' . $user_mail . '": ' . $import_error->getMessage());
} catch (\Exception $import_error){
$this->warn('Could not import user "'.$user_mail.'": '.$import_error->getMessage());
}
}
}
Expand Down

0 comments on commit 1f58d66

Please sign in to comment.