feat(GODT-2540): notify user of wrong IMAP password.

This commit is contained in:
Xavier Michelon
2023-04-25 18:39:23 +02:00
parent 543c35041d
commit 6a6ead8e6d
9 changed files with 128 additions and 36 deletions

View File

@ -34,9 +34,7 @@ SPUser User::newUser(QObject *parent) {
/// \param[in] parent The parent object.
//****************************************************************************************************************************************************
User::User(QObject *parent)
: QObject(parent)
, imapFailureCooldownEndTime_(QDateTime::currentDateTime()) {
: QObject(parent) {
}
@ -355,22 +353,18 @@ QString User::stateToString(UserState state) {
//****************************************************************************************************************************************************
/// We display a notification and pop the application window if an IMAP client tries to connect to a signed out account, but we do not want to
/// do it repeatedly, as it's an intrusive action. This function let's you define a period of time during which the notification should not be
/// displayed.
///
/// \param durationMSecs The duration of the period in milliseconds.
/// \param[in] durationMSecs The duration of the period in milliseconds.
//****************************************************************************************************************************************************
void User::startImapLoginFailureCooldown(qint64 durationMSecs) {
imapFailureCooldownEndTime_ = QDateTime::currentDateTime().addMSecs(durationMSecs);
void User::startNotificationCooldownPeriod(User::ENotification notification, qint64 durationMSecs) {
notificationCooldownList_[notification] = QDateTime::currentDateTime().addMSecs(durationMSecs);
}
//****************************************************************************************************************************************************
/// \return true if we currently are in a cooldown period for the notification
/// \return true iff the notification is currently in a cooldown period.
//****************************************************************************************************************************************************
bool User::isInIMAPLoginFailureCooldown() const {
return QDateTime::currentDateTime() < imapFailureCooldownEndTime_;
bool User::isNotificationInCooldown(User::ENotification notification) const {
return notificationCooldownList_.contains(notification) && (QDateTime::currentDateTime() < notificationCooldownList_[notification]);
}

View File

@ -62,6 +62,12 @@ typedef std::shared_ptr<class User> SPUser; ///< Type definition for shared poin
class User : public QObject {
Q_OBJECT
public: // data types
enum class ENotification {
IMAPLoginWhileSignedOut, ///< An IMAP client tried to login while the user is signed out.
IMAPPasswordFailure, ///< An IMAP client provided an invalid password for the user.
};
public: // static member function
static SPUser newUser(QObject *parent); ///< Create a new user
static QString stateToString(UserState state); ///< Return a string describing a user state.
@ -74,8 +80,8 @@ public: // member functions.
User &operator=(User &&) = delete; ///< Disabled move assignment operator.
void update(User const &user); ///< Update the user.
Q_INVOKABLE QString primaryEmailOrUsername() const; ///< Return the user primary email, or, if unknown its username.
void startImapLoginFailureCooldown(qint64 durationMSecs); ///< Start the user cooldown period for the IMAP login attempt while signed-out notification.
bool isInIMAPLoginFailureCooldown() const; ///< Check if the user in a IMAP login failure notification.
void startNotificationCooldownPeriod(ENotification notification, qint64 durationMSecs); ///< Start the user cooldown period for a notification.
bool isNotificationInCooldown(ENotification notification) const; ///< Return true iff the notification is in a cooldown period.
public slots:
// slots for QML generated calls
@ -147,7 +153,7 @@ private: // member functions.
User(QObject *parent); ///< Default constructor.
private: // data members.
QDateTime imapFailureCooldownEndTime_; ///< The end date/time for the IMAP login failure notification cooldown period.
QMap<ENotification, QDateTime> notificationCooldownList_; ///< A list of cooldown period end time for notifications.
QString id_; ///< The userID.
QString username_; ///< The username
QString password_; ///< The IMAP password of the user.