public function userLogin() { $user = UserQuery::create()->filterByEmail($this->request_body->email)->filterByPassword(md5($this->request_body->password))->findOne(); if (null === $user) { throw new Exception("Incorrect username or password.", 401); } // TODO: Add previous token invalidation $token = new AccessToken(); $token->setTokenContent(uniqid()); $token->setUser($user); $token->save(); return array('user' => $user->toArray(), 'token' => $token->toArray()); }
/** * Exclude object from result * * @param ChildAccessToken $accessToken Object to remove from the list of results * * @return $this|ChildAccessTokenQuery The current query, for fluid interface */ public function prune($accessToken = null) { if ($accessToken) { $this->addUsingAlias(AccessTokenTableMap::COL_ID, $accessToken->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Filter the query by a related \Model\AccessToken object * * @param \Model\AccessToken|ObjectCollection $accessToken the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildUserQuery The current query, for fluid interface */ public function filterByAccessToken($accessToken, $comparison = null) { if ($accessToken instanceof \Model\AccessToken) { return $this->addUsingAlias(UserTableMap::COL_ID, $accessToken->getUserId(), $comparison); } elseif ($accessToken instanceof ObjectCollection) { return $this->useAccessTokenQuery()->filterByPrimaryKeys($accessToken->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByAccessToken() only accepts arguments of type \\Model\\AccessToken or Collection'); } }
/** * @param ChildAccessToken $accessToken The ChildAccessToken object to add. */ protected function doAddAccessToken(ChildAccessToken $accessToken) { $this->collAccessTokens[] = $accessToken; $accessToken->setUser($this); }