data_table = Option::get('data_table_name'); $this->column_uname = Option::get('data_column_uname'); $this->column_passwd = Option::get('data_column_passwd'); $this->column_ip = Option::get('data_column_ip'); } public function sync($username, $reverse = false) { $exist_in_bs_table = $this->has('username', $username); $exist_in_data_table = $this->has($this->column_uname, $username, $this->data_table); if ($exist_in_bs_table && !$exist_in_data_table) { $result = $this->select('username', $username); $user_data = array( $this->column_uname => $username, $this->column_passwd => $result['password'], $this->column_ip => $result['ip'] ); // 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); } if (!$exist_in_bs_table && $exist_in_data_table) { $result = $this->select($this->column_uname, $username, null, $this->data_table); $this->insert(array( "username" => $username, "password" => $result[$this->column_passwd], "ip" => $result[$this->column_ip] )); // recursion return $this->sync($username); } if (!($exist_in_bs_table || $exist_in_data_table)) // user not exists return false; if ($exist_in_bs_table && $exist_in_data_table) { $passwd1 = $this->select('username', $username)['password']; $passwd2 = $this->select($this->column_uname, $username, null, $this->data_table)[$this->column_passwd]; if ($passwd1 == $passwd2) { return true; } else { // sync password if ($reverse) { $this->update($this->column_passwd, $passwd1, ['where' => "$this->column_uname='$username'"], $this->data_table); } else { $this->update('password', $passwd2, ['where' => "username='$username'"]); } return $this->sync($username); } } } }