/*
* Copyright (C) 2014-2019 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#include
#include "src/datovka_shared/log/log.h"
#include "src/net/isds_const.h"
#include "src/worker/task_change_password.h"
#include "src/xml/xml_base.h"
#include "src/xml/xml_login.h"
TaskChangePassword::TaskChangePassword(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, const QString &dbOTPType, const QString &oldPwd,
const QString &newPwd)
: m_result(DL_ERR),
m_isdsText(),
m_ctx(ctx),
m_netLayer(netLayer),
m_dbOTPType(dbOTPType),
m_oldPwd(oldPwd),
m_newPwd(newPwd)
{
}
void TaskChangePassword::run(void)
{
if (Q_NULLPTR == m_netLayer) {
Q_ASSERT(0);
return;
}
/* ### Worker task begin. ### */
logDebugLv0NL("%s", "--------------CHANGE PASSWORD TASK-------------");
logDebugLv0NL("Starting in thread '%p'", QThread::currentThreadId());
m_result = changePassword(m_ctx, m_netLayer, m_dbOTPType,
m_oldPwd, m_newPwd);
m_isdsText = m_ctx.last_isds_msg;
logDebugLv0NL("Finished in thread '%p'", QThread::currentThreadId());
logDebugLv0NL("%s", "-----------------------------------------------");
/* ### Worker task end. ### */
}
enum TaskChangePassword::Result TaskChangePassword::changePassword(
IsdsSession::IsdsContext &ctx, NetLayer *netLayer, const QString &dbOTPType,
const QString &oldPwd, const QString &newPwd)
{
if (ctx.username.isEmpty()) {
logErrorNL("%s", "Account user name missing!");
Q_ASSERT(0);
return DL_ERR;
}
logDebugLv1NL("Sending from account '%s'",
ctx.account_name.toUtf8().constData());
QByteArray xmlDataOut;
/* Send SOAP request */
if (dbOTPType == OTP_NO_OTP) {
if (!netLayer->createChangePwdRequest(ctx, DB_SERVICE,
Xml::xmlCreateChangeISDSPasswordSoapRequest(oldPwd,
newPwd), xmlDataOut)) {
logErrorNL("ISDS returns: '%s'",
ctx.last_isds_msg.toUtf8().constData());
return DL_ISDS_ERROR;
}
} else {
if (!netLayer->createChangePwdRequest(ctx, OTP_CHNG_PWD_SERVICE,
Xml::xmlCreateChangePasswordOTPSoapRequest(dbOTPType,
oldPwd, newPwd), xmlDataOut)) {
logErrorNL("ISDS returns: '%s'",
ctx.last_isds_msg.toUtf8().constData());
return DL_ISDS_ERROR;
}
}
/* Parse SOAP response */
if (!Xml::parseDbStatusFromXml(xmlDataOut, ctx.last_isds_msg)) {
logErrorNL("ISDS returns: '%s'",
ctx.last_isds_msg.toUtf8().constData());
return DL_XML_ERROR;
}
logDebugLv1NL("%s", "Password has been changed");
return DL_SUCCESS;
}