function admin_login() { safe('admin_login'); global $smarty, $lang; $username = substr(post('username'), 0, 30); $password = substr(post('password'), 0, 30); if ($username == '' || $password == '') { unset_session('admin_username'); unset_session('admin_password'); $info_text = '对不起,用户名和密码不能为空'; $link_text = '返回重新登录'; } else { $password = md5($password); $obj = new admin(); $obj->set_field('adm_id,adm_last_login'); $obj->set_where("adm_username = '******'"); $obj->set_where("adm_password = '******'"); $one = $obj->get_one(); if (count($one) !== 0) { set_session('session_id', session_id()); set_session('admin_username', $username); set_session('admin_password', $password); $adm_id = $one['adm_id']; $adm_prev_login = $one['adm_last_login']; $adm_last_login = time(); $obj->set_value('adm_prev_login', $adm_prev_login); $obj->set_value('adm_last_login', $adm_last_login); $obj->set_where(''); $obj->set_where("adm_id = {$adm_id}"); $obj->edit(); $info_text = '欢迎使用新秀文章管理系统后台'; $link_text = '进入后台'; } else { unset_session('session_id'); unset_session('admin_username'); unset_session('admin_password'); $info_text = '对不起,用户名不存在或密码不正确'; $link_text = '返回重新登录'; } } $smarty->assign('info_text', $info_text); $smarty->assign('link_text', $link_text); $smarty->assign('link_href', $_SERVER['PHP_SELF']); }
function edit_admin() { global $global, $smarty; $adm_id = post('adm_id'); $adm_password = post('adm_password'); $re_password = post('re_password'); $obj = new admin(); $obj->set_where('adm_id = ' . $global['admin_id']); $a = $obj->get_one(); $obj->set_where(''); $obj->set_where("adm_id = {$adm_id}"); $b = $obj->get_one(); $success = 0; if ($obj->get_count()) { if ($a['adm_id'] == $b['adm_id'] || $a['adm_grade'] < $b['adm_grade']) { if (strlen($adm_password) >= 5 && $adm_password == $re_password) { $obj->set_value('adm_password', md5($adm_password)); $obj->edit(); $success = 1; } } } if ($success) { $info_text = '修改密码成功'; $link_text = '返回列表页'; $link_href = url(array('channel' => 'basic', 'mod' => 'admin_list')); } else { $info_text = '修改密码失败'; $link_text = '返回上一页'; $link_href = url(array('channel' => 'basic', 'mod' => 'admin_edit')); } $smarty->assign('info_text', $info_text); $smarty->assign('link_text', $link_text); $smarty->assign('link_href', $link_href); }