diff --git a/app/Repositories/User/UserRepository.php b/app/Repositories/User/UserRepository.php index 16567096f6..471545a298 100644 --- a/app/Repositories/User/UserRepository.php +++ b/app/Repositories/User/UserRepository.php @@ -285,6 +285,8 @@ class UserRepository implements UserRepositoryInterface */ public function hasRole(User $user, string $role): bool { + // TODO no longer need to loop like this + /** @var Role $userRole */ foreach ($user->roles as $userRole) { if ($userRole->name === $role) { @@ -371,4 +373,16 @@ class UserRepository implements UserRepositoryInterface return true; } + + /** + * Set MFA code. + * + * @param User $user + * @param string $code + */ + public function setMFACode(User $user, string $code): void + { + $user->mfa_secret = $code; + $user->save(); + } } diff --git a/app/Repositories/User/UserRepositoryInterface.php b/app/Repositories/User/UserRepositoryInterface.php index c01be9f65d..235fb0a301 100644 --- a/app/Repositories/User/UserRepositoryInterface.php +++ b/app/Repositories/User/UserRepositoryInterface.php @@ -39,6 +39,14 @@ interface UserRepositoryInterface */ public function all(): Collection; + /** + * Set MFA code. + * + * @param User $user + * @param string $code + */ + public function setMFACode(User $user, string $code): void; + /** * Gives a user a role. * diff --git a/app/User.php b/app/User.php index 0446a19b73..330dc20a7f 100644 --- a/app/User.php +++ b/app/User.php @@ -62,6 +62,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property bool $has2FA used in admin user controller. * @property array $prefs used in admin user controller. * @property string password + * @property string $mfa_secret * @property Collection roles * @property string blocked_code * @property bool blocked diff --git a/database/migrations/2019_03_22_183214_changes_for_v480.php b/database/migrations/2019_03_22_183214_changes_for_v480.php index adbe630292..21d19891c5 100644 --- a/database/migrations/2019_03_22_183214_changes_for_v480.php +++ b/database/migrations/2019_03_22_183214_changes_for_v480.php @@ -47,9 +47,15 @@ class ChangesForV480 extends Migration $table->dropColumn('transaction_group_id'); } ); - Schema::table('rule_groups', function (Blueprint $table) { + Schema::table('rule_groups', static function (Blueprint $table) { $table->dropColumn('stop_processing'); }); + + Schema::table( + 'users', static function (Blueprint $table) { + $table->dropColumn('mfa_secret'); + } + ); } /** @@ -62,7 +68,7 @@ class ChangesForV480 extends Migration Schema::table( 'transaction_journals', - function (Blueprint $table) { + static function (Blueprint $table) { $table->integer('transaction_currency_id', false, true)->nullable()->change(); @@ -74,8 +80,13 @@ class ChangesForV480 extends Migration $table->foreign('transaction_group_id')->references('id')->on('transaction_groups')->onDelete('cascade'); } ); - Schema::table('rule_groups', function (Blueprint $table) { + Schema::table('rule_groups', static function (Blueprint $table) { $table->boolean('stop_processing')->default(false); }); + Schema::table( + 'users', static function (Blueprint $table) { + $table->string('mfa_secret', 50)->nullable(); + } + ); } }