Exemplo n.º 1
0
use Model\User;
use Util\Token;
use Form\Response;
if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
    $userPostData = isset($_POST['user']) && is_array($_POST['user']) ? $_POST['user'] : array();
    $userPostData = array_map('trim', $userPostData);
    $username = isset($userPostData['name']) ? $userPostData['name'] : '';
    $password = isset($userPostData['pass']) ? $userPostData['pass'] : '';
    //进行表单令牌验证
    if (Token::validate($_POST['token']) === false) {
        Response::json(array('msg' => '非法访问,请刷新表单'), 1);
    }
    if (User::isUsername($username) == false) {
        Response::json(array('msg' => '账号不符合规则,请重新输入'), 1);
    }
    if (User::isPassword($password) == false) {
        Response::json(array('msg' => '密码不符合规则,请重新输入'), 1);
    }
    $userData = User::getUserDataByUsername('user_id,user_pass', $username);
    if (isset($userData['user_id']) == false) {
        Response::json(array('msg' => '您输入的帐号不存在,请重新输入'), 1);
    }
    if (md5($password) != $userData['user_pass']) {
        Response::json(array('msg' => '您输入的密码有误,请重新输入'), 1);
    }
    $_SESSION['user_id'] = $userData['user_id'];
    $_SESSION['user_name'] = $username;
    Response::json(array('msg' => '系统登录成功'), 0);
}
?>
<!DOCTYPE html>
Exemplo n.º 2
0
$eid = isset($_GET['eid']) ? intval($_GET['eid']) : '';
$act = isset($_GET['act']) ? $_GET['act'] : '';
if ($act == 'save') {
    $userData = isset($_POST['user']) && is_array($_POST['user']) ? $_POST['user'] : array();
    $data = array('user_name' => isset($userData['name']) ? $userData['name'] : '', 'user_pass' => isset($userData['pass']) && $userData['pass'] != '' ? md5($userData['pass']) : '', 'user_real_name' => isset($userData['real_name']) ? $userData['real_name'] : '', 'user_sex' => isset($userData['sex']) && $userData['sex'] != '' ? $userData['sex'] : 1, 'user_age' => isset($userData['age']) && $userData['age'] != '' ? $userData['age'] : 0, 'user_email' => isset($userData['email']) ? $userData['email'] : '', 'user_qq' => isset($userData['qq']) && $userData['qq'] != '' ? $userData['qq'] : 0, 'user_phone' => isset($userData['phone']) && $userData['phone'] != '' ? $userData['phone'] : 0, 'user_mobile' => isset($userData['mobile']) && $userData['mobile'] != '' ? $userData['mobile'] : 0);
    //去除数据两侧空字符
    $data = array_map('trim', $data);
    if (User::isUsername($data['user_name']) == false) {
        Response::json(array('msg' => '用户名不符合规则,请重新输入'), 1);
    }
    if ($eid > 0) {
        if ($data['user_pass'] != '' && User::isPassword($data['user_pass']) == false) {
            Response::json(array('msg' => '密码不符合规则,请重新输入'), 1);
        }
    } else {
        if (User::isPassword($data['user_pass']) == false) {
            Response::json(array('msg' => '密码不符合规则,请重新输入'), 1);
        }
    }
    //真实姓名
    if ($data['user_real_name'] != '' && User::isRealName($data['user_real_name']) == false) {
        Response::json(array('msg' => '输入的名字不符合规则,请重新输入'), 1);
    }
    //性别
    if ($data['user_sex'] != '' && User::isSex($data['user_sex']) == false) {
        Response::json(array('msg' => '输入的性别不符合规则,请重新输入'), 1);
    }
    //年龄
    if ($data['user_age'] != 0 && User::isAge($data['user_age']) == false) {
        Response::json(array('msg' => '输入的年龄不符合规则,请重新输入'), 1);
    }