Skip to content

Commit

Permalink
sync icon & fix #24
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-convertino committed Jan 27, 2024
1 parent ce1819c commit 4a22ddb
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 21 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This way, the migration from Google Authenticator to OTP Manager will be quick a
* [Official iOS App](https://apps.apple.com/us/app/nextcloud-otp-manager/id6471510170)
]]>
</description>
<version>0.3.5</version>
<version>0.3.6</version>
<licence>agpl</licence>
<author mail="[email protected]" homepage="https://www.convertino.cloud">Matteo Convertino</author>
<namespace>OtpManager</namespace>
Expand Down
4 changes: 2 additions & 2 deletions js/otpmanager-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/otpmanager-main.js.map

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions lib/Controller/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ private function validateFields($data)
{
$errors = [];

if (!array_key_exists("name", $data) || strlen($data["name"]) == 0 || strlen($data["name"]) > 64)
$errors["name"] = "Name must be 1-64 characters long";
if (!array_key_exists("name", $data) || strlen($data["name"]) == 0 || strlen($data["name"]) > 256)
$errors["name"] = "Name must be 1-256 characters long";

if (!array_key_exists("issuer", $data) || strlen($data["issuer"]) > 64)
$errors["issuer"] = "Issuer must be shorter than 64 characters";
if (!array_key_exists("issuer", $data) || strlen($data["issuer"]) > 256)
$errors["issuer"] = "Issuer must be shorter than 256 characters";

if (!array_key_exists("type", $data) || !in_array($data["type"], ["totp", "hotp"]))
$errors["type"] = "Type of code must be one of those listed";
Expand All @@ -82,8 +82,8 @@ private function validateFields($data)

if($data["secret"] === false)
$errors["secret"] = "Not able to decrypt secret key";
else if (!array_key_exists("secret", $data) || strlen($data["secret"]) < 16 || strlen($data["secret"]) > 256)
$errors["secret"] = "Secret key must be 16-256 characters long";
else if (!array_key_exists("secret", $data) || strlen($data["secret"]) < 16 || strlen($data["secret"]) > 512)
$errors["secret"] = "Secret key must be 16-512 characters long";
else if (!preg_match($regexBase32, $data["secret"]))
$errors["secret"] = "Secret key is not Base32-encodable";

Expand Down Expand Up @@ -291,6 +291,7 @@ private function compareAccounts(array $localAccounts)
$serverAccount->setPeriod($localAccount["period"]);
$serverAccount->setAlgorithm($localAccount["algorithm"]);
$serverAccount->setCounter($localAccount["counter"]);
$serverAccount->setIcon($localAccount["icon"] ?? "default");
$serverAccount->setPosition($position);
$serverAccount->setDeletedAt(null);
$serverAccount->setUpdatedAt(date("Y-m-d H:i:s"));
Expand All @@ -310,6 +311,7 @@ private function compareAccounts(array $localAccounts)
$account->setPeriod($localAccount["period"]);
$account->setAlgorithm($localAccount["algorithm"]);
$account->setCounter($localAccount["counter"]);
$account->setIcon($localAccount["icon"] ?? "default");
$account->setPosition($position);
$account->setUserId($this->userId);
$account->setCreatedAt(date("Y-m-d H:i:s"));
Expand All @@ -332,6 +334,7 @@ private function compareAccounts(array $localAccounts)
$account->setPeriod($localAccount["period"]);
$account->setAlgorithm($localAccount["algorithm"]);
$account->setCounter($localAccount["counter"]);
$account->setIcon($localAccount["icon"] ?? "default");
$account->setPosition($localAccount["position"]);
$account->setUpdatedAt(date("Y-m-d H:i:s"));

Expand All @@ -357,6 +360,7 @@ private function compareAccounts(array $localAccounts)
else if ($serverAccount->getPeriod() != $localAccount["period"]) $toEdit = true;
else if ($serverAccount->getAlgorithm() != $localAccount["algorithm"]) $toEdit = true;
else if ($serverAccount->getCounter() != $localAccount["counter"]) $toEdit = true;
else if ($serverAccount->getIcon() != ($localAccount["icon"] ?? "default")) $toEdit = true;
else if ($serverAccount->getPosition() != $localAccount["position"]) $toEdit = true;

$found = true;
Expand Down
2 changes: 2 additions & 0 deletions lib/Db/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Account extends Entity implements JsonSerializable {
protected $period;
protected $algorithm;
protected $counter;
protected $icon;
protected $position;
protected $userId;
protected $createdAt;
Expand All @@ -46,6 +47,7 @@ public function jsonSerialize(): array {
'period' => $this->period,
'algorithm' => $this->algorithm,
'counter' => $this->counter,
'icon' => $this->icon,
'position' => $this->position,
'user_id' => $this->userId,
'created_at' => $this->createdAt,
Expand Down
1 change: 0 additions & 1 deletion lib/Db/AccountMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCA\OtpManager\AppInfo\Application;
use Throwable;
Expand Down
33 changes: 33 additions & 0 deletions lib/Migration/Version000011Date20240127121000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace OCA\OtpManager\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;
use OCA\OtpManager\AppInfo\Application;

class Version000011Date20240127121000 extends SimpleMigrationStep
{
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options)
{
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$table = $schema->getTable(Application::ACCOUNTS_DB);

$table->addColumn('icon', 'string', [
'notnull' => false,
'default' => 'default',
]);

return $schema;
}
}
10 changes: 5 additions & 5 deletions src/js/modals/CreateOtpAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export function CreateOtpAccount({
},

validate: {
name: hasLength({ min: 1, max: 64 }, "Name must be 1-64 characters long"),
name: hasLength({ min: 1, max: 256 }, "Name must be 1-256 characters long"),
issuer: hasLength(
{ min: 0, max: 64 },
"Issuer must be shorter than 64 characters"
{ min: 0, max: 256 },
"Issuer must be shorter than 256 characters"
),
secret: hasLength(
{ min: 1, max: 256 },
"Secret must be 1-256 characters long"
{ min: 1, max: 512 },
"Secret must be 1-512 characters long"
),
},
});
Expand Down
10 changes: 5 additions & 5 deletions src/js/modals/EditOtpAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ export function EditOtpAccount({
},

validate: {
name: hasLength({ min: 1, max: 64 }, "Name must be 1-64 characters long"),
name: hasLength({ min: 1, max: 256 }, "Name must be 1-256 characters long"),
issuer: hasLength(
{ min: 0, max: 64 },
"Issuer must be shorter than 64 characters"
{ min: 0, max: 256 },
"Issuer must be shorter than 256 characters"
),
secret: hasLength(
{ min: 1, max: 256 },
"Secret must be 1-256 characters long"
{ min: 1, max: 512 },
"Secret must be 1-512 characters long"
),
},
});
Expand Down

0 comments on commit 4a22ddb

Please sign in to comment.