00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "stdafx.h"
00030 #include "ldapauth_plus.h"
00031 #include "ConfigUser.h"
00032 #include ".\configuser.h"
00033
00034
00035
00036
00037 IMPLEMENT_DYNAMIC(CConfigUser, CDialog)
00038 CConfigUser::CConfigUser(CWnd* pParent )
00039 : CDialog(CConfigUser::IDD, pParent)
00040 , m_NewAdmin(_T(""))
00041 , m_newUser(_T(""))
00042 {
00043 hasLoaded = false;
00044 }
00045
00046 CConfigUser::~CConfigUser()
00047 {
00048 }
00049
00050 void CConfigUser::DoDataExchange(CDataExchange* pDX)
00051 {
00052 CDialog::DoDataExchange(pDX);
00053 DDX_Control(pDX, IDC_ADMINLIST, m_AdminList);
00054 DDX_Text(pDX, IDC_NEWADMIN, m_NewAdmin);
00055 DDX_Control(pDX, IDC_USERLIST, m_UserList);
00056 DDX_Text(pDX, IDC_NEWUSER, m_newUser);
00057
00058 if(!hasLoaded)
00059 {
00060 loadListsFromReg();
00061 hasLoaded = true;
00062 }
00063 }
00064
00065
00066 BEGIN_MESSAGE_MAP(CConfigUser, CDialog)
00067 ON_BN_CLICKED(IDC_ADDADMIN, OnAddAdmin)
00068 ON_BN_CLICKED(IDC_DELETEADMIN, OnRemoveAdmin)
00069 ON_BN_CLICKED(IDC_ADDUSER, OnAddUser)
00070 ON_BN_CLICKED(IDC_DELETEUSER, OnRemoveUser)
00071 END_MESSAGE_MAP()
00072
00073
00074
00075 void CConfigUser::OnOK()
00076 {
00077 return;
00078 }
00079
00080 void CConfigUser::OnAddAdmin()
00081 {
00082
00083 UpdateData(TRUE);
00084 if (m_NewAdmin == "") {
00085 MessageBox(L"Please enter a valid username", L"LDAPAuth", MB_OK);
00086 return;
00087 }
00088 m_AdminList.AddString(m_NewAdmin);
00089 m_NewAdmin = TEXT("");
00090 UpdateData(FALSE);
00091 }
00092
00093 void CConfigUser::OnRemoveAdmin()
00094 {
00095
00096 if(m_AdminList.GetCurSel() >= 0)
00097 m_AdminList.DeleteString(m_AdminList.GetCurSel());
00098 }
00099
00100 void CConfigUser::OnAddUser()
00101 {
00102
00103 UpdateData(TRUE);
00104 if (m_newUser == "") {
00105 MessageBox(L"Please enter a valid username", L"LDAPAuth", MB_OK);
00106 return;
00107 }
00108 m_UserList.AddString(m_newUser);
00109 m_newUser = TEXT("");
00110 UpdateData(FALSE);
00111 }
00112
00113 void CConfigUser::OnRemoveUser()
00114 {
00115
00116 if(m_UserList.GetCurSel() >= 0)
00117 m_UserList.DeleteString(m_UserList.GetCurSel());
00118 }
00119
00120 void CConfigUser::loadListsFromReg(void)
00121 {
00122
00123 WCHAR currentName[256];
00124 int x = 0;
00125 CString contextValue = NULL;
00126
00127
00128 swprintf(currentName,TEXT("adminOK%d"),x);
00129 contextValue = regReadString(currentName);
00130 while(contextValue.GetLength() > 0)
00131 {
00132 m_AdminList.AddString(contextValue);
00133 x++;
00134 swprintf(currentName,TEXT("adminOK%d"),x);
00135 contextValue = regReadString(currentName);
00136 }
00137
00138 x = 0;
00139
00140 swprintf(currentName,TEXT("userOK%d"),x);
00141 contextValue = regReadString(currentName);
00142 while(contextValue.GetLength() > 0)
00143 {
00144 m_UserList.AddString(contextValue);
00145 x++;
00146 swprintf(currentName,TEXT("userOK%d"),x);
00147 contextValue = regReadString(currentName);
00148 }
00149 }
00150
00151 void CConfigUser::saveListsToReg(void)
00152 {
00153 WCHAR currentName[256];
00154 CString value = NULL;
00155 int x = 0;
00156
00157
00158 for(x = 0; x < m_AdminList.GetCount(); x++)
00159 {
00160 m_AdminList.GetText(x,value);
00161 swprintf(currentName,TEXT("adminOK%d"),x);
00162 regWriteString(value.GetBuffer(value.GetLength()),currentName);
00163 }
00164
00165
00166 x = m_AdminList.GetCount();
00167 swprintf(currentName,TEXT("adminOK%d"),x);
00168 value = regReadString(currentName);
00169
00170 while(value.GetLength() > 0)
00171 {
00172 regDelValue(currentName);
00173 x++;
00174 swprintf(currentName,TEXT("adminOK%d"),x);
00175 value = regReadString(currentName);
00176 }
00177
00178
00179 for(x = 0; x < m_UserList.GetCount(); x++)
00180 {
00181 m_UserList.GetText(x,value);
00182 swprintf(currentName,TEXT("userOK%d"),x);
00183 regWriteString(value.GetBuffer(value.GetLength()),currentName);
00184 }
00185
00186
00187 x = m_UserList.GetCount();
00188 swprintf(currentName,TEXT("userOK%d"),x);
00189 value = regReadString(currentName);
00190
00191 while(value.GetLength() > 0)
00192 {
00193 regDelValue(currentName);
00194 x++;
00195 swprintf(currentName,TEXT("userOK%d"),x);
00196 value = regReadString(currentName);
00197 }
00198 }
00199
00200 void CConfigUser::OnSave(void)
00201 {
00202 UpdateData(TRUE);
00203 WCHAR currentName[256];
00204 CString value = NULL;
00205 int x = 0;
00206
00207
00208 for(x = 0; x < m_AdminList.GetCount(); x++)
00209 {
00210 m_AdminList.GetText(x,value);
00211 swprintf(currentName,TEXT("adminOK%d"),x);
00212 regWriteString(value.GetBuffer(value.GetLength()),currentName);
00213 }
00214
00215
00216 x = m_AdminList.GetCount();
00217 swprintf(currentName,TEXT("adminOK%d"),x);
00218 value = regReadString(currentName);
00219
00220 while(value.GetLength() > 0)
00221 {
00222 regDelValue(currentName);
00223 x++;
00224 swprintf(currentName,TEXT("adminOK%d"),x);
00225 value = regReadString(currentName);
00226 }
00227
00228
00229 for(x = 0; x < m_UserList.GetCount(); x++)
00230 {
00231 m_UserList.GetText(x,value);
00232 swprintf(currentName,TEXT("userOK%d"),x);
00233 regWriteString(value.GetBuffer(value.GetLength()),currentName);
00234 }
00235
00236
00237 x = m_UserList.GetCount();
00238 swprintf(currentName,TEXT("userOK%d"),x);
00239 value = regReadString(currentName);
00240
00241 while(value.GetLength() > 0)
00242 {
00243 regDelValue(currentName);
00244 x++;
00245 swprintf(currentName,TEXT("userOK%d"),x);
00246 value = regReadString(currentName);
00247 }
00248 }