fix empty realname column of Authme

This commit is contained in:
printempw 2016-06-12 10:45:32 +08:00
parent 99b514e318
commit dedabf1fac
2 changed files with 23 additions and 4 deletions

View File

@ -3,7 +3,7 @@
* @Author: printempw
* @Date: 2016-03-18 16:53:55
* @Last Modified by: printempw
* @Last Modified time: 2016-04-03 15:36:35
* @Last Modified time: 2016-06-12 10:44:56
*/
namespace Database;
@ -35,11 +35,19 @@ class AdaptedDatabase extends Database implements PasswordInterface, SyncInterfa
if ($exist_in_bs_table && !$exist_in_data_table) {
$result = $this->select('username', $username);
$this->insert(array(
$user_data = array(
$this->column_uname => $username,
$this->column_passwd => $result['password'],
$this->column_ip => $result['ip']
), $this->data_table);
);
// quick fix for Authme realname
if (Option::get('data_adapter') == "Authme") {
if ($this->checkColumnExist('realname', $this->data_table))
$user_data['realname'] = $username;
}
$this->insert($user_data, $this->data_table);
// recursion
return $this->sync($username);

View File

@ -3,7 +3,7 @@
* @Author: printempw
* @Date: 2016-02-02 21:59:06
* @Last Modified by: printempw
* @Last Modified time: 2016-04-11 17:09:09
* @Last Modified time: 2016-06-12 10:43:47
*/
namespace Database;
@ -111,6 +111,17 @@ class Database implements PasswordInterface, SyncInterface
return $this->query("DELETE FROM $table".$this->where($condition));
}
public function checkTableExist($table_name) {
$sql = "SELECT table_name FROM `INFORMATION_SCHEMA`.`TABLES` WHERE (table_name ='$table_name') AND TABLE_SCHEMA='".DB_NAME."'";
return ($this->query($sql)->num_rows == 0) ? false : true;
}
public function checkColumnExist($column_name, $table = null) {
$table = is_null($table) ? $this->table_name : $table;
$sql = "SELECT * FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE TABLE_SCHEMA = '".DB_NAME."' AND TABLE_NAME = '$table' AND COLUMN_NAME = '$column_name'";
return ($this->query($sql)->num_rows == 0) ? false : true;
}
public function getNumRows($key, $value, $table = null) {
$table = is_null($table) ? $this->table_name : $table;
$sql = "SELECT * FROM $table WHERE $key='$value'";