VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
authController.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2026 MAK Technologies, Inc.
3  * All rights reserved.
4  ******************************************************************************/
5 
6 #pragma once
7 
8 #include <oatpp/web/server/api/ApiController.hpp>
9 #include <oatpp/parser/json/mapping/ObjectMapper.hpp>
10 #include <oatpp/core/macro/codegen.hpp>
11 #include <oatpp/core/macro/component.hpp>
12 
13 #include OATPP_CODEGEN_BEGIN(ApiController)
14 
40 class DtAuthController : public oatpp::web::server::api::ApiController
41 {
42 public:
43  explicit DtAuthController(const std::shared_ptr<ObjectMapper>& objectMapper)
44  : oatpp::web::server::api::ApiController(objectMapper)
45  {
46  }
47 
49  {
50  info->summary = "Log in and obtain a session key";
51  info->description =
52  "Accepts a JSON body with 'username' and optional 'password' fields. "
53  "If the account has no password set, the password field is ignored. "
54  "Returns a session key that must be sent as 'Authorization: Bearer <sessionKey>' "
55  "on all subsequent API requests.";
56  info->addTag("Auth");
57  info->addConsumes<oatpp::String>("application/json");
58  info->addResponse<oatpp::String>(Status::CODE_200, "application/json");
59  info->addResponse<oatpp::String>(Status::CODE_400, "application/json");
60  info->addResponse<oatpp::String>(Status::CODE_401, "application/json");
61  }
62  ENDPOINT("POST", "/auth/login", login, REQUEST(std::shared_ptr<IncomingRequest>, request))
63  {
64  return handleLogin(request);
65  }
66 
67  ENDPOINT_INFO(logout)
68  {
69  info->summary = "Log out and invalidate the current session key";
70  info->description =
71  "Reads the Bearer token from the Authorization header and removes it from the "
72  "active session table. Always returns 200 regardless of whether the key "
73  "existed, so clients can safely call this even if already logged out.";
74  info->addTag("Auth");
75  info->addResponse<oatpp::String>(Status::CODE_200, "application/json");
76  }
77  ENDPOINT("POST", "/auth/logout", logout, REQUEST(std::shared_ptr<IncomingRequest>, request))
78  {
79  return handleLogout(request);
80  }
81 
82 private:
83  std::shared_ptr<OutgoingResponse> handleLogin(const std::shared_ptr<IncomingRequest>& req);
84 
85  std::shared_ptr<OutgoingResponse> handleLogout(const std::shared_ptr<IncomingRequest>& req);
86 };
87 
88 #include OATPP_CODEGEN_END(ApiController)
std::shared_ptr< OutgoingResponse > handleLogin(const std::shared_ptr< IncomingRequest > &req)
std::shared_ptr< OutgoingResponse > handleLogout(const std::shared_ptr< IncomingRequest > &req)
DtAuthController(const std::shared_ptr< ObjectMapper > &objectMapper)
Definition: authController.h:43
ENDPOINT_INFO(login)
Definition: authController.h:48
DtAuthController — REST endpoints for user authentication.
Definition: authController.h:40
ENDPOINT_INFO(logout)
Definition: authController.h:67

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)