public function act() { if (!$this->check_param('username, password, issave')) { LF\V('Json.Base')->init(Const_Code::LOGIN_PARAM_ERROR, '登录传递参数错误'); return; } $username = trim(Request::get_param('username', 'post')); $password = trim(Request::get_param('password', 'post')); $is_save = (int) Request::get_param('issave', 'post'); $time = time(); $seckey = LF\lb_read_system('seckey'); $user_id = (int) LF\M('User')->check_password($username, md5($username . $password)); if (!$user_id) { LF\V('Json.Base')->init(Const_Code::LOGIN_FAIL, '帐号验证失败'); return; } $user = LF\M('User')->get_by_id($user_id); $expire_time = $is_save ? 86400 * 30 : 0; Cookie::set_cookie('userid', $user_id, $expire_time); Cookie::set_cookie('username', $user['name'], $expire_time); Cookie::set_cookie('userrole', $user['role'], $expire_time); Cookie::set_cookie('time', $time, $expire_time); Cookie::set_cookie('secstr', md5($user_id . '$' . $user['name'] . '$' . $user['role'] . '$' . $time . '$' . $seckey), $expire_time); LF\V('Json.Base')->init(Const_Code::SUCCESS, '帐号验证通过'); }
protected function unset_cookie() { Util_Client_Cookie::unset_cookie('userid'); Util_Client_Cookie::unset_cookie('username'); Util_Client_Cookie::unset_cookie('time'); Util_Client_Cookie::unset_cookie('secstr'); }
public function get_cookie($file = '') { $saved_file = Request::get_cookie('cookiefile'); if ($saved_file) { $file = $saved_file; } else { $file = $file ? $file : 'local-' . microtime(); Cookie::set_cookie('cookiefile', $file, time() + 90 * 24 * 3600); } return APP_PATH . '/tmp/cookie/' . $file; }
public function act() { $space_id = (int) Request::get_param('spaceid', 'post'); Cookie::set_cookie('current_space', $space_id, 60 * 60 * 24 * 30); }
public function act() { Cookie::unset_cookie('userid'); Response::set_header_location('/index.php/login'); exit; }