コード例 #1
0
 /**
  * @SWG\Api(
  *      path="/user/login",
  *      description="User login API",
  *      @SWG\Operation(
  *          method="POST",
  *          summary="User login API",
  *          notes="Return JSON",
  *          type="User",
  *          nickname="login",
  *          @SWG\Parameter(
  *              name="username",
  *              description="Username",
  *              paramType="query",
  *              required=true,
  *              allowMultiple=false,
  *              type="string"
  *          ),
  *          @SWG\Parameter(
  *              name="password",
  *              description="Password",
  *              paramType="query",
  *              required=true,
  *              allowMultiple=false,
  *              type="string"
  *          ),
  *          @SWG\ResponseMessage(
  *              code=200,
  *              message="Succes"
  *          ),
  *          @SWG\ResponseMessage(
  *              code=400,
  *              message="Invalid username or password"
  *          )
  *      )
  * )
  * @SLX\Route(
  *      @SLX\Request(method="POST", uri="login")
  * )
  * @param Request $request
  * @return JsonResponse
  */
 public function loginAction(Request $request)
 {
     $command = new LoginCommand();
     $command->setUsername($request->get("username"));
     $command->setPassword($request->get("password"));
     $token = $this->bus->handle($command);
     $object = new \ArrayObject();
     $object->offsetSet("data", ["token" => $token]);
     $response = new JsonResponse($object);
     return $response;
 }
コード例 #2
0
ファイル: UserHandler.php プロジェクト: digideskio/singo-app
 /**
  * @param LoginCommand $command
  * @return string
  */
 public function handleLoginCommand(LoginCommand $command)
 {
     if ($command->getUsername() == "admin" && $command->getPassword() == "singo") {
         /**
          * notify all AfterLoginEvent subscriber
          */
         $this->dispatcher->dispatch(AfterLoginEvent::EVENT, new AfterLoginEvent($command->getUsername()));
         return $this->encoder->encode(["name" => $command->getUsername()]);
     }
     throw new InvalidUsernamePasswordException("invalid username or password");
 }