diff --git a/skeema/gradido_login/email_opt_in.sql b/skeema/gradido_login/email_opt_in.sql index f29f86034..a85c972c3 100644 --- a/skeema/gradido_login/email_opt_in.sql +++ b/skeema/gradido_login/email_opt_in.sql @@ -5,6 +5,7 @@ CREATE TABLE `email_opt_in` ( `email_opt_in_type_id` int(11) NOT NULL, `created` datetime NOT NULL DEFAULT current_timestamp(), `resend_count` int(11) DEFAULT 0, + `updated` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `verification_code` (`verification_code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; diff --git a/src/cpp/model/table/EmailOptIn.cpp b/src/cpp/model/table/EmailOptIn.cpp index e4cc8a021..c7871bef7 100644 --- a/src/cpp/model/table/EmailOptIn.cpp +++ b/src/cpp/model/table/EmailOptIn.cpp @@ -25,7 +25,9 @@ namespace model { } EmailOptIn::EmailOptIn(const EmailOptInTuple& tuple) - : ModelBase(tuple.get<0>()), mUserId(tuple.get<1>()), mEmailVerificationCode(tuple.get<2>()), mType(tuple.get<3>()), mCreated(tuple.get<4>()), mResendCount(tuple.get<5>()) + : ModelBase(tuple.get<0>()), + mUserId(tuple.get<1>()), mEmailVerificationCode(tuple.get<2>()), mType(tuple.get<3>()), + mCreated(tuple.get<4>()), mResendCount(tuple.get<5>()), mUpdated(tuple.get<6>()) { } @@ -45,6 +47,8 @@ namespace model { << " (user_id, verification_code, email_opt_in_type_id, resend_count) VALUES(?,?,?,?)" , use(mUserId), use(mEmailVerificationCode), bind(mType), bind(mResendCount); unlock(); + mUpdated = Poco::DateTime(); + mCreated = Poco::DateTime(); return insert; } @@ -53,9 +57,9 @@ namespace model { { Poco::Data::Statement select(session); - select << "SELECT id, user_id, verification_code, email_opt_in_type_id, created, resend_count FROM " << getTableName() + select << "SELECT id, user_id, verification_code, email_opt_in_type_id, created, resend_count, updated FROM " << getTableName() << " where " << fieldName << " = ?" - , into(mID), into(mUserId), into(mEmailVerificationCode), into(mType), into(mCreated), into(mResendCount); + , into(mID), into(mUserId), into(mEmailVerificationCode), into(mType), into(mCreated), into(mResendCount), into(mUpdated); return select; @@ -76,7 +80,7 @@ namespace model { { Poco::Data::Statement select(session); - select << "SELECT id, user_id, verification_code, email_opt_in_type_id, created, resend_count FROM " << getTableName() + select << "SELECT id, user_id, verification_code, email_opt_in_type_id, created, resend_count, updated FROM " << getTableName() << " where " << fieldName << " = ?"; @@ -90,7 +94,7 @@ namespace model { throw Poco::NullValueException("EmailOptIn::_loadFromDB fieldNames empty or contain only one field"); } - select << "SELECT id, user_id, verification_code, email_opt_in_type_id, created, resend_count FROM " << getTableName() + select << "SELECT id, user_id, verification_code, email_opt_in_type_id, created, resend_count, updated FROM " << getTableName() << " where " << fieldNames[0] << " = ? "; if (conditionType == MYSQL_CONDITION_AND) { for (int i = 1; i < fieldNames.size(); i++) { @@ -106,7 +110,7 @@ namespace model { addError(new ParamError("EmailOptIn::_loadFromDB", "condition type not implemented", conditionType)); } //<< " where " << fieldName << " = ?" - select , into(mID), into(mUserId), into(mEmailVerificationCode), into(mType), into(mCreated), into(mResendCount); + select , into(mID), into(mUserId), into(mEmailVerificationCode), into(mType), into(mCreated), into(mResendCount), into(mUpdated); return select; @@ -116,6 +120,7 @@ namespace model { { Poco::ScopedLock _lock(mWorkMutex); mResendCount++; + mUpdated = Poco::DateTime(); return updateIntoDB("resend_count", mResendCount); } diff --git a/src/cpp/model/table/EmailOptIn.h b/src/cpp/model/table/EmailOptIn.h index af08c20fe..6a12e3d91 100644 --- a/src/cpp/model/table/EmailOptIn.h +++ b/src/cpp/model/table/EmailOptIn.h @@ -17,7 +17,7 @@ namespace model { EMAIL_OPT_IN_REGISTER_DIRECT = 3 }; - typedef Poco::Tuple EmailOptInTuple; + typedef Poco::Tuple EmailOptInTuple; class EmailOptIn : public ModelBase { @@ -36,6 +36,7 @@ namespace model { inline int getUserId() const { return mUserId; } inline int getResendCount() const { Poco::ScopedLock _lock(mWorkMutex); return mResendCount; } inline Poco::DateTime getCreated() const { return mCreated; } + inline Poco::DateTime getUpdated() const { Poco::ScopedLock _lock(mWorkMutex); return mUpdated; } inline EmailOptInType getType() const { return static_cast(mType);} inline void setCode(Poco::UInt64 code) { mEmailVerificationCode = code; } inline void setUserId(int user_Id) { mUserId = user_Id; } @@ -56,6 +57,7 @@ namespace model { int mType; Poco::DateTime mCreated; int mResendCount; + Poco::DateTime mUpdated; };