function king_ajax_lostpwd1() { global $king; $username = kc_post('username'); //ask if ($user = $king->db->getRows_one("select userid,uid,userask,useranswer,usermail from %s_user where isdelete=0 and username='******'username')) . "'")) { if (!$user['userask']) { kc_error($king->lang->get('user/error/ask')); } } else { kc_error($king->lang->get('system/error/param')); } $s = $king->htmForm($king->lang->get('user/label/ask'), htmlspecialchars($user['userask'])); //answer $array = array(array('useranswer', 0, 1, 16), array('useranswer', 12, $king->lang->get('portal/check/lost/answer'), $user['useranswer'] != kc_post('useranswer'))); $s .= $king->htmForm($king->lang->get('user/label/answer'), '<input class="k_in w150" type="text" name="useranswer" id="useranswer" maxlength="16" value="' . htmlspecialchars(kc_post('useranswer')) . '" />', $array); //mail $_array = array(array('usermail', 0, 6, 32), array('usermail', 5, $king->lang->get('portal/check/reg/u-4')), array('usermail', 12, $king->lang->get('portal/check/lost/mail'), strtolower($user['usermail']) != strtolower(kc_post('usermail')))); $s .= $king->htmForm($king->lang->get('portal/user/mail'), '<input class="k_in w250" type="text" name="usermail" value="' . htmlspecialchars(kc_post('usermail')) . '" maxlength="32" />', $_array); //pass $_array = array(array('userpass', 0, 6, 30), array('userpass', 17, null, 'userpass1')); $s .= $king->htmForm($king->lang->get('portal/user/pass') . ' (6-30)', '<input class="k_in w150" type="password" name="userpass" id="userpass" maxlength="30" value="' . htmlspecialchars(kc_post('userpass')) . '" />', $_array); //repass $s .= $king->htmForm($king->lang->get('portal/user/pass1'), '<input class="k_in w150" type="password" name="userpass1" id="userpass1" maxlength="30" value="' . htmlspecialchars(kc_post('userpass1')) . '" />'); $verify = new KC_Verify_class(); $s .= $verify->Show(); if ($GLOBALS['ischeck']) { $array = array(); $salt = kc_random(6); $md5pass = md5($salt . kc_post('userpass')); $array['userpass'] = $md5pass; $array['ksalt'] = $salt; $userid = $king->db->update('%s_user', $array, "userid={$user['userid']}"); //写Cookie $s = $king->user->userLogin($user['userid'], 2592000); $king->user->delUserInfo($user['userid']); kc_ajax($king->lang->get('system/common/welcome'), $s . "<p class=\"k_ok\">" . $king->lang->get('portal/user/lostok') . "</p>", 0); } $but = kc_htm_a($king->lang->get('system/common/submit'), "{URL:'" . $king->config('inst') . "user/index.php',CMD:'lostpwd1',username:'******',IS:1}"); $height = $king->config('verifyopen') ? 250 + $king->config('verifyheight') : 230; kc_ajax($king->lang->get('portal/user/name'), $s, $but, '', 420, $height + $GLOBALS['check_num'] * 15); }
function king_def() { global $king; //die(uc_user_synlogin(2)); if ($GLOBALS['ismethod']) { //POST过程 $data = $_POST; } else { $data = array('re' => kc_val($_SERVER, 'HTTP_REFERER')); } $data = kc_data(array('re', 'username', 'userpass', 'expire')); if ($king->config('blackuser', 'user')) { $array_black = explode('|', $king->config('blackuser', 'user')); $array_black = array_diff($array_black, array(null)); } else { $array_black = array(); } $s = $king->openForm('login.php'); //username $_array = array(array('username', 0, 3, 15), array('username', 14, $king->lang->get('portal/check/reg/u-1'), array('*', '\\', ':', '?', '<', '>', '|', ';', ',', '\'', '!', '~', '$', '#', '@', '^', '(', ')', '{', '}', '=', '+', '%', '/')), array('username', 14, $king->lang->get('portal/check/reg/u-2'), $array_black)); $s .= $king->htmForm($king->lang->get('portal/user/name'), '<input class="k_in w150" type="text" name="username" value="' . htmlspecialchars($data['username']) . '" maxlength="15" />', $_array, null, "<tt><a href=\"javascript:; \" class=\"k_user_register\">" . $king->lang->get('portal/user/reg') . "</a></tt>"); //pass $_array = array(array('userpass', 0, 6, 30)); if ($data['userpass'] && $GLOBALS['ischeck']) { //有密码 并 账号验证成功的时候进行验证 $username = $data['username']; $is = False; if ($king->user->isuc) { //如果有UC if ($array_uc = uc_user_login($data['username'], $data['userpass'])) { //链接成功 if ((int) $array_uc[0] < 0) { //用户名不存在或密码错误 if ($res = $king->db->getRows_one("select usermail,userpass,ksalt,userid from %s_user where username='******' and uid=0")) { //判断本地是否存在这个用户并且未同步到uc $userid = $res['userid']; if (md5($res['ksalt'] . $data['userpass']) == $res['userpass']) { //检测密码 $uid = uc_user_register($username, $data['userpass'], $res['usermail']); //注册用户到uc $king->db->update('%s_user', array('lastlogindate' => time(), 'uid' => $uid > 0 ? $uid : 0), 'username=\'' . $king->db->escape($username . '\'')); uc_user_login($data['username'], $data['userpass']); } else { $is = True; $errId = -2; } } else { $is = True; $errId = $array_uc[0]; } } else { //登录成功的时候,检查一下本地是否有这个账号 $uid = $array_uc[0]; //UC中的UID if ($res = $king->db->getRows_one("select userpass,ksalt,userid from %s_user where username='******'")) { //如果有这么个账号 $userid = $res['userid']; if (md5($res['ksalt'] . $data['userpass']) != $res['userpass']) { //若不一致,则进行更新 $userpass = md5($res['ksalt'] . $data['userpass']); $king->db->update('%s_user', array('userpass' => $userpass, 'lastlogindate' => time()), 'username=\'' . $king->db->escape($username . '\'')); } else { $king->db->update('%s_user', array('lastlogindate' => time()), 'username=\'' . $king->db->escape($username . '\'')); } } else { //如果本地没有这个账号,则添加 $usermail = $array_uc[3]; $ksalt = kc_random(6); $array = array('username' => $username, 'userpass' => md5($ksalt . $data['userpass']), 'usermail' => $usermail, 'ksalt' => $ksalt, 'uid' => $uid, 'regdate' => time(), 'lastlogindate' => time()); $king->db->insert('%s_user', $array); $res = $king->db->getRows_one("select userid from %s_user where uid='" . $uid . "' and isdelete=0"); $userid = $res['userid']; } } } else { kc_error($king->lang->get('portal/error/connect')); //连接错误 } } else { //如果没有UC if ($res = $king->db->getRows_one("select userpass,ksalt,userid from %s_user where username='******' and isdelete=0")) { //如果有这么个账号 $md5pass = md5($res['ksalt'] . $data['userpass']); // kc_error($md5pass."\t".$res['userpass']); if ($md5pass != $res['userpass']) { //若不一致,提示错误 $is = True; $errId = -2; } else { //验证通过 $userid = $res['userid']; $king->db->update('%s_user', array('lastlogindate' => time()), 'userid=' . $userid); // $userpass=md5($res['ksalt'].$data['userpass']); } } else { $is = True; $errId = -1; } } if (!empty($errId)) { $_array[] = array('userpass', 12, $king->lang->get('portal/check/pwd/p' . $errId), $is); } } $s .= $king->htmForm($king->lang->get('portal/user/pass') . '', '<input class="k_in w150" type="password" name="userpass" maxlength="30" />', $_array, null, "<tt><a href=\"javascript:;\" class=\"k_user_lostpwd\">" . $king->lang->get('portal/user/lostpwd') . "</a></tt>"); //expire $array_select = array(0 => $king->lang->get('system/time/cookie'), 86400 => $king->lang->get('system/time/oneday'), 2592000 => $king->lang->get('system/time/jan'), 15768000 => $king->lang->get('system/time/halfyear'), 31536000 => $king->lang->get('system/time/ayear'), 315360000 => $king->lang->get('system/time/forever')); $s .= $king->htmForm($king->lang->get('portal/user/expire'), kc_htm_radio('expire', $array_select, 2592000)); //verify $verify = new KC_Verify_class(); $s .= $verify->Show(); $s .= kc_htm_hidden(array('re' => $data['re'])); $s .= $king->closeForm($king->lang->get('system/common/login')); if ($GLOBALS['ischeck']) { //写Cookie $s = $king->user->userLogin($userid, $data['expire']); $array = array('<a href="/">' . $king->lang->get('portal/user/return/home') . '</a>', '<a href="index.php">' . $king->lang->get('portal/user/return/uc') . '</a>'); if ($data['re']) { $array[] = '<a href="' . $data['re'] . '">' . $king->lang->get('portal/user/return/re') . ' : ' . $data['re'] . '</a>'; $goto = $data['re']; } else { $goto = $king->config('inst') . 'user/index.php'; } $s .= kc_htm_ol($king->lang->get('portal/user/loginok'), $array, $goto); } $tmp = new KC_Template_class($king->config('templateuser', 'user'), $king->config('templatepath') . '/inside/user/login.htm'); $tmp->assign('main', $s); $tmp->assign('title', $king->lang->get('portal/title/login')); echo $tmp->output(); }