Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3748191
D26.id54.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D26.id54.diff
View Options
diff --git a/app/Console/Commands/AccountReset.php b/app/Console/Commands/AccountReset.php
new file mode 100644
--- /dev/null
+++ b/app/Console/Commands/AccountReset.php
@@ -0,0 +1,130 @@
+<?php
+
+namespace AuthGrove\Console\Commands;
+
+use Illuminate\Console\Command;
+use Illuminate\Contracts\Auth\PasswordBroker;
+use Illuminate\Support\Facades\Password;
+use AuthGrove\User;
+use AuthGrove\Console\Services\AccountHelpers;
+
+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 = 'Gets 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()
+ {
+ 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($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()
+ {
+ //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.");
+ exit;
+ }
+
+ //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 PḦP_EOL;
+ break;
+
+ default:
+ $this->error("Unknown format: $format");
+ }
+ }
+}
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -13,6 +13,7 @@
protected $commands = [
'AuthGrove\Console\Commands\AccountInfo',
'AuthGrove\Console\Commands\AccountDump',
+ 'AuthGrove\Console\Commands\AccountReset',
'AuthGrove\Console\Commands\Inspire',
];
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 17, 07:12 (15 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2248890
Default Alt Text
D26.id54.diff (3 KB)
Attached To
Mode
D26: New artisan command: account:reset
Attached
Detach File
Event Timeline
Log In to Comment