我想知道如何在用户登录时更改在线用户状态。我一直在寻找这个,但我的问题没有答案。我是新学习这个代码的人,所以,我希望你们能为我的问题提供帮助。
控制器:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({width: 1440, height: 2000});
await page.goto(`https://www.southwest.com/air/check-in/review.html?confirmationNumber=${process.argv[2]}&passengerFirstName=${process.argv[3]}&passengerLastName=${process.argv[4]}`, {
waitUntil: 'networkidle2'
});
[ confirmationNumber, checkinButtonText ] = [ await page.$eval('.confirmation-number--code', el => el.innerHTML), await page.$eval('.actionable_primary.actionable_large-button', el => el.innerHTML) ]
console.log(checkinButtonText);
console.log(confirmationNumber);
await page.click('.actionable_primary.actionable_large-button');
// The below line makes a click on the button
await page.click('.air-check-in-boarding-pass-options .boarding-pass-options--button-email, .air-check-in-boarding-pass-options .boarding-pass-options--button-print, .air-check-in-boarding-pass-options .boarding-pass-options--button-text');
await browser.close();
})();
型号:
public function signdevice() {
$device = $this->input->post('device');
$pass = $this->input->post('password');
$data = array(
'device' => $device,
'password' => $pass,
'status' => $status
);
$status = 1;
$res = $this->db->get_where('devices', $data);
if ($res->num_rows() > 0) {
$this->session->set_userdata(
array(
'signin' => TRUE,
'device' => $device,
'status' => $status
)
);
$data = array('device' => $device, 'password' => $pass, 'status' => 1);
$this->db->where('device', '$device');
$this->db->update('devices', $data);
redirect(base_url('pelanggan'));
} else {
$this->session->set_flashdata('result_login', 'Wrong Username or Password.');
redirect(base_url());
}
}
答案 0 :(得分:2)
你有几行失踪&错误的代码。
控制器:
public function signdevice() {
$device = $this->input->post('device');
$pass = $this->input->post('password');
$data = array(
'device' => $device,
'password' => $pass,
'status' => 0 // changed value to 0
);
$status = 1;
$res = $this->db->get_where('devices', $data);
if ($res->num_rows() > 0) {
$this->session->set_userdata(
array(
'signin' => TRUE,
'device' => $device,
'status' => $status
)
);
$data = array('device' => $device, 'password' => $pass, 'status' => 1);
$this->db->where('device', $device); // removed quotes
$this->db->update('devices', $data);
redirect(base_url('pelanggan'));
} else {
$this->session->set_flashdata('result_login', 'Wrong Username or Password.');
redirect(base_url());
}
}
型号:
...
function update($id,$stat)
{
$stat = 1; // swapped this line with below
$data['status'] = $stat; // swapped this line with above
$this->db->where('kd_device', $id);
$this->db->update('devices', $data); // maybe what you want to save is $data?
return TRUE;
}