Skip to content

Commit

Permalink
add general relationship methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pjc09h committed May 29, 2024
1 parent 2b66810 commit 46659c2
Show file tree
Hide file tree
Showing 83 changed files with 3,992 additions and 815 deletions.
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Contributing to BioGazelle

Thanks for your interest in improving BioGazelle's codebase.

## General application layout

todo
67 changes: 28 additions & 39 deletions app/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,13 @@ public function login(array $data)

$username = \Gazelle\Escape::username($data["username"] ?? null);
$passphrase = \Gazelle\Escape::passphrase($data["passphrase"] ?? null);
$rememberMe = \Gazelle\Escape::bool($data["rememberMe"] ?? null);

# 2fa code needs to be a string (RobThree)
$twoFactor = \Gazelle\Escape::string($data["twoFactor"] ?? null);
$rememberMe = \Gazelle\Escape::bool($data["rememberMe"] ?? null);

try {
# start a transaction
$app->dbNew->beginTransaction();

# validate userId and 2fa
$query = "
select users.id, users_main.twoFactor from users
Expand All @@ -410,30 +411,12 @@ public function login(array $data)
if ($row["twoFactor"] && empty($twoFactor)) {
throw new Exception("2fa code required");
}
} catch (Throwable $e) {
return $e->getMessage();
return $message;
}

# gazelle 2fa
if (!empty($twoFactor)) {
try {
if (!empty($twoFactor)) {
$this->verify2FA($userId, $twoFactor);
} catch (Throwable $e) {
return $e->getMessage();
return $message;
}
}

try {
/*
# todo: we're just updating users_main.id, it's technically wrong
# also this executes on every login, kinda lazy and not ideal
$query = "update users_main set id = userId where userId = ?";
$app->dbNew->do($query, [$userId]);
*/

# todo: same as above
# are there any unencrypted emails left?
$query = "select email from users where id = ?";
$email = $app->dbNew->single($query, [$userId]);

Expand All @@ -443,7 +426,7 @@ public function login(array $data)
$app->dbNew->do($query, [ \Gazelle\Crypto::encrypt($email), $userId ]);
}

# legacy: remove after 2024-04-01
# legacy isPassphraseMigrated: remove after 2025-04-01
$query = "select isPassphraseMigrated from users_info where userId = ?";
$isPassphraseMigrated = $app->dbNew->single($query, [$userId]);

Expand Down Expand Up @@ -482,36 +465,42 @@ public function login(array $data)
$response = $this->library->loginWithUsername($username, $passphrase, $this->remember($rememberMe));
}
*/
} catch (\Delight\Auth\InvalidEmailException $e) {
return $e->getMessage();
return $message;
} catch (\Delight\Auth\InvalidPasswordException $e) {
return $e->getMessage();
return $message;
/*
} catch (\Delight\Auth\InvalidEmailException $e) {
return $e->getMessage();
return $message;
} catch (\Delight\Auth\InvalidPasswordException $e) {
return $e->getMessage();
return $message;
*/
} catch (\Delight\Auth\EmailNotVerifiedException $e) {
# this throws to provide a "resend confirmation email" link
throw new \Delight\Auth\EmailNotVerifiedException($e->getMessage());
} catch (\Delight\Auth\TooManyRequestsException $e) {
return $e->getMessage();
return $message;
} catch (\Delight\Auth\UnknownUsernameException $e) {
return $e->getMessage();
return $message;
} catch (\Delight\Auth\AmbiguousUsernameException $e) {
return $e->getMessage();
return $message;
/*
} catch (\Delight\Auth\TooManyRequestsException $e) {
return $e->getMessage();
return $message;
} catch (\Delight\Auth\UnknownUsernameException $e) {
return $e->getMessage();
return $message;
} catch (\Delight\Auth\AmbiguousUsernameException $e) {
return $e->getMessage();
return $message;
*/
} catch (Throwable $e) {
return $e->getMessage();
return $message;
}

/*
try {
# gazelle session
$this->createSession($userId, $rememberMe);
} catch (Throwable $e) {
return $e->getMessage();
return $message;
}
*/
} # login


Expand Down
2 changes: 1 addition & 1 deletion app/Better.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static function missingCitations(bool $snatchedOnly = false): array
from torrents_group
{$subQuery}
where torrents_group.id not in
(select distinct group_id from literature)
(select distinct groupId from literature_groups)
order by rand() limit {$resultCount}
";

Expand Down
26 changes: 1 addition & 25 deletions app/Models/Collages.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function relationships(): array
*
* @return array
*/
public function relatedTorrentGroups(): array
private function relatedTorrentGroups(): array
{
$app = App::go();

Expand All @@ -145,30 +145,6 @@ public function relatedTorrentGroups(): array
}


/** accessors */


/**
* getTorrentGroups
*
* @return array
*/
public function getTorrentGroups(): array
{
$app = App::go();

# get related id's
$ref = $this->relatedTorrentGroups();

$data = [];
foreach ($ref as $row) {
$data[] = new TorrentGroups($row["id"]);
}

return $data;
}


/** methods */


Expand Down
2 changes: 1 addition & 1 deletion app/Models/Conversations.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function relationships(): ?array
*
* @return ?array
*/
public function relatedMessages(): ?array
private function relatedMessages(): ?array
{
$app = App::go();

Expand Down
58 changes: 5 additions & 53 deletions app/Models/Creators.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function relationships(): array
*
* @return array
*/
public function relatedTorrentGroups(): array
private function relatedTorrentGroups(): array
{
$app = App::go();

Expand All @@ -104,7 +104,7 @@ public function relatedTorrentGroups(): array
*
* @return array
*/
public function relatedRequests(): array
private function relatedRequests(): array
{
$app = App::go();

Expand All @@ -123,55 +123,6 @@ public function relatedRequests(): array
/** methods */


/**
* getTorrentGroups
*
* Gets the torrent groups for a creator.
*
* @return array
*/
public function getTorrentGroups(): array
{
$app = App::go();

# get related id's
$ref = $this->relatedTorrentGroups();

$data = [];
foreach ($ref as $row) {
$data[] = new TorrentGroups($row["id"]);
}

return $data;
}


/**
* getRequests
*
* Gets the requests for a creator.
*
* @return array
*/
public function getRequests(): array
{
$app = App::go();

# get related id's
$ref = $this->relatedRequests();

$data = [];
foreach ($ref as $row) {
$data[] = new Requests($row["id"]);
}

return $data;
}


/** */


/**
* hydrateFromSemanticScholar
*
Expand Down Expand Up @@ -209,11 +160,12 @@ public function hydrateFromSemanticScholar(): ?array
# prepare the data for the database
$data = [
"id" => $this->id,
"orcid" => $canonicalCreator["externalIds"]["ORCID"] ?? null,
"semanticScholarId" => $canonicalCreator["authorId"] ?? null,
"name" => $canonicalCreator["name"] ?? null,
"slug" => \Illuminate\Support\Str::slug($canonicalCreator["name"] ?? null),
"aliases" => json_encode($canonicalCreator["aliases"] ?? null),
"affiliations" => json_encode($canonicalCreator["affiliations"] ?? null),
"aliases" => json_encode($canonicalCreator["aliases"] ?? []),
"affiliations" => json_encode($canonicalCreator["affiliations"] ?? []),
"homepage" => $canonicalCreator["homepage"] ?? null,
"hIndex" => $canonicalCreator["hIndex"] ?? null,
"paperCount" => $canonicalCreator["paperCount"] ?? null,
Expand Down
Loading

0 comments on commit 46659c2

Please sign in to comment.