1 
2 /***************************************************************************
3                    Change the password of a Jabber account
4                              -------------------
5     begin                : Tue May 31 2005
6     copyright            : (C) 2005 by Till Gerken <till@tantalo.net>
7 
8 		Kopete (C) 2001-2005 Kopete developers <kopete-devel@kde.org>
9  ***************************************************************************/
10 
11 /***************************************************************************
12  *                                                                         *
13  *   This program is free software; you can redistribute it and/or modify  *
14  *   it under the terms of the GNU General Public License as published by  *
15  *   the Free Software Foundation; either version 2 of the License, or     *
16  *   (at your option) any later version.                                   *
17  *                                                                         *
18  ***************************************************************************/
19 
20 #include "dlgjabberchangepassword.h"
21 
22 #include "jabber_protocol_debug.h"
23 #include <KLocalizedString>
24 #include <QLineEdit>
25 #include <kmessagebox.h>
26 #include <qlabel.h>
27 #include <qlineedit.h>
28 #include <kopetepassword.h>
29 #include <xmpp_tasks.h>
30 #include "jabberaccount.h"
31 #include "ui_dlgchangepassword.h"
32 
DlgJabberChangePassword(JabberAccount * account,QWidget * parent)33 DlgJabberChangePassword::DlgJabberChangePassword ( JabberAccount *account, QWidget *parent )
34  : KDialog ( parent )
35 {
36 	setCaption( i18n("Change Jabber Password") );
37 	setButtons( KDialog::Ok | KDialog::Cancel );
38 	setDefaultButton( KDialog::Ok );
39 	showButtonSeparator( true );
40 
41 	m_account = account;
42 
43 	new QWidget( this );
44 	m_mainWidget = new Ui::DlgChangePassword;
45 	m_mainWidget->setupUi( mainWidget() );
46 
47     m_mainWidget->peNewPassword1->setEchoMode(QLineEdit::Password);
48     m_mainWidget->peNewPassword2->setEchoMode(QLineEdit::Password);
49     m_mainWidget->peCurrentPassword->setEchoMode(QLineEdit::Password);
50     connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
51     connect(this,SIGNAL(cancelClicked()),this,SLOT(slotCancel()));
52 }
53 
~DlgJabberChangePassword()54 DlgJabberChangePassword::~DlgJabberChangePassword()
55 {
56 	delete m_mainWidget;
57 }
58 
slotOk()59 void DlgJabberChangePassword::slotOk ()
60 {
61 	if ( m_account->password().cachedValue () != m_mainWidget->peCurrentPassword->text() )
62 	{
63 		KMessageBox::sorry ( this,
64 							 i18n ( "You entered your current password incorrectly." ),
65 							 i18n ( "Password Incorrect" ) );
66 		return;
67 	}
68 
69 	if ( m_mainWidget->peNewPassword1->text() !=  m_mainWidget->peNewPassword2->text() )
70 	{
71 		KMessageBox::sorry ( this,
72 							 i18n ( "Your new passwords do not match. Please enter them again." ),
73 							 i18n ( "Password Incorrect" ) );
74 		return;
75 	}
76 
77 	if ( m_mainWidget->peNewPassword1->text().isEmpty() )
78 	{
79 		KMessageBox::sorry ( this,
80 							 i18n ( "For security reasons, you are not allowed to set an empty password." ),
81 							 i18n ( "Password Incorrect" ) );
82 		return;
83 	}
84 
85 	if ( !m_account->isConnected () )
86 	{
87 		if ( KMessageBox::questionYesNo ( this,
88 										  i18n ( "Your account needs to be connected before the password can be changed. Do you want to try to connect now?" ),
89 		                                  i18n ( "Jabber Password Change" ), KGuiItem( i18n("Connect") ), KGuiItem( i18n("Stay Offline") ) ) == KMessageBox::Yes )
90 		{
91 			connect ( m_account, SIGNAL (isConnectedChanged()), this, SLOT (slotChangePassword()) );
92 			m_account->connect ();
93 		}
94 	}
95 	else
96 	{
97 		slotChangePassword();
98 	}
99 
100 }
101 
slotCancel()102 void DlgJabberChangePassword::slotCancel ()
103 {
104 
105 	deleteLater ();
106 
107 }
108 
slotChangePassword()109 void DlgJabberChangePassword::slotChangePassword ()
110 {
111 
112 	XMPP::JT_Register *task = new XMPP::JT_Register ( m_account->client()->rootTask () );
113 	QObject::connect ( task, SIGNAL (finished()), this, SLOT (slotChangePasswordDone()) );
114 
115 	task->changepw ( m_mainWidget->peNewPassword1->text () );
116 	task->go ( true );
117 
118 }
119 
slotChangePasswordDone()120 void DlgJabberChangePassword::slotChangePasswordDone ()
121 {
122 
123 	XMPP::JT_Register *task = (XMPP::JT_Register *) sender ();
124 
125 	if ( task->success () )
126 	{
127 		KMessageBox::information ( dynamic_cast<QWidget*>(parent()),
128 								   i18n ( "Your password has been changed successfully. Please note that the change may not be instantaneous. If you have problems logging in with your new password, please contact the administrator." ),
129 								   i18n ( "Jabber Password Change" ) );
130 
131 		m_account->password().set ( m_mainWidget->peNewPassword1->text () );
132 	}
133 	else
134 	{
135 		KMessageBox::sorry ( dynamic_cast<QWidget*>(parent()),
136 							 i18n ( "Your password could not be changed. Either your server does not support this feature or the administrator does not allow you to change your password." ) );
137 	}
138 
139 	deleteLater();
140 
141 }
142 
143