|
17 | 17 | */
|
18 | 18 |
|
19 | 19 | #include "AccountLoginManager.h"
|
20 |
| -#include <app-common/zap-generated/attribute-id.h> |
21 |
| -#include <app-common/zap-generated/attribute-type.h> |
22 |
| -#include <app-common/zap-generated/cluster-id.h> |
23 |
| -#include <app-common/zap-generated/command-id.h> |
24 |
| -#include <app-common/zap-generated/enums.h> |
25 | 20 | #include <app/CommandHandler.h>
|
26 | 21 | #include <app/util/af.h>
|
27 | 22 |
|
28 | 23 | using namespace std;
|
| 24 | +using namespace chip::app::Clusters::AccountLogin; |
29 | 25 |
|
30 |
| -bool AccountLoginManager::isUserLoggedIn(string requestTempAccountIdentifier, string requestSetupPin) |
| 26 | +bool AccountLoginManager::HandleLogin(const chip::CharSpan & tempAccountIdentifier, const chip::CharSpan & setupPin) |
31 | 27 | {
|
32 |
| - // TODO: Fix hardcoding length of strings |
33 |
| - requestTempAccountIdentifier = requestTempAccountIdentifier.substr(0, 4); |
34 |
| - requestSetupPin = requestSetupPin.substr(0, 10); |
35 |
| - for (auto it = accounts.cbegin(); it != accounts.cend(); ++it) |
36 |
| - { |
37 |
| - ChipLogProgress(Zcl, "temporary account id: %s", it->first.c_str()); |
38 |
| - ChipLogProgress(Zcl, "setup pin %s", it->second.c_str()); |
39 |
| - } |
| 28 | + string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); |
| 29 | + string setupPinString(setupPin.data(), setupPin.size()); |
| 30 | + ChipLogProgress(Zcl, "temporary account id: %s", tempAccountIdentifierString.c_str()); |
| 31 | + ChipLogProgress(Zcl, "setup pin %s", setupPinString.c_str()); |
40 | 32 |
|
41 |
| - if (accounts.find(requestTempAccountIdentifier) != accounts.end()) |
42 |
| - { |
43 |
| - bool found = accounts[requestTempAccountIdentifier] == requestSetupPin; |
44 |
| - if (!found) |
45 |
| - { |
46 |
| - ChipLogError(Zcl, "User is not logged in, failed to match request setup pin."); |
47 |
| - } |
48 |
| - return found; |
49 |
| - } |
50 |
| - else |
51 |
| - { |
52 |
| - ChipLogError(Zcl, "User is not logged in, failed to find temp account identifier."); |
53 |
| - return false; |
54 |
| - } |
55 |
| -} |
56 |
| - |
57 |
| -void AccountLoginManager::setTempAccountIdentifierForPin(string tempAccountIdentifier, string setupPin) |
58 |
| -{ |
59 |
| - // TODO: Fix hardcoding length of strings |
60 |
| - string tempId = tempAccountIdentifier.substr(0, 4); |
61 |
| - accounts[tempId] = setupPin; |
62 |
| -} |
63 |
| - |
64 |
| -string AccountLoginManager::proxySetupPinRequest(string requestTempAccountIdentifier, chip::EndpointId endpoint) |
65 |
| -{ |
66 |
| - // TODO: Insert your code here to send temp account identifier request |
67 |
| - return "tempPin123"; |
| 33 | + // TODO: Insert your code here to handle login request |
| 34 | + return true; |
68 | 35 | }
|
69 | 36 |
|
70 |
| -bool AccountLoginManager::proxyLogout() |
| 37 | +bool AccountLoginManager::HandleLogout() |
71 | 38 | {
|
72 | 39 | // TODO: Insert your code here to send logout request
|
73 | 40 | return true;
|
74 | 41 | }
|
75 | 42 |
|
76 |
| -bool accountLoginClusterIsUserLoggedIn(std::string requestTempAccountIdentifier, std::string requestSetupPin) |
77 |
| -{ |
78 |
| - return AccountLoginManager().GetInstance().isUserLoggedIn(requestTempAccountIdentifier, requestSetupPin); |
79 |
| -} |
80 |
| - |
81 |
| -bool accountLoginClusterLogout() |
82 |
| -{ |
83 |
| - return AccountLoginManager().GetInstance().proxyLogout(); |
84 |
| -} |
85 |
| - |
86 |
| -std::string accountLoginClusterGetSetupPin(std::string requestTempAccountIdentifier, chip::EndpointId endpoint) |
| 43 | +Commands::GetSetupPINResponse::Type AccountLoginManager::HandleGetSetupPin(const chip::CharSpan & tempAccountIdentifier) |
87 | 44 | {
|
88 |
| - string responseSetupPin = AccountLoginManager().proxySetupPinRequest(requestTempAccountIdentifier, endpoint); |
89 |
| - AccountLoginManager().GetInstance().setTempAccountIdentifierForPin(requestTempAccountIdentifier, responseSetupPin); |
90 |
| - return responseSetupPin; |
| 45 | + string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); |
| 46 | + ChipLogProgress(Zcl, "temporary account id: %s", tempAccountIdentifierString.c_str()); |
| 47 | + // TODO: Insert your code here to handle get setup pin |
| 48 | + Commands::GetSetupPINResponse::Type response; |
| 49 | + response.setupPIN = chip::CharSpan("tempPin123", strlen("tempPin123")); |
| 50 | + return response; |
91 | 51 | }
|
0 commit comments