public static function findAndlogin($userAlias, $password, $remember = false) { if (!$userAlias) { throw new Exceptions\InvalidField("useralias"); } if (!$password) { throw new Exceptions\InvalidField("password"); } $user = Users::findFirst(['conditions' => ['email' => $userAlias]]); if (!$user) { throw new Exceptions\InvalidField("useralias"); } if (!self::verifyHash($password, $user->passwordHash)) { throw new Exceptions\InvalidField("password"); } $user->saveSession($remember); return $user; }
public function validation() { // Verify Name $this->requireField("name"); if (strlen($this->name) < 1) { throw new Exceptions\InvalidField("name"); } // Verify Location $this->requireField("location"); $this->location = (int) $this->location; if ($this->location !== 0 && $this->location !== 1) { throw new Exceptions\InvalidField("location"); } // Verify Author $this->requireField("authorId"); $author = UserVault\Users::findById($this->authorId); if (!isset($author) || !$author) { throw new Exceptions\InvalidField("authorId"); } // Verify FormulaId if ($this->formulaId) { $formula = PredefinedFormulas::findById($this->formulaId); if (!isset($formula) || !$formula) { throw new Exceptions\InvalidField("formulaId"); } } // Verify Contracts $autoNames = []; foreach ($this->contracts as $i => &$contractInfo) { $contract = new Works\Contracts(); $contract->fromArray($contractInfo); if ($i == 0) { $contract->validationInitial(); } else { $contract->validation(); } // ConsignmentDate >= (BidDate || Initial->BidDate) $bidDate = $contract->bidDate ? $contract->bidDate : $this->contracts[0]["bidDate"]; if ($contract->consignmentDate < $bidDate) { throw new Exceptions\InvalidField("consignmentDate"); } // Verify unique name of Autos foreach ($contract->autos as $auto) { if (in_array($auto["name"], $autoNames)) { throw new Exceptions\NotUniqueField("autoName"); } $autoNames[] = $auto["name"]; } $contractInfo = $contract->toArray(); } return true; }