Skip to content

Commit

Permalink
feat: correct migrations for user sessions columns
Browse files Browse the repository at this point in the history
  • Loading branch information
samerton committed Jul 14, 2024
1 parent 0fad486 commit c0712ff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 0 additions & 1 deletion core/classes/Core/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ private function _commonLogin(?string $username, ?string $password, bool $rememb
}
} elseif ($this->checkCredentials($username, $password, $method) === true) {
// Valid credentials
// TODO: job to remove old sessions?
$hash = SecureRandom::alphanumeric();
$expiresAt = $remember ? time() + Config::get('remember.cookie_expiry') : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function change(): void
$table = $this->table('nl2_users_session');
$table->addColumn('remember_me', 'boolean', ['default' => false]);
$table->addColumn('active', 'boolean', ['default' => false]);
$table->addColumn('user_agent', 'string', ['length' => 256, 'null' => true, 'default' => null]);
$table->addColumn('device_name', 'string', ['length' => 256, 'null' => true, 'default' => null]);
$table->addColumn('last_seen', 'integer', ['length' => 11, 'null' => true, 'default' => null]);
$table->addColumn('login_method', 'string', ['length' => 32]);
$table->addIndex('hash', ['unique' => true]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class RenameDeviceNameColumnUsersSessionTable extends AbstractMigration
{
public function up(): void
{
$table = $this->table('nl2_users_session');
$table->renameColumn('device_name', 'user_agent')->save();
}

public function down(): void
{
$table = $this->table('nl2_users_session');
$table->renameColumn('user_agent', 'device_name')->save();
}
}

0 comments on commit c0712ff

Please sign in to comment.