Main Page | Class List | File List | Class Members | File Members

ConfigUser.cpp

Go to the documentation of this file.
00001 /*
00002 pGina ldapAuth code - based upon skeleton code for pGina plugin development
00003 Copyright (C) 2002 Micah Cooper
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019 Email: coopermj@muohio.edu
00020 Snail Mail:
00021         Micah Cooper
00022         212A Kreger Hall
00023         Miami University
00024         Oxford OH  45056
00025 */
00026 // ConfigUser.cpp : implementation file
00027 //
00028 
00029 #include "stdafx.h"
00030 #include "ldapauth_plus.h"
00031 #include "ConfigUser.h"
00032 #include ".\configuser.h"
00033 
00034 
00035 // CConfigUser dialog
00036 
00037 IMPLEMENT_DYNAMIC(CConfigUser, CDialog)
00038 CConfigUser::CConfigUser(CWnd* pParent /*=NULL*/)
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 // CConfigUser message handlers
00075 void CConfigUser::OnOK()
00076 {
00077         return;
00078 }
00079 
00080 void CConfigUser::OnAddAdmin()
00081 {
00082         // TODO: Add your control notification handler code here
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         // TODO: Add your control notification handler code here
00096         if(m_AdminList.GetCurSel() >= 0)
00097                 m_AdminList.DeleteString(m_AdminList.GetCurSel());
00098 }
00099 
00100 void CConfigUser::OnAddUser()
00101 {
00102         // TODO: Add your control notification handler code here
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         // TODO: Add your control notification handler code here
00116         if(m_UserList.GetCurSel() >= 0)
00117                 m_UserList.DeleteString(m_UserList.GetCurSel());
00118 }
00119 
00120 void CConfigUser::loadListsFromReg(void)
00121 {
00122         // Load the content for the lists from the registry 
00123         WCHAR currentName[256];
00124         int x = 0;
00125         CString contextValue = NULL;
00126 
00127         // Then adminOKx
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         // Then userOKx
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         // Now for admin, save them
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         // Now loop through and delete any existing contexts above our last saved one
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         // then users
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         // Now loop through and delete any existing contexts above our last saved one
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         // Now for admin, save them
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         // Now loop through and delete any existing contexts above our last saved one
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         // then users
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         // Now loop through and delete any existing contexts above our last saved one
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 }

Generated on Fri Feb 20 12:03:40 2004 for ldapauth plugin for pGina by doxygen 1.3.5