Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

401 lines
7.0 KiB

  1. /*++
  2. Copyright (c) 1994-1998 Microsoft Corporation
  3. Module Name :
  4. anondlg.cpp
  5. Abstract:
  6. WWW Anonymous account dialog
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. //
  14. // Include Files
  15. //
  16. #include "stdafx.h"
  17. #include "w3scfg.h"
  18. #include "anondlg.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. CAnonymousDlg::CAnonymousDlg(
  25. IN CString & strServerName,
  26. IN CString & strUserName,
  27. IN CString & strPassword,
  28. IN BOOL & fPasswordSync,
  29. IN CWnd * pParent OPTIONAL
  30. )
  31. /*++
  32. Routine Description:
  33. Constructor
  34. Arguments:
  35. CString & strServerName : Server name
  36. CString & strUserName : User name
  37. CString & strPassword : Password
  38. BOOL & fPasswordSync : TRUE for password sync
  39. CWnd * pParent : Optional parent window
  40. Return Value:
  41. N/A
  42. --*/
  43. : CDialog(CAnonymousDlg::IDD, pParent),
  44. m_strServerName(strServerName),
  45. m_strUserName(strUserName),
  46. m_strPassword(strPassword),
  47. m_fPasswordSync(fPasswordSync),
  48. m_fPasswordSyncChanged(FALSE),
  49. m_fUserNameChanged(FALSE),
  50. m_fPasswordSyncMsgShown(FALSE)
  51. {
  52. #if 0 // Keep class wizard happy
  53. //{{AFX_DATA_INIT(CAnonymousDlg)
  54. m_strUserName = _T("");
  55. m_fPasswordSync = FALSE;
  56. //}}AFX_DATA_INIT
  57. m_strPassword = _T("");
  58. #endif // 0
  59. }
  60. void
  61. CAnonymousDlg::DoDataExchange(
  62. IN CDataExchange * pDX
  63. )
  64. /*++
  65. Routine Description:
  66. Initialise/Store control data
  67. Arguments:
  68. CDataExchange * pDX - DDX/DDV control structure
  69. Return Value:
  70. None
  71. --*/
  72. {
  73. CDialog::DoDataExchange(pDX);
  74. //{{AFX_DATA_MAP(CAnonymousDlg)
  75. DDX_Check(pDX, IDC_CHECK_ENABLE_PW_SYNCHRONIZATION, m_fPasswordSync);
  76. DDX_Control(pDX, IDC_EDIT_USERNAME, m_edit_UserName);
  77. DDX_Control(pDX, IDC_EDIT_PASSWORD, m_edit_Password);
  78. DDX_Control(pDX, IDC_STATIC_USERNAME, m_static_Username);
  79. DDX_Control(pDX, IDC_STATIC_PASSWORD, m_static_Password);
  80. DDX_Control(pDX, IDC_STATIC_ANONYMOUS_LOGON, m_group_AnonymousLogon);
  81. DDX_Control(pDX, IDC_CHECK_ENABLE_PW_SYNCHRONIZATION, m_chk_PasswordSync);
  82. DDX_Control(pDX, IDC_BUTTON_CHECK_PASSWORD, m_button_CheckPassword);
  83. //}}AFX_DATA_MAP
  84. DDX_Text(pDX, IDC_EDIT_USERNAME, m_strUserName);
  85. DDV_MinMaxChars(pDX, m_strUserName, 1, UNLEN);
  86. //
  87. // Some people have a tendency to add "\\" before
  88. // the computer name in user accounts. Fix this here.
  89. //
  90. m_strUserName.TrimLeft();
  91. while (*m_strUserName == '\\')
  92. {
  93. m_strUserName = m_strUserName.Mid(2);
  94. }
  95. //
  96. // Display the remote password sync message if
  97. // password sync is on, the account is not local,
  98. // password sync has changed or username has changed
  99. // and the message hasn't already be shown.
  100. //
  101. if (pDX->m_bSaveAndValidate && m_fPasswordSync
  102. && !IsLocalAccount(m_strUserName)
  103. && (m_fPasswordSyncChanged || m_fUserNameChanged)
  104. && !m_fPasswordSyncMsgShown
  105. )
  106. {
  107. if (::AfxMessageBox(
  108. IDS_WRN_PWSYNC,
  109. MB_YESNO | MB_DEFBUTTON2 | MB_ICONQUESTION
  110. ) != IDYES)
  111. {
  112. pDX->Fail();
  113. }
  114. //
  115. // Don't show it again
  116. //
  117. m_fPasswordSyncMsgShown = TRUE;
  118. }
  119. if (!m_fPasswordSync || !pDX->m_bSaveAndValidate)
  120. {
  121. DDX_Password(
  122. pDX,
  123. IDC_EDIT_PASSWORD,
  124. m_strPassword,
  125. g_lpszDummyPassword
  126. );
  127. }
  128. if (!m_fPasswordSync)
  129. {
  130. DDV_MaxChars(pDX, m_strPassword, PWLEN);
  131. }
  132. }
  133. //
  134. // Message Map
  135. //
  136. BEGIN_MESSAGE_MAP(CAnonymousDlg, CDialog)
  137. //{{AFX_MSG_MAP(CAnonymousDlg)
  138. ON_BN_CLICKED(IDC_BUTTON_BROWSE_USERS, OnButtonBrowseUsers)
  139. ON_BN_CLICKED(IDC_BUTTON_CHECK_PASSWORD, OnButtonCheckPassword)
  140. ON_BN_CLICKED(IDC_CHECK_ENABLE_PW_SYNCHRONIZATION, OnCheckEnablePwSynchronization)
  141. ON_EN_CHANGE(IDC_EDIT_USERNAME, OnChangeEditUsername)
  142. //}}AFX_MSG_MAP
  143. ON_EN_CHANGE(IDC_EDIT_PASSWORD, OnItemChanged)
  144. ON_EN_CHANGE(IDC_EDIT_DOMAIN_NAME, OnItemChanged)
  145. ON_EN_CHANGE(IDC_EDIT_BASIC_DOMAIN, OnItemChanged)
  146. END_MESSAGE_MAP()
  147. void
  148. CAnonymousDlg::SetControlStates()
  149. /*++
  150. Routine Description:
  151. Set the states of the dialog control depending on its current
  152. values.
  153. Arguments:
  154. None
  155. Return Value:
  156. None
  157. --*/
  158. {
  159. m_static_Password.EnableWindow(!m_fPasswordSync);
  160. m_edit_Password.EnableWindow(!m_fPasswordSync);
  161. m_button_CheckPassword.EnableWindow(!m_fPasswordSync);
  162. }
  163. //
  164. // Message Handlers
  165. //
  166. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  167. BOOL
  168. CAnonymousDlg::OnInitDialog()
  169. /*++
  170. Routine Description:
  171. WM_INITDIALOG handler. Initialize the dialog.
  172. Arguments:
  173. None.
  174. Return Value:
  175. TRUE if no focus is to be set automatically, FALSE if the focus
  176. is already set.
  177. --*/
  178. {
  179. CDialog::OnInitDialog();
  180. SetControlStates();
  181. return TRUE;
  182. }
  183. void
  184. CAnonymousDlg::OnItemChanged()
  185. /*++
  186. Routine Description:
  187. All EN_CHANGE and BN_CLICKED messages map to this function
  188. Arguments:
  189. None
  190. Return Value:
  191. None
  192. --*/
  193. {
  194. SetControlStates();
  195. }
  196. void
  197. CAnonymousDlg::OnButtonBrowseUsers()
  198. /*++
  199. Routine Description:
  200. User browse dialog pressed, bring up
  201. the user browser
  202. Arguments:
  203. None
  204. Return Value:
  205. None
  206. --*/
  207. {
  208. CString str;
  209. if (GetIUsrAccount(m_strServerName, this, str))
  210. {
  211. //
  212. // If the name is non-local (determined by having
  213. // a slash in the name, password sync is disabled,
  214. // and a password should be entered.
  215. //
  216. m_edit_UserName.SetWindowText(str);
  217. if (!(m_fPasswordSync = IsLocalAccount(str)))
  218. {
  219. m_edit_Password.SetWindowText(_T(""));
  220. m_edit_Password.SetFocus();
  221. }
  222. m_chk_PasswordSync.SetCheck(m_fPasswordSync);
  223. OnItemChanged();
  224. }
  225. }
  226. void
  227. CAnonymousDlg::OnButtonCheckPassword()
  228. /*++
  229. Routine Description:
  230. Check password button has been pressed.
  231. Arguments:
  232. None
  233. Return Value:
  234. None
  235. --*/
  236. {
  237. if (!UpdateData(TRUE))
  238. {
  239. return;
  240. }
  241. CError err(VerifyUserPassword(m_strUserName, m_strPassword));
  242. if (!err.MessageBoxOnFailure())
  243. {
  244. ::AfxMessageBox(IDS_PASSWORD_OK);
  245. }
  246. }
  247. void
  248. CAnonymousDlg::OnCheckEnablePwSynchronization()
  249. /*++
  250. Routine Description:
  251. Handler for 'enable password synchronization' checkbox press
  252. Arguments:
  253. None
  254. Return Value:
  255. None
  256. --*/
  257. {
  258. m_fPasswordSyncChanged = TRUE;
  259. m_fPasswordSync = !m_fPasswordSync;
  260. OnItemChanged();
  261. SetControlStates();
  262. if (!m_fPasswordSync )
  263. {
  264. m_edit_Password.SetSel(0,-1);
  265. m_edit_Password.SetFocus();
  266. }
  267. }
  268. void
  269. CAnonymousDlg::OnChangeEditUsername()
  270. /*++
  271. Routine description:
  272. Handler for 'username' edit box change messages
  273. Arguments:
  274. None
  275. Return Value:
  276. None
  277. --*/
  278. {
  279. m_fUserNameChanged = TRUE;
  280. OnItemChanged();
  281. }