10 #include <QLoggingCategory>
11 #include <QTemporaryFile>
15 Q_LOGGING_CATEGORY(C_AUTH_HTPASSWD,
"cutelyst.plugin.authentication.htpasswd", QtWarningMsg)
28 const QString username = user.
value(QStringLiteral(
"username"));
33 qCWarning(C_AUTH_HTPASSWD) <<
"Failed to open temporary file for writing";
38 QFile file(m_filename);
40 while (!file.
atEnd()) {
45 user.
value(QStringLiteral(
"password")).toLatin1().replace(
':',
',') +
'\n';
55 user.
value(QStringLiteral(
"password")).toLatin1().replace(
':',
',') +
61 qCWarning(C_AUTH_HTPASSWD) <<
"Failed to remove auth file for replacement";
65 if (!tmp.
rename(m_filename)) {
66 qCWarning(C_AUTH_HTPASSWD) <<
"Failed to rename temporary file";
74 const QString username = userInfo.
value(QStringLiteral(
"username"));
76 QFile file(m_filename);
78 while (!file.
atEnd()) {
81 if (parts.
size() >= 2 && !parts.
first().startsWith(
'#') &&
83 ret.
insert(QStringLiteral(
"username"), username);
86 ret.
insert(QStringLiteral(
"password"),
Container for user data retrieved from an AuthenticationStore.
void setId(const QVariant &id)
void insert(const QString &key, const QVariant &value)
Authentication data store using a flat file.
virtual ~StoreHtpasswd() override
QVariant forSession(Context *c, const AuthenticationUser &user) override final
AuthenticationUser findUser(Context *c, const ParamsMultiMap &userInfo) override final
AuthenticationUser fromSession(Context *c, const QVariant &frozenUser) override final
void addUser(const ParamsMultiMap &user)
The Cutelyst namespace holds all public Cutelyst API.
QByteArray & replace(QByteArrayView before, QByteArrayView after)
QList< QByteArray > split(char sep) const const
QByteArray trimmed() const const
bool exists(const QString &fileName)
bool open(FILE *fh, QIODeviceBase::OpenMode mode, QFileDevice::FileHandleFlags handleFlags)
virtual bool atEnd() const const override
virtual void close() override
QByteArray readLine(qint64 maxSize)
qint64 write(const QByteArray &data)
QList::const_reference at(qsizetype i) const const
qsizetype size() const const
T value(const Key &key, const T &defaultValue) const const
QString fromLatin1(QByteArrayView str)
QByteArray toLatin1() const const
bool rename(const QString &newName)
void setAutoRemove(bool b)
QString toString() const const