New user dialog: Implement user options properly.
authorEric Kohl <eric.kohl@reactos.org>
Sat, 17 May 2008 14:00:39 +0000 (14:00 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 17 May 2008 14:00:39 +0000 (14:00 +0000)
svn path=/trunk/; revision=33554

reactos/dll/cpl/usrmgr/users.c

index 43c206f..fc8b80d 100644 (file)
@@ -116,6 +116,36 @@ ChangePasswordDlgProc(HWND hwndDlg,
 }\r
 \r
 \r
+static VOID\r
+UpdateUserOptions(HWND hwndDlg,\r
+                  PUSER_INFO_3 userInfo,\r
+                  BOOL bInit)\r
+{\r
+    EnableWindow(GetDlgItem(hwndDlg, IDC_USER_NEW_CANNOT_CHANGE),\r
+                 !userInfo->usri3_password_expired);\r
+    EnableWindow(GetDlgItem(hwndDlg, IDC_USER_NEW_NEVER_EXPIRES),\r
+                 !userInfo->usri3_password_expired);\r
+\r
+    EnableWindow(GetDlgItem(hwndDlg, IDC_USER_NEW_FORCE_CHANGE),\r
+                 (userInfo->usri3_flags & (UF_PASSWD_CANT_CHANGE | UF_DONT_EXPIRE_PASSWD)) == 0);\r
+\r
+    if (bInit)\r
+    {\r
+        CheckDlgButton(hwndDlg, IDC_USER_NEW_FORCE_CHANGE,\r
+                       userInfo->usri3_password_expired ? BST_CHECKED : BST_UNCHECKED);\r
+\r
+        CheckDlgButton(hwndDlg, IDC_USER_NEW_CANNOT_CHANGE,\r
+                       (userInfo->usri3_flags & UF_PASSWD_CANT_CHANGE) ? BST_CHECKED : BST_UNCHECKED);\r
+\r
+        CheckDlgButton(hwndDlg, IDC_USER_NEW_NEVER_EXPIRES,\r
+                       (userInfo->usri3_flags & UF_DONT_EXPIRE_PASSWD) ? BST_CHECKED : BST_UNCHECKED);\r
+\r
+        CheckDlgButton(hwndDlg, IDC_USER_NEW_DISABLED,\r
+                       (userInfo->usri3_flags & UF_ACCOUNTDISABLE) ? BST_CHECKED : BST_UNCHECKED);\r
+    }\r
+}\r
+\r
+\r
 INT_PTR CALLBACK\r
 NewUserDlgProc(HWND hwndDlg,\r
                UINT uMsg,\r
@@ -127,12 +157,15 @@ NewUserDlgProc(HWND hwndDlg,
 \r
     UNREFERENCED_PARAMETER(wParam);\r
 \r
+    userInfo = (PUSER_INFO_3)GetWindowLongPtr(hwndDlg, DWLP_USER);\r
+\r
     switch (uMsg)\r
     {\r
         case WM_INITDIALOG:\r
+            userInfo = (PUSER_INFO_3)lParam;\r
             SetWindowLongPtr(hwndDlg, DWLP_USER, lParam);\r
             SendDlgItemMessage(hwndDlg, IDC_USER_NEW_NAME, EM_SETLIMITTEXT, 20, 0);\r
-            CheckDlgButton(hwndDlg, IDC_USER_NEW_FORCE_CHANGE, BST_CHECKED);\r
+            UpdateUserOptions(hwndDlg, userInfo, TRUE);\r
             break;\r
 \r
         case WM_COMMAND:\r
@@ -146,6 +179,25 @@ NewUserDlgProc(HWND hwndDlg,
                     }\r
                     break;\r
 \r
+                case IDC_USER_NEW_FORCE_CHANGE:\r
+                    userInfo->usri3_password_expired = !userInfo->usri3_password_expired;\r
+                    UpdateUserOptions(hwndDlg, userInfo, FALSE);\r
+                    break;\r
+\r
+                case IDC_USER_NEW_CANNOT_CHANGE:\r
+                    userInfo->usri3_flags ^= UF_PASSWD_CANT_CHANGE;\r
+                    UpdateUserOptions(hwndDlg, userInfo, FALSE);\r
+                    break;\r
+\r
+                case IDC_USER_NEW_NEVER_EXPIRES:\r
+                    userInfo->usri3_flags ^= UF_DONT_EXPIRE_PASSWD;\r
+                    UpdateUserOptions(hwndDlg, userInfo, FALSE);\r
+                    break;\r
+\r
+                case IDC_USER_NEW_DISABLED:\r
+                    userInfo->usri3_flags ^= UF_ACCOUNTDISABLE;\r
+                    break;\r
+\r
                 case IDOK:\r
                     if (!CheckUserName(hwndDlg, IDC_USER_NEW_NAME))\r
                     {\r
@@ -161,8 +213,7 @@ NewUserDlgProc(HWND hwndDlg,
                         break;\r
                     }\r
 \r
-                    userInfo = (LPUSER_INFO_3)GetWindowLongPtr(hwndDlg, DWLP_USER);\r
-\r
+                    /* Store the user name */\r
                     nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_NAME, WM_GETTEXTLENGTH, 0, 0);\r
                     if (nLength > 0)\r
                     {\r
@@ -170,6 +221,7 @@ NewUserDlgProc(HWND hwndDlg,
                         GetDlgItemText(hwndDlg, IDC_USER_NEW_NAME, userInfo->usri3_name, nLength + 1);\r
                     }\r
 \r
+                    /* Store the full user name */\r
                     nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_FULL_NAME, WM_GETTEXTLENGTH, 0, 0);\r
                     if (nLength > 0)\r
                     {\r
@@ -177,6 +229,7 @@ NewUserDlgProc(HWND hwndDlg,
                         GetDlgItemText(hwndDlg, IDC_USER_NEW_FULL_NAME, userInfo->usri3_full_name, nLength + 1);\r
                     }\r
 \r
+                    /* Store the description */\r
                     nLength = SendDlgItemMessage(hwndDlg, IDC_USER_NEW_DESCRIPTION, WM_GETTEXTLENGTH, 0, 0);\r
                     if (nLength > 0)\r
                     {\r
@@ -192,12 +245,6 @@ NewUserDlgProc(HWND hwndDlg,
                         GetDlgItemText(hwndDlg, IDC_USER_NEW_PASSWORD1, userInfo->usri3_password, nLength + 1);\r
                     }\r
 \r
-                    if (IsDlgButtonChecked(hwndDlg, IDC_USER_NEW_FORCE_CHANGE) == BST_CHECKED)\r
-                        userInfo->usri3_password_expired = TRUE;\r
-\r
-                    if (IsDlgButtonChecked(hwndDlg, IDC_USER_NEW_DISABLED) == BST_CHECKED)\r
-                        userInfo->usri3_flags |= UF_ACCOUNTDISABLE;\r
-\r
                     EndDialog(hwndDlg, IDOK);\r
                     break;\r
 \r
@@ -232,6 +279,8 @@ UserNew(HWND hwndDlg)
     user.usri3_max_storage = USER_MAXSTORAGE_UNLIMITED;\r
     user.usri3_primary_group_id = DOMAIN_GROUP_RID_USERS;\r
 \r
+    user.usri3_password_expired = TRUE;\r
+\r
     if (DialogBoxParam(hApplet,\r
                        MAKEINTRESOURCE(IDD_USER_NEW),\r
                        hwndDlg,\r