Page MenuHomeDevCentral

No OneTemporary

diff --git a/app/Console/Commands/AccountDump.php b/app/Console/Commands/AccountDump.php
index 1caa848..9881b1e 100644
--- a/app/Console/Commands/AccountDump.php
+++ b/app/Console/Commands/AccountDump.php
@@ -1,60 +1,59 @@
<?php
namespace AuthGrove\Console\Commands;
use Illuminate\Console\Command;
use AuthGrove\Models\User;
-class AccountDump extends Command
-{
+class AccountDump extends Command {
+
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'account:dump {--format=human}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Dump the accounts list';
/**
* Create a new command instance.
*
* @return void
*/
- public function __construct()
- {
+ public function __construct() {
parent::__construct();
}
-
+
/**
* Execute the console command.
*
* @return mixed
*/
- public function handle()
- {
+ public function handle() {
$format = $this->option('format');
$attributes = User::getDefaultAttributes();
$users = User::all($attributes)->toArray();
switch ($format) {
case "human":
$headers = array_map('\AuthGrove\Models\User::localizeAttribute', $attributes);
$this->table($headers, $users);
break;
case "json":
echo json_encode($users);
break;
default:
$this->error("Unknown format: $format");
}
}
+
}
diff --git a/app/Console/Commands/AccountInfo.php b/app/Console/Commands/AccountInfo.php
index 47887c2..40ab1d3 100644
--- a/app/Console/Commands/AccountInfo.php
+++ b/app/Console/Commands/AccountInfo.php
@@ -1,87 +1,86 @@
<?php
namespace AuthGrove\Console\Commands;
use Illuminate\Console\Command;
use AuthGrove\Console\Services\AccountHelpers as AccountHelpers;
-class AccountInfo extends Command
-{
+class AccountInfo extends Command {
+
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'account:info {user} {--format=human}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Get information about an account';
/**
* The length of a padded localized attribute
* @var int
*/
const ATTRIBUTE_LEN = 21;
/**
* Create a new command instance.
*
* @return void
*/
- public function __construct()
- {
+ public function __construct() {
parent::__construct();
}
/**
* Prints a padded "attribute: value" line.
*
* @param string $attribute The attribute
* @param string $value The value for this attribute
*/
protected function printInformationAttribute ($attribute, $value) {
$line = \Keruald\mb_str_pad(
AccountHelpers::localizeUserAttribute($attribute),
self::ATTRIBUTE_LEN
);
$line .= $value;
$this->info($line);
}
/**
* Execute the console command.
*
* @return mixed
*/
- public function handle()
- {
+ public function handle() {
$format = $this->option('format');
$user = AccountHelpers::findUser($this->argument('user'));
if ($user === null) {
$this->error("User not found.");
return;
}
$information = $user->getInformation();
switch ($format) {
case "human":
foreach ($user->getInformation() as $attribute => $value) {
$this->printInformationAttribute($attribute, $value);
}
break;
case "json":
echo json_encode($information), "\n";
break;
default:
$this->error("Unknown format: $format");
}
}
+
}
diff --git a/app/Console/Commands/AccountReset.php b/app/Console/Commands/AccountReset.php
index a75013e..91bbae1 100644
--- a/app/Console/Commands/AccountReset.php
+++ b/app/Console/Commands/AccountReset.php
@@ -1,131 +1,131 @@
<?php
namespace AuthGrove\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Contracts\Auth\PasswordBroker;
use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Password;
use AuthGrove\Console\Services\AccountHelpers;
-class AccountReset extends Command
-{
+class AccountReset extends Command {
+
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'account:reset {user} {--subject=} {--format=human}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send a mail with a reset password link for an account';
/**
* The user e-mail
*
* @var string
*/
private $email;
/**
* Create a new command instance.
*
* @return void
*/
- public function __construct()
- {
+ public function __construct() {
parent::__construct();
}
/**
* Gets e-mail subject from command line option or default l10n
*
* @return string the e-mail subject
*/
public function getEmailSubject () {
$subject = $this->option('subject');
if ($subject === null) {
return trans('emails.reset-password-subject');
}
return $subject;
}
/**
* Sends a reset passsword e-mail
*
* @return bool true if a mail has been sent, false if the user is invalid
*/
public function sendResetMail () {
//Information we need for this mail
$subject = $this->getEmailSubject();
$credentials = [
'email' => $this->email
];
//Tries to send the mail
$response = Password::sendResetLink($credentials, function(Message $m) use ($subject)
{
$m->subject($subject);
});
//Handles password broker response, returning true on success
switch ($response) {
case PasswordBroker::RESET_LINK_SENT:
return true;
case PasswordBroker::INVALID_USER:
return false;
default:
throw new \Exception("Unhandled password broker response: " . $response);
}
}
/**
* Execute the console command.
*
* @return mixed
*/
- public function handle()
- {
+ public function handle() {
//Gets the information
$user = AccountHelpers::findUser($this->argument('user'));
if ($user === null) {
$this->error("User not found.");
return;
}
$this->email = $user->getInformation()['email'];
//Operation
$success = $this->sendResetMail();
if (!$success) {
$this->error("The user has been found, but the password broker considers this user is invalid.");
return;
}
//Regular output
$format = $this->option('format');
switch ($format) {
case "human":
$this->info("A reset link mail has been sent to $this->email.");
break;
case "json":
echo json_encode([
"result" => "ok",
"email" => $this->email
]);
echo PHP_EOL;
break;
default:
$this->error("Unknown format: $format");
}
}
+
+
}
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index 767eef6..8e50968 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -1,33 +1,32 @@
<?php namespace AuthGrove\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel {
- /**
- * The Artisan commands provided by your application.
- *
- * @var array
- */
- protected $commands = [
- 'AuthGrove\Console\Commands\AccountInfo',
- 'AuthGrove\Console\Commands\AccountDump',
- 'AuthGrove\Console\Commands\AccountReset',
- 'AuthGrove\Console\Commands\Inspire',
- 'AuthGrove\Console\Commands\DatabaseShell',
- ];
+ /**
+ * The Artisan commands provided by your application.
+ *
+ * @var array
+ */
+ protected $commands = [
+ 'AuthGrove\Console\Commands\AccountInfo',
+ 'AuthGrove\Console\Commands\AccountDump',
+ 'AuthGrove\Console\Commands\AccountReset',
+ 'AuthGrove\Console\Commands\Inspire',
+ 'AuthGrove\Console\Commands\DatabaseShell',
+ ];
- /**
- * Define the application's command schedule.
- *
- * @param \Illuminate\Console\Scheduling\Schedule $schedule
- * @return void
- */
- protected function schedule(Schedule $schedule)
- {
- $schedule->command('inspire')
- ->hourly();
- }
+ /**
+ * Define the application's command schedule.
+ *
+ * @param \Illuminate\Console\Scheduling\Schedule $schedule
+ * @return void
+ */
+ protected function schedule(Schedule $schedule) {
+ $schedule->command('inspire')
+ ->hourly();
+ }
}
diff --git a/app/Console/Services/AccountHelpers.php b/app/Console/Services/AccountHelpers.php
index 2551064..fb3e7a2 100644
--- a/app/Console/Services/AccountHelpers.php
+++ b/app/Console/Services/AccountHelpers.php
@@ -1,45 +1,46 @@
<?php
namespace AuthGrove\Console\Services;
use AuthGrove\Models\User;
class AccountHelpers {
/**
* Finds an user from user id, name or e-mail
*
* @param mixed $data User id, name or e-mail
* @return User|null
*/
public static function findUser ($data) {
//By id
if (is_numeric($data)) {
return User::find($data);
}
//By other attributes
$attributes = ['username', 'email'];
foreach ($attributes as $attribute) {
$user = User::findBy($attribute, $data);
if ($user !== null) {
return $user;
}
}
return null;
}
public static function getNonBreakableSpace() {
return mb_convert_encoding('&nbsp;', 'UTF-8', 'HTML-ENTITIES');
}
public static function localizeUserAttribute ($attribute, $useNoBreakableSpace = true) {
$localizedKey = 'panel.user-attributes.' . $attribute;
$localizedString = trans($localizedKey);
if ($useNoBreakableSpace) {
return str_replace(' ', self::getNonBreakableSpace(), $localizedString);
}
return $localizedString;
}
+
}
diff --git a/app/Models/User.php b/app/Models/User.php
index 94c82e0..e13ee42 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -1,96 +1,96 @@
<?php namespace AuthGrove\Models;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use AuthGrove\Services\FindableByAttribute;
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword, FindableByAttribute;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['username', 'fullname', 'email', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
- /**
- * Gets fillable but not hidden attributes, plus create/update time
- *
- * @return Array
- */
- public function getAttributes () {
- $attributes = array_diff($this->fillable , $this->hidden);
- $attributes[] = 'created_at';
- $attributes[] = 'updated_at';
- array_unshift($attributes, 'id');
- return $attributes;
- }
+ /**
+ * Gets fillable but not hidden attributes, plus create/update time
+ *
+ * @return Array
+ */
+ public function getAttributes () {
+ $attributes = array_diff($this->fillable , $this->hidden);
+ $attributes[] = 'created_at';
+ $attributes[] = 'updated_at';
+ array_unshift($attributes, 'id');
+ return $attributes;
+ }
- /**
- * Localizes attribute
- *
- * @param string $attribute The attribute to localize
- * @return string The localized name of the attribute
- */
- public static function localizeAttribute ($attribute) {
- return trans("panel.user-attributes.$attribute");
- }
+ /**
+ * Localizes attribute
+ *
+ * @param string $attribute The attribute to localize
+ * @return string The localized name of the attribute
+ */
+ public static function localizeAttribute ($attribute) {
+ return trans("panel.user-attributes.$attribute");
+ }
- /**
- * Gets default attributes
- *
- * @return Array an array of string, each a default attribute of the model
- */
- public static function getDefaultAttributes () {
- $user = new self();
- return $user->getAttributes();
- }
+ /**
+ * Gets default attributes
+ *
+ * @return Array an array of string, each a default attribute of the model
+ */
+ public static function getDefaultAttributes () {
+ $user = new self();
+ return $user->getAttributes();
+ }
- /**
- * Gets non sensible properties
- *
- * @return Array
- */
- public function getInformation () {
- $info = [];
- $attributes = $this->getAttributes();
- foreach ($attributes as $attribute) {
- $info[$attribute] = $this->attributes[$attribute];
- }
- return $info;
- }
+ /**
+ * Gets non sensible properties
+ *
+ * @return Array
+ */
+ public function getInformation () {
+ $info = [];
+ $attributes = $this->getAttributes();
+ foreach ($attributes as $attribute) {
+ $info[$attribute] = $this->attributes[$attribute];
+ }
+ return $info;
+ }
- /**
- * Gets the full name of an user, or if not defined, the username.
- */
- public function getName () {
- if ($this->attributes['fullname'] !== "") {
- return $this->attributes['fullname'];
- }
- return $this->attributes['username'];
- }
+ /**
+ * Gets the full name of an user, or if not defined, the username.
+ */
+ public function getName () {
+ if ($this->attributes['fullname'] !== "") {
+ return $this->attributes['fullname'];
+ }
+ return $this->attributes['username'];
+ }
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Nov 25, 19:39 (5 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260869
Default Alt Text
(14 KB)

Event Timeline