templateCredentials.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include "./templateCredentials.h"
  2. #include "./pageCredentials.h"
  3. #include "./common.h"
  4. LoginTemplateCredentials::LoginTemplateCredentials()
  5. : ref(1), title(NULL), accountRecoverUrl(NULL), accountCreateUrl(NULL), usernameLabel(NULL), passwordLabel(NULL)
  6. {
  7. }
  8. LoginTemplateCredentials::~LoginTemplateCredentials()
  9. {
  10. LoginBox_FreeString(title);
  11. LoginBox_FreeString(accountRecoverUrl);
  12. LoginBox_FreeString(accountCreateUrl);
  13. LoginBox_FreeString(usernameLabel);
  14. LoginBox_FreeString(passwordLabel);
  15. }
  16. HRESULT LoginTemplateCredentials::CreateInstance(LoginTemplateCredentials **instance)
  17. {
  18. if (NULL == instance) return E_POINTER;
  19. *instance = new LoginTemplateCredentials();
  20. if (NULL == *instance) return E_OUTOFMEMORY;
  21. return S_OK;
  22. }
  23. ULONG LoginTemplateCredentials::AddRef()
  24. {
  25. return InterlockedIncrement((LONG*)&ref);
  26. }
  27. ULONG LoginTemplateCredentials::Release()
  28. {
  29. if (0 == ref)
  30. return ref;
  31. LONG r = InterlockedDecrement((LONG*)&ref);
  32. if (0 == r)
  33. delete(this);
  34. return r;
  35. }
  36. HRESULT LoginTemplateCredentials::GetType(GUID *templateUid)
  37. {
  38. if (NULL == templateUid) return E_INVALIDARG;
  39. *templateUid = LTUID_CREDENTIALS;
  40. return S_OK;
  41. }
  42. HRESULT LoginTemplateCredentials::SetParameter(LPCWSTR pszKey, LPCWSTR pszValue)
  43. {
  44. if (S_OK == LoginBox_IsStrEqInvI(pszKey, L"title"))
  45. {
  46. LoginBox_FreeString(title);
  47. title = LoginBox_CopyString(pszValue);
  48. }
  49. else if (S_OK == LoginBox_IsStrEqInvI(pszKey, L"accountRecoverUrl"))
  50. {
  51. LoginBox_FreeString(accountRecoverUrl);
  52. accountRecoverUrl = LoginBox_CopyString(pszValue);
  53. }
  54. else if (S_OK == LoginBox_IsStrEqInvI(pszKey, L"accountCreateUrl"))
  55. {
  56. LoginBox_FreeString(accountCreateUrl);
  57. accountCreateUrl = LoginBox_CopyString(pszValue);
  58. }
  59. else if (S_OK == LoginBox_IsStrEqInvI(pszKey, L"usernameLabel"))
  60. {
  61. LoginBox_FreeString(usernameLabel);
  62. usernameLabel = LoginBox_CopyString(pszValue);
  63. }
  64. else if (S_OK == LoginBox_IsStrEqInvI(pszKey, L"passwordLabel"))
  65. {
  66. LoginBox_FreeString(passwordLabel);
  67. passwordLabel = LoginBox_CopyString(pszValue);
  68. }
  69. return S_OK;
  70. }
  71. HRESULT LoginTemplateCredentials::IsValid()
  72. {
  73. return S_OK;
  74. }
  75. HRESULT LoginTemplateCredentials::IsIdentical(LoginTemplate *test)
  76. {
  77. if (NULL == test)
  78. return E_INVALIDARG;
  79. GUID typeId;
  80. if (FAILED(test->GetType(&typeId)) || FALSE == IsEqualGUID(LTUID_CREDENTIALS, typeId))
  81. return S_FALSE;
  82. LoginTemplateCredentials *testCred = (LoginTemplateCredentials*)test;
  83. if(S_OK != LoginBox_IsStrEq(title, testCred->title) ||
  84. S_OK != LoginBox_IsStrEqInvI(accountRecoverUrl, testCred->accountRecoverUrl) ||
  85. S_OK != LoginBox_IsStrEqInvI(accountCreateUrl, testCred->accountCreateUrl) ||
  86. S_OK != LoginBox_IsStrEq(usernameLabel, testCred->usernameLabel) ||
  87. S_OK != LoginBox_IsStrEq(passwordLabel, testCred->passwordLabel))
  88. {
  89. return S_FALSE;
  90. }
  91. return S_OK;
  92. }
  93. HWND LoginTemplateCredentials::CreatePage(HWND hLoginbox, HWND hParent)
  94. {
  95. HWND hPage = LoginPageCredentials::CreatePage(hLoginbox, hParent);
  96. if (NULL == hPage) return NULL;
  97. if (NULL != title)
  98. LoginPage_SetTitle(hPage, title);
  99. if (NULL != accountRecoverUrl)
  100. LoginPageCredentials_SetAccountRecoverUrl(hPage, accountRecoverUrl);
  101. if (NULL != accountCreateUrl)
  102. LoginPageCredentials_SetAccountCreateUrl(hPage, accountCreateUrl);
  103. if (NULL != usernameLabel)
  104. LoginPageCredentials_SetUsernameLabel(hPage, usernameLabel);
  105. if (NULL != passwordLabel)
  106. LoginPageCredentials_SetPasswordLabel(hPage, passwordLabel);
  107. return hPage;
  108. }