//Sample code file: var/ndk/webBuildengine/tmp/viewable_samples/a4ad0b48-dd95-46b6-8289-721e99c8dc76/login_method/lcm/win32/UserInputDialog.cpp

//Warning: This code has been marked up for HTML

//
// UserInputDialog: dialog to get user input for the Simple Password
// Login Client Method
// Platform:   Windows Client
//
// Copyright (C) 2000-2001 Novell, Inc. All Rights Reserved. 
//
// THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
// TREATIES. USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE
// LICENSE AGREEMENT ACCOMPANYING THE SOFTWARE DEVELOPMENT KIT
// (SDK) THAT CONTAINS THIS WORK. PURSUANT TO THE SDK LICENSE
// AGREEMENT, NOVELL HEREBY GRANTS TO DEVELOPER A ROYALTY-FREE,
// NON-EXCLUSIVE LICENSE TO INCLUDE NOVELL'S SAMPLE CODE IN ITS
// PRODUCT. NOVELL GRANTS DEVELOPER WORLDWIDE DISTRIBUTION RIGHTS TO
// MARKET, DISTRIBUTE, OR SELL NOVELL'S SAMPLE CODE AS A COMPONENT OF
// DEVELOPER'S PRODUCTS. NOVELL SHALL HAVE NO OBLIGATIONS TO
// DEVELOPER OR DEVELOPER'S CUSTOMERS WITH RESPECT TO THIS CODE. 
class='cKeyword'>#include "stdafx.h"
class='cKeyword'>#include "guiwin32.h"
class='cKeyword'>#include "UserInputDialog.h"

class='cKeyword'>class='cKeyword'>#ifdef _DEBUG
class='cKeyword'>#define new DEBUG_NEW
class='cKeyword'>#undef THIS_FILE
static class='cKeyword'>char THIS_FILE[] = __FILE__;
class='cKeyword'>#endif

int ForceChgPwd = 0;

/////////////////////////////////////////////////////////////////////////////
// CUserInputDialog message handlers
/////////////////////////////////////////////////////////////////////////////
// UserInputDialog dialog


UserInputDialog::UserInputDialog(int forceChg, CWnd* pParent /*=NULL*/)
   : CDialog(UserInputDialog::IDD, pParent)
{
   ForceChgPwd = forceChg;

   //{{AFX_DATA_INIT(UserInputDialog)
   m_UserInput = _T("");
   m_ChangePassword = FALSE;
   m_newPwd = _T("");
   //}}AFX_DATA_INIT
}


void UserInputDialog::DoDataExchange(CDataExchange* pDX)
{
   CDialog::DoDataExchange(pDX);
   //{{AFX_DATA_MAP(UserInputDialog)
   DDX_Text(pDX, IDC_EDIT_BOX, m_UserInput);
   DDX_Check(pDX, IDD_CHANGE_PWD, m_ChangePassword);
   DDX_Text(pDX, IDC_CHANGE, m_newPwd);
   //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(UserInputDialog, CDialog)
   //{{AFX_MSG_MAP(UserInputDialog)
   ON_BN_CLICKED(IDD_CHANGE_PWD, OnChangePwd)
   //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// UserInputDialog message handlers

void UserInputDialog::OnChangePwd() 
{
   if ( ((CButton*)GetDlgItem( IDD_CHANGE_PWD ))->GetCheck() == 1 )
   {
      // TODO: Add your control notification handler code here
      ((CWnd*)GetDlgItem( IDC_CHANGE ))->EnableWindow(TRUE);
      ((CWnd*)GetDlgItem( IDC_CONFIRM))->EnableWindow(TRUE);

      ((CWnd*)GetDlgItem( IDC_NEW_PWD_LABEL))->EnableWindow(TRUE);
      ((CWnd*)GetDlgItem( IDC_CONFIRM_LABEL))->EnableWindow(TRUE);
   }
   else
   {
      ((CWnd*)GetDlgItem( IDC_CHANGE ))->EnableWindow(FALSE);
      ((CWnd*)GetDlgItem( IDC_CHANGE ))->SetWindowText("");

      ((CWnd*)GetDlgItem( IDC_CONFIRM))->EnableWindow(FALSE);
      ((CWnd*)GetDlgItem( IDC_CONFIRM))->SetWindowText("");
   
      ((CWnd*)GetDlgItem( IDC_NEW_PWD_LABEL))->EnableWindow(FALSE);
      ((CWnd*)GetDlgItem( IDC_CONFIRM_LABEL))->EnableWindow(FALSE);
   
   }
   OnPaint();
   
}

void UserInputDialog::OnOK() 
{
   CString confirm,errTitle,errMsg;


   if ( ((CButton*)GetDlgItem( IDD_CHANGE_PWD ))->GetCheck() == 1 )
   {
      m_ChangePassword = TRUE;
   } 
   else
   {
      m_ChangePassword = FALSE;
   }

      // TODO: Add extra validation here
   if ( m_ChangePassword == TRUE )
   {
      ((CWnd*)GetDlgItem( IDC_CHANGE ))->GetWindowText( m_newPwd );
      
      //make sure that the new password and confirm match
      ((CWnd*)GetDlgItem( IDC_CONFIRM ))->GetWindowText( confirm );
      if ( confirm!=m_newPwd)
      {
         errTitle.LoadString( IDS_PWD_CHANGED_TITLE );
         errMsg.LoadString( IDS_CHANGE_PWD_FAILED_CONFIRM );
         MessageBox( errMsg, errTitle, MB_OK | MB_ICONERROR );
         return;
      }
   }
   CDialog::OnOK();
}

BOOL UserInputDialog::OnInitDialog() 
{
   CDialog::OnInitDialog();

   if (ForceChgPwd)
   {
      ((CButton*)GetDlgItem( IDD_CHANGE_PWD ))->SetCheck(1);
      ((CWnd*)GetDlgItem( IDD_CHANGE_PWD ))->EnableWindow(FALSE);

      ((CWnd*)GetDlgItem( IDC_CHANGE ))->EnableWindow(TRUE);
      ((CWnd*)GetDlgItem( IDC_CONFIRM))->EnableWindow(TRUE);

      ((CWnd*)GetDlgItem( IDC_NEW_PWD_LABEL))->EnableWindow(TRUE);
      ((CWnd*)GetDlgItem( IDC_CONFIRM_LABEL))->EnableWindow(TRUE);
   }

   return TRUE;  // return TRUE unless you set the focus to a control
                 // EXCEPTION: OCX Property Pages should return FALSE
}