2018-10-23 13:58:34 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: creddlg.h
|
|
|
|
// Created: 2018-10-23
|
|
|
|
// Copyright: (c) 2018 wxWidgets development team
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxCredentialEntryDialog
|
|
|
|
|
|
|
|
This class represents a dialog that requests a user name and a password
|
2021-01-09 19:53:32 -05:00
|
|
|
from the user.
|
|
|
|
|
|
|
|
Currently it is implemented as a generic wxWidgets dialog on all platforms.
|
|
|
|
|
|
|
|
Simple example of using this dialog assuming @c MyFrame object has a member
|
|
|
|
@c m_request of wxWebRequest type:
|
|
|
|
@code
|
|
|
|
void MyFrame::OnWebRequestState(wxWebRequestEvent& evt)
|
|
|
|
{
|
|
|
|
if ( evt.GetState() == wxWebRequest::State_Unauthorized )
|
|
|
|
{
|
|
|
|
wxCredentialEntryDialog dialog
|
|
|
|
(
|
|
|
|
this,
|
|
|
|
wxString::Format
|
|
|
|
(
|
|
|
|
"Please enter credentials for accessing "
|
|
|
|
"the web page at %s",
|
|
|
|
evt.GetResponse().GetURL()
|
|
|
|
),
|
|
|
|
"My Application Title"
|
|
|
|
);
|
|
|
|
if ( dialog.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
m_request.GetAuthChallenge().
|
|
|
|
SetCredentials(dialog.GetCredentials());
|
|
|
|
}
|
|
|
|
//else: the dialog was cancelled
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@endcode
|
2018-10-23 13:58:34 -04:00
|
|
|
|
2018-11-02 10:54:14 -04:00
|
|
|
@note For secure saving and loading users and passwords, have a look at
|
2018-10-23 13:58:34 -04:00
|
|
|
wxSecretStore.
|
|
|
|
|
2020-12-12 18:50:03 -05:00
|
|
|
@since 3.1.5
|
2018-10-23 13:58:34 -04:00
|
|
|
|
|
|
|
@library{wxcore}
|
|
|
|
@category{cmndlg}
|
|
|
|
|
|
|
|
@see @ref overview_cmndlg_cred
|
|
|
|
*/
|
|
|
|
class wxCredentialEntryDialog: public wxDialog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Default constructor.
|
|
|
|
|
|
|
|
Call Create() to really create the dialog later.
|
|
|
|
*/
|
|
|
|
wxCredentialEntryDialog();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
|
|
|
|
Use ShowModal() to show the dialog.
|
|
|
|
|
|
|
|
See Create() method for parameter description.
|
|
|
|
*/
|
|
|
|
wxCredentialEntryDialog(wxWindow* parent, const wxString& message,
|
|
|
|
const wxString& title,
|
2021-01-09 19:53:32 -05:00
|
|
|
const wxWebCredentials& cred = wxWebCredentials());
|
2018-10-23 13:58:34 -04:00
|
|
|
|
|
|
|
/**
|
2020-12-12 18:18:27 -05:00
|
|
|
Create the dialog constructed using the default constructor.
|
|
|
|
|
2018-10-23 13:58:34 -04:00
|
|
|
@param parent
|
|
|
|
Parent window.
|
|
|
|
@param message
|
|
|
|
Message to show on the dialog.
|
|
|
|
@param title
|
2021-01-10 20:51:05 -05:00
|
|
|
Title of the dialog.
|
2021-01-09 19:53:32 -05:00
|
|
|
@param cred
|
|
|
|
The default username and password to use (optional).
|
2018-10-23 13:58:34 -04:00
|
|
|
*/
|
|
|
|
bool Create(wxWindow* parent, const wxString& message,
|
|
|
|
const wxString& title,
|
2021-01-09 19:53:32 -05:00
|
|
|
const wxWebCredentials& cred = wxWebCredentials());
|
2018-10-23 13:58:34 -04:00
|
|
|
|
|
|
|
/**
|
2021-01-09 19:53:32 -05:00
|
|
|
Returns the credentials entered by the user.
|
|
|
|
|
|
|
|
This should be called if ShowModal() returned ::wxID_OK.
|
2018-10-23 13:58:34 -04:00
|
|
|
*/
|
2021-01-09 19:53:32 -05:00
|
|
|
wxWebCredentials GetCredentials() const;
|
2018-10-23 13:58:34 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the current user name.
|
2020-12-12 18:18:27 -05:00
|
|
|
|
|
|
|
This function may be called before showing the dialog to provide the
|
|
|
|
default value for the user name, if it's different from the one given
|
|
|
|
at the creation time.
|
2018-10-23 13:58:34 -04:00
|
|
|
*/
|
|
|
|
void SetUser(const wxString& user);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the current password.
|
2020-12-12 18:18:27 -05:00
|
|
|
|
|
|
|
This function may be called before showing the dialog for the reasons
|
|
|
|
similar to SetUser().
|
2018-10-23 13:58:34 -04:00
|
|
|
*/
|
|
|
|
void SetPassword(const wxString& password);
|
|
|
|
};
|