Working setUser for postgres

This commit is contained in:
HanzZ 2011-12-22 20:47:36 +01:00
parent 630bee4b67
commit 12d117f54f
2 changed files with 19 additions and 6 deletions

View file

@ -97,6 +97,7 @@ class PQXXBackend : public StorageBackend
private:
bool exec(const std::string &query, bool show_error = true);
bool exec(pqxx::work &txn, const std::string &query, bool show_error = true);
Config *m_config;
std::string m_prefix;

View file

@ -126,6 +126,10 @@ bool PQXXBackend::createDatabase() {
bool PQXXBackend::exec(const std::string &query, bool show_error) {
pqxx::work txn(*m_conn);
return exec(txn, query, show_error);
}
bool PQXXBackend::exec(pqxx::work &txn, const std::string &query, bool show_error) {
try {
txn.exec(query);
txn.commit();
@ -139,12 +143,20 @@ bool PQXXBackend::exec(const std::string &query, bool show_error) {
}
void PQXXBackend::setUser(const UserInfo &user) {
// std::string encrypted = user.password;
// if (!CONFIG_STRING(m_config, "database.encryption_key").empty()) {
// encrypted = Util::encryptPassword(encrypted, CONFIG_STRING(m_config, "database.encryption_key"));
// }
// *m_setUser << user.jid << user.uin << encrypted << user.language << user.encoding << user.vip << user.uin << encrypted;
// EXEC(m_setUser, setUser(user));
std::string encrypted = user.password;
if (!CONFIG_STRING(m_config, "database.encryption_key").empty()) {
encrypted = Util::encryptPassword(encrypted, CONFIG_STRING(m_config, "database.encryption_key"));
}
pqxx::work txn(*m_conn);
exec(txn, "UPDATE " + m_prefix + "users SET uin=" + txn.quote(user.uin) + ", password=" + txn.quote(encrypted) + ";"
"INSERT INTO " + m_prefix + "users (jid, uin, password, language, encoding, last_login, vip) VALUES "
"(" + txn.quote(user.jid) + ","
+ txn.quote(user.uin) + ","
+ txn.quote(encrypted) + ","
+ txn.quote(user.language) + ","
+ txn.quote(user.encoding) + ","
+ "NOW(),"
+ txn.quote(user.vip) +")");
}
bool PQXXBackend::getUser(const std::string &barejid, UserInfo &user) {