task_change_password.h 3.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
/*
 * Copyright (C) 2014-2017 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 <http://www.gnu.org/licenses/>.
 *
 * 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.
 */

#ifndef _TASK_CHANGE_PASSWORD_H_
#define _TASK_CHANGE_PASSWORD_H_

#include "src/net/isds_session.h"
#include "src/net/net_layer.h"
#include "src/worker/task.h"

/*!
 * @brief Task describing change password.
 */
class TaskChangePassword : public Task {
public:
	/*!
	 * @brief Return state describing what happened.
	 */
	enum Result {
		DL_SUCCESS, /*!< Operation was successful. */
		DL_ISDS_ERROR, /*!< Error communicating with ISDS. */
		DL_XML_ERROR, /*!< Error xml parse. */
		DL_DB_INS_ERR, /*!< Error inserting into database. */
		DL_ERR /*!< Other error. */
	};

	/*!
	 * @brief Constructor.
	 *
	 * @param[in]     ctx            Account isds context (include username).
	 * @param[in]     netLayer       Pointer to network manager.
	 * @param[in]     dbOTPType      OTP login type (TOTP/HOTP).
	 * @param[in]     oldPwd         Old password.
	 * @param[in]     newPwd         New password.
	 */
	explicit TaskChangePassword(IsdsSession::IsdsContext &ctx,
	    NetLayer *netLayer, const QString &dbOTPType, const QString &oldPwd,
	    const QString &newPwd);

	/*!
	 * @brief Performs actual change password.
	 */
	virtual
	void run(void) Q_DECL_OVERRIDE;

	/*!
	 * @brief Change password.
	 *
	 * @param[in]     ctx            Account isds context (include username).
	 * @param[in]     netLayer       Pointer to network manager.
	 * @param[in]     dbOTPType      OTP login type (TOTP/HOTP).
	 * @param[in]     oldPwd         Old password.
	 * @param[in]     newPwd         New password.
	 * @return Error state.
	 */
	static
	enum Result changePassword(IsdsSession::IsdsContext &ctx,
	    NetLayer *netLayer, const QString &dbOTPType, const QString &oldPwd,
	    const QString &newPwd);

	enum Result m_result; /*!< Return state. */
82
	QString m_isdsText; /*!< Return isds result text. */
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

private:
	/*!
	 * Disable copy and assignment.
	 */
	TaskChangePassword(const TaskChangePassword &);
	TaskChangePassword &operator=(const TaskChangePassword &);

	IsdsSession::IsdsContext m_ctx; /*!< Account isds context. */
	NetLayer *m_netLayer; /*!< Pointer to network manager to send request. */
	QString m_dbOTPType; /*!< OTP login type (TOTP/HOTP). */
	QString m_oldPwd; /*!< Old password. */
	QString m_newPwd; /*!< New password. */
};

#endif /* _TASK_CHANGE_PASSWORD_H_ */