Skip to content

Commit

Permalink
[Jabber] Added captcha support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruslan Nigmatullin committed Mar 24, 2012
1 parent 8df3ce4 commit 23a0ea7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion protocols/jabber/jreen
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ void JDataFormPrivate::init(JDataForm *that, const Jreen::DataForm::Ptr &form, c
QGridLayout *layout = new QGridLayout(that);
that->setLayout(layout);
layout->addWidget(widget = AbstractDataForm::get(root, buttons));
QObject::connect(widget, SIGNAL(accepted()), that, SIGNAL(accepted()));
}

JDataForm::JDataForm(const Jreen::DataForm::Ptr &form,
Expand Down
4 changes: 4 additions & 0 deletions protocols/jabber/src/protocol/account/dataform/jdataform.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class JDataForm : public QWidget
~JDataForm();
qutim_sdk_0_3::AbstractDataForm *widget();
Jreen::DataForm::Ptr getDataForm();

signals:
void accepted();

private:
QScopedPointer<JDataFormPrivate> d_ptr;
};
Expand Down
42 changes: 41 additions & 1 deletion protocols/jabber/src/protocol/account/muc/jmucsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@
#include "../roster/jcontactresource_p.h"
#include <jreen/client.h>
#include "../roster/jsoftwaredetection.h"
#include "../dataform/jdataform.h"
#include <jreen/captcha.h>
#include <QVBoxLayout>
#include <qutim/notification.h>
#include <QApplication>
#include <qutim/debug.h>
#include <QInputDialog>
#include <QLabel>
#include <QTimer>

using namespace Jreen;
Expand Down Expand Up @@ -511,7 +515,31 @@ void JMUCSession::onMessage(Jreen::Message msg, bool priv)

void JMUCSession::onServiceMessage(const Jreen::Message &msg)
{
//TODO add capthca handler
Q_D(JMUCSession);
Captcha::Ptr captcha = msg.payload<Captcha>();
debug() << Q_FUNC_INFO
<< msg.body()
<< captcha.data()
<< (captcha ? captcha->form().data() : reinterpret_cast<DataForm*>(0));
if (captcha && captcha->form()) {
QString text = tr("Conference \"%1\" requires you to fill the captcha to enter the room")
.arg(d->jid.bare());
QWidget *widget = new QWidget;
QVBoxLayout *layout = new QVBoxLayout(widget);
QLabel *label = new QLabel(text, widget);
JDataForm *form = new JDataForm(captcha->form(),
msg.payloads<BitsOfBinary>(),
AbstractDataForm::Ok | AbstractDataForm::Cancel,
widget);
form->layout()->setMargin(0);
layout->addWidget(label);
layout->addWidget(form);
connect(form, SIGNAL(accepted()), SLOT(onCaptchaFilled()));
connect(form->widget(), SIGNAL(accepted()), widget, SLOT(deleteLater()));
connect(form->widget(), SIGNAL(rejected()), widget, SLOT(deleteLater()));
widget->show();
return;
}
if (!msg.subject().isEmpty())
return;
ChatSession *chatSession = ChatLayer::get(this, true);
Expand Down Expand Up @@ -801,5 +829,17 @@ void JMUCSession::onNickSelected(const QString &nick)
}
}

void JMUCSession::onCaptchaFilled()
{
Q_D(JMUCSession);
JDataForm *form = qobject_cast<JDataForm*>(sender());
Client *client = d->account.data()->client();
Jreen::IQ iq(Jreen::IQ::Set, d->jid.bareJID());
Captcha::Ptr captcha = Captcha::Ptr::create();
captcha->setForm(form->getDataForm());
iq.addPayload(captcha);
client->send(iq);
}

}

1 change: 1 addition & 0 deletions protocols/jabber/src/protocol/account/muc/jmucsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected slots:
void onServiceMessage(const Jreen::Message &msg);
void onError(Jreen::Error::Ptr error);
void onNickSelected(const QString &nick);
void onCaptchaFilled();
// bool handleMUCRoomCreation(gloox::MUCRoom *room);
// void handleMUCInviteDecline(gloox::MUCRoom *room, const gloox::JID &invitee,
// const std::string &reason);
Expand Down

0 comments on commit 23a0ea7

Please sign in to comment.