Software / code / prosody-modules
Comparison
mod_auth_wordpress/mod_auth_wordpress.lua @ 426:6f2e37d0a1b0
mod_auth_wordpress: Allow table prefix to be configured
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 11 Sep 2011 22:53:23 +0200 |
| parent | 425:34eb9df9e37f |
| child | 427:35b3ea156156 |
comparison
equal
deleted
inserted
replaced
| 425:34eb9df9e37f | 426:6f2e37d0a1b0 |
|---|---|
| 11 local md5 = require "util.hashes".md5; | 11 local md5 = require "util.hashes".md5; |
| 12 local uuid_gen = require "util.uuid".generate; | 12 local uuid_gen = require "util.uuid".generate; |
| 13 | 13 |
| 14 local connection; | 14 local connection; |
| 15 local params = module:get_option("sql"); | 15 local params = module:get_option("sql"); |
| 16 local table_prefix = module:get_option_string("wordpress_table_prefix", "wp_"); | |
| 16 | 17 |
| 17 local resolve_relative_path = require "core.configmanager".resolve_relative_path; | 18 local resolve_relative_path = require "core.configmanager".resolve_relative_path; |
| 18 | 19 |
| 19 local function test_connection() | 20 local function test_connection() |
| 20 if not connection then return nil; end | 21 if not connection then return nil; end |
| 78 if not stmt then return stmt, err; end | 79 if not stmt then return stmt, err; end |
| 79 return stmt:affected(); | 80 return stmt:affected(); |
| 80 end | 81 end |
| 81 | 82 |
| 82 local function get_password(username) | 83 local function get_password(username) |
| 83 local stmt, err = getsql("SELECT `user_pass` FROM `wp_users` WHERE `user_login`=?", username); | 84 local stmt, err = getsql("SELECT `user_pass` FROM `"..table_prefix.."users` WHERE `user_login`=?", username); |
| 84 if stmt then | 85 if stmt then |
| 85 for row in stmt:rows(true) do | 86 for row in stmt:rows(true) do |
| 86 return row.user_password; | 87 return row.user_password; |
| 87 end | 88 end |
| 88 end | 89 end |
| 188 function provider.get_password(username) | 189 function provider.get_password(username) |
| 189 return nil, "Getting password is not supported."; | 190 return nil, "Getting password is not supported."; |
| 190 end | 191 end |
| 191 function provider.set_password(username, password) | 192 function provider.set_password(username, password) |
| 192 local hash = wordpressCreateHash(password); | 193 local hash = wordpressCreateHash(password); |
| 193 local stmt, err = setsql("UPDATE `wp_users` SET `user_pass`=? WHERE `user_login`=?", hash, username); | 194 local stmt, err = setsql("UPDATE `"..table_prefix.."users` SET `user_pass`=? WHERE `user_login`=?", hash, username); |
| 194 return stmt and true, err; | 195 return stmt and true, err; |
| 195 end | 196 end |
| 196 function provider.create_user(username, password) | 197 function provider.create_user(username, password) |
| 197 return nil, "Account creation/modification not supported."; | 198 return nil, "Account creation/modification not supported."; |
| 198 end | 199 end |