Exemple #1
0
 function ForgotPassword($row)
 {
     Module::Module($row);
     $user_id = (int) Url::get('id');
     if ($user_id) {
         $user = DB::fetch("SELECT user_name,email FROM user WHERE id={$user_id}");
         if ($user && md5($user['user_name'] . $user['email']) == Url::get('u')) {
             $new_password = $this->random_string();
             $user_name = $user['user_name'];
             $subject = 'Khôi phục mật khẩu thành công!';
             $messenger = file_get_contents('templates/ForgotPassword/reset_password.html');
             $message = str_replace('[[|user_name|]]', $user_name, $messenger);
             $message = str_replace('[[|password|]]', $new_password, $message);
             if (System::sendEBEmail($user['email'], $subject, $message)) {
                 DB::update('user', array('password' => User::encode_password($new_password)), "id={$user_id}");
                 Url::redirect_current(array('action' => 'reset_success'));
             } else {
                 Url::redirect_current(array('action' => 'reset_error'));
             }
         } else {
             Url::redirect('home');
         }
     }
     require_once 'forms/forgot_password.php';
     $this->add_form(new ForgotPasswordForm());
 }
Exemple #2
0
 function on_submit()
 {
     $user_update = array();
     $full_name = Url::get('full_name');
     $user_name = Url::get('register_user_name');
     $mobile_phone = AZLib::trimSpace(Url::get('mobile_phone'));
     $home_phone = AZLib::trimSpace(Url::get('home_phone'));
     $gender = (int) Url::get('gender');
     $yahoo_id = AZLib::trimSpace(Url::get('yahoo_id'));
     $skype_id = AZLib::trimSpace(Url::get('skype_id'));
     $address = AZLib::trimSpace(Url::get('address'));
     $website = AZLib::trimSpace(Url::get('website'));
     $this->checkFormInput('Tên đầy đủ', 'full_name', $full_name, 'str', false, '', 0, 50);
     $this->checkFormInput('Điện thoại di động', 'mobile_phone', $mobile_phone, 'str', false, '', 0, 50);
     $this->checkFormInput('Điện thoại bàn', 'home_phone', $home_phone, 'str', false, '', 0, 50);
     $change_pass = 0;
     $change_mail = 0;
     if (User::is_root() && (User::id() == 1 || $this->user['id'] != 1)) {
         $email = Url::get('email');
         $password = AZLib::trimSpace(Url::get('register_password'));
         $confirm_password = AZLib::trimSpace(Url::get('confirm_password'));
         if ($password && User::encode_password($password) != $this->user['password']) {
             //Có nhập pass mới khác pass cũ
             $this->checkFormInput('Mật khẩu truy cập', 'register_password', $password, 'str', true, '', 6, 50);
             $change_pass = 1;
             if ($password != $confirm_password) {
                 $this->setFormError('confirm_password', "Nhập lại Mật khẩu truy cập không khớp!");
             }
         }
         if ($email && $email != $this->user['email']) {
             //Có nhập email mới khác email cũ
             $this->checkFormInput('Email', 'email', $email, 'email', true, '', 6, 50);
             $change_mail = 1;
         }
     }
     if ($mobile_phone && !AZLib::is_mobile($mobile_phone)) {
         $mobile_phone = "";
     }
     if (!$this->errNum) {
         if ($change_mail && DB::exists('SELECT id FROM `user` WHERE `email`="' . $email . '" AND id!=' . $this->user['id'])) {
             $this->setFormError('email', "<b>Email</b> bạn chọn đã tồn tại, hãy chọn lại một <b>Email</b> khác!");
         } else {
             $user_info = array('full_name' => $full_name, 'mobile_phone' => $mobile_phone, 'home_phone' => $home_phone, 'gender' => $gender == 1 ? 0 : 1, 'yahoo_id' => $yahoo_id, 'skype_id' => $skype_id, 'address' => $address, 'website' => $website);
             if ($change_pass) {
                 $user_info['password'] = User::encode_password($password);
             }
             if ($change_mail) {
                 $user_info['email'] = $email;
             }
             DB::update('user', $user_info, "id=" . $this->user['id']);
             User::getUser($this->user['id'], 0, 1);
             Url::redirect_current();
         }
     }
 }
Exemple #3
0
 static function register_by_name($name, $password)
 {
     $black_kws = array('admin', 'system', 'root', 'test');
     foreach ($black_kws as $kw) {
         if (stripos($name, $kw) !== false) {
             throw new Exception("用户名包含非法词");
         }
     }
     self::validate_name($name);
     self::validate_password($password);
     $m = User::getBy('name', $name);
     if ($m) {
         throw new Exception('用户名已被占用');
     }
     $salt = User::gen_salt();
     $password = User::encode_password($password, $salt);
     $row = array('name' => $name, 'status' => User::STATUS_OK, 'password' => $password, 'salt' => $salt, 'reg_time' => date('Y-m-d H:i:s'), 'reg_ip' => ip());
     $m = User::save($row);
     return $m;
 }
Exemple #4
0
 static function update_password($password)
 {
     return DB::update('user', array('password' => User::encode_password($password)), 'id=' . User::$current->data['id']);
 }
Exemple #5
0
 function check_password()
 {
     if (isset($_REQUEST['old_password']) && User::is_login()) {
         $password = $_REQUEST['old_password'];
         $sql = "select id from user where password = '******' and id='" . User::$current->data['id'] . "'";
         DB::query($sql);
         if (DB::num_rows()) {
             $resp = 'true';
         } else {
             $resp = 'false';
         }
         echo $resp;
         exit;
     } else {
         echo "no_login";
         exit;
     }
 }
 function change_password()
 {
     $json = "";
     if (!User::is_login()) {
         $json = '({"msg":"no_login"})';
         echo $json;
         exit;
     }
     $old_password = Url::get("old_password", "");
     $new_password = Url::get("new_password", "");
     $retype_new_password = Url::get("retype_new_password", "");
     if ($new_password == $retype_new_password) {
         if (DB::update('user', array('password' => User::encode_password($new_password)), 'id=' . User::id())) {
             $json = '({"msg":"success"';
             $json .= ',"note":"Thay đổi mật khẩu thành công"';
             $json .= '})';
             echo $json;
             exit;
         } else {
             $json = '({"msg":"unsuccess"';
             $json .= ',"note":"Có lỗi xẩy ra. Không thay đổi được mật khẩu"';
             $json .= '})';
             echo $json;
             exit;
         }
     } else {
         $json = '({"msg":"unsuccess"';
         $json .= ',"note":"Xác nhận mật khẩu không đúng"';
         $json .= '})';
         echo $json;
         exit;
     }
 }
Exemple #7
0
 function on_submit()
 {
     if (User::checkLock4Ever(1)) {
         Url::redirect_current();
     }
     //check bảo mật
     $just_registed_s = 0;
     $just_registed_c = 0;
     if (isset($_SESSION['just_registed'])) {
         $just_registed_s = $_SESSION['just_registed'];
     }
     if (isset($_COOKIE['just_registed'])) {
         $just_registed_c = $_COOKIE['just_registed'];
     }
     if ($just_registed_s > TIME_NOW - 120 || $just_registed_c > TIME_NOW - 120 || !REG_ON) {
         Url::redirect_current();
     }
     //END check bảo mật
     // check de ban IP
     $ip = AZLib::ip();
     $arr_badwords = AZLib::checkBadWord($ip, true);
     if ($arr_badwords["bad"] != "" && $arr_badwords["bad_key"] != "") {
         $this->setFormError('ban_ip', "Có lỗi xẩy ra");
     }
     // end check de ban IP
     $full_name = Url::get('full_name');
     $email = Url::get('email');
     $user_name = Url::get('register_user_name');
     $mobile_phone = AZLib::trimSpace(Url::get('mobile_phone'));
     $password = AZLib::trimSpace(Url::get('register_password'));
     $confirm_password = AZLib::trimSpace(Url::get('confirm_password'));
     $this->checkFormInput('Tên đầy đủ', 'full_name', $full_name, 'str', false, '', 0, 50);
     $this->checkFormInput('Email', 'email', $email, 'email', true, '', 6, 50);
     $this->checkFormInput('Tên truy cập', 'user_name', $user_name, 'uname', true, '', 4, 50);
     $this->checkFormInput('Điện thoại di động', 'mobile_phone', $mobile_phone, 'str', false, '', 0, 50);
     $this->checkFormInput('Mật khẩu truy cập', 'register_password', $password, 'str', true, '', 6, 50);
     $this->checkFormInput('Nhập lại mật khẩu', 'confirm_password', $confirm_password, 'str', true, '', 6, 50);
     if (!$this->errNum) {
         if ($password != $confirm_password) {
             $this->setFormError('captcha_register', "Nhập lại Mật khẩu truy cập không khớp!");
             return;
         }
     }
     $captcha_register = Url::get('captcha_register');
     if ($mobile_phone && !AZLib::is_mobile($mobile_phone)) {
         $mobile_phone = "";
     }
     if ($captcha_register == '') {
         $this->setFormError('captcha_register', "Bạn chưa nhập <b>Mã bảo mật</b>!");
     } else {
         if (!isset($_SESSION["enbac_validate"]) || $captcha_register != $_SESSION["enbac_validate"]) {
             $this->setFormError('captcha_register', "<b>Mã bảo mật</b> không chính xác!");
         }
     }
     if ((int) Url::get('confirm_register') != 1) {
         $this->setFormError('confirm_register', "Bạn phải đọc và đồng ý với những <a target=\"_blank\" href=\"http://help.enbac.com/content/4/5/en/Quy-che-thanh-vien.html\" >điều khoản của Enbac.com</a>!");
     }
     if (!$this->errNum) {
         if (DB::exists('SELECT id FROM `user` WHERE `email`="' . $email . '"')) {
             $this->setFormError('email', "<b>Email</b> bạn chọn đã tồn tại, hãy chọn lại một <b>Email</b> khác!");
         } elseif (DB::exists('SELECT id FROM `user` WHERE `user_name`="' . $user_name . '"')) {
             $this->setFormError('email', "<b>Tên truy cập</b> bạn chọn đã tồn tại, hãy chọn lại một <b>Tên truy cập</b> khác!");
         } else {
             $user_info = array('user_name' => $user_name, 'email' => $email, 'password' => User::encode_password($password), 'full_name' => $full_name, 'mobile_phone' => $mobile_phone, 'create_time' => TIME_NOW, 'is_active' => (int) (bool) USER_ACTIVE_ON, 'reg_ip' => AZLib::ip());
             $id = DB::insert('user', $user_info);
             if ($id) {
                 $_SESSION['just_registed'] = TIME_NOW;
                 AZLib::my_setcookie('just_registed', TIME_NOW);
                 if (USER_ACTIVE_ON && $user_info['is_active'] == 1) {
                     global $display;
                     $active = DB::select('user_active', 'user_id=' . $id);
                     $active_code = md5(TIME_NOW . $user_info['password']);
                     if ($active) {
                         $active = array('id' => $active['id'], 'user_id' => $id, 'active_code' => $active_code, 'time' => TIME_NOW);
                     } else {
                         $active = array('user_id' => $id, 'active_code' => $active_code, 'time' => TIME_NOW);
                     }
                     DB::insert('user_active', $active, true);
                     $display->add('eb_url', WEB_ROOT);
                     $display->add('user_id', $id);
                     $display->add('user_name', $user_info['user_name']);
                     $display->add('active_code', $active_code);
                     $display->add('WEB_NAME', WEB_NAME);
                     $display->add('MAIL_FOOTER', MAIL_FOOTER);
                     $content_email = $display->output('send_active_mail', 1, 'RegisterSuccess');
                     //Send email here;
                     if (System::sendEBEmail($user_info['email'], 'Kích hoạt tài khoản!', $content_email)) {
                         //$this->setFormSucces('','<b>Chúc mừng bạn đã đăng ký tài khoản thành công!</b><br /><br />Mã kích hoạt đã được gửi đi tới E-mail: "'.$user_info['email'].'"<br />Bạn hãy check lại Email để kích hoạt tài khoản của mình!');
                         Url::redirect('reg_success', array('cmd' => 'notify'));
                     } else {
                         $this->setFormError('', '<b>Chúc mừng bạn đã đăng ký tài khoản thành công!</b><br /><br />Tuy nhiên hệ thống chưa gửi được Mã kích hoạt tới E-mail: "' . $user_info['email'] . '"!<br />Bạn có thể <a href="' . Url::build('reg_success', array('cmd' => 'active')) . '">click vào đây</a> để hệ thống gửi lại mã kích hoạt vào Email của mình!');
                     }
                     $this->show_form = false;
                 } else {
                     User::Login($id);
                     Url::redirect('reg_success');
                 }
             } else {
                 $this->setFormError('', "Chưa đăng ký được, mời bạn thử lại!");
             }
         }
     }
 }
Exemple #8
0
    function on_submit()
    {
        if (User::checkLock4Ever(1)) {
            Url::redirect_current();
        }
        $user_name = AZLib::getParam('user_name_this');
        $password = AZLib::getParam('password_this');
        $this->checkFormInput('Tên truy cập', 'user_name', $user_name, 'uname', true, '', 4, 50);
        $this->checkFormInput('Mật khẩu truy cập', 'password', $password, 'str', true, '', 6, 50);
        // check de ban IP
        $ip = AZLib::ip();
        $arr_badwords = AZLib::checkBadWord($ip, true);
        if ($arr_badwords["bad"] != "" && $arr_badwords["bad_key"] != "") {
            $this->setFormError('ban_ip', "Có lỗi xẩy ra. Hãy kiểm tra lại");
        }
        // end check de ban IP
        if (!$this->errNum) {
            $user_data = DB::fetch('SELECT id, user_name, password, is_active, block_time FROM user WHERE user_name="' . $user_name . '"');
            if (!USER_ACTIVE_ON && $user_data && $user_data['is_active']) {
                DB::query("UPDATE user SET is_active=0 WHERE id=" . $user_data['id']);
                DB::delete('user_active', 'user_id=' . $user_data['id']);
                User::getUser($user_data['id'], 0, 1);
            }
            if ($user_data && $user_data['password'] == User::encode_password($password)) {
                if (USER_ACTIVE_ON && $user_data['is_active']) {
                    //Chưa kích hoạt
                    $this->setFormError('user_name', "Bạn chưa kích hoạt tài khoản!<br /><br />Bạn hãy check lại mail để kích hoạt lại tài khoản<br />\r\n\t\t\t\t\thoặc <a href=''>click vào đây</a> để hệ thống gửi lại email kích hoạt!");
                } else {
                    $alert = '';
                    $href = base64_decode(Url::get('href'));
                    if (!$href) {
                        $href = Url::build('home');
                    }
                    if ($user_data['block_time'] == -1) {
                        $this->setFormError('user_name', "Tài khoản hoặc mật khẩu không đúng!");
                    } elseif ($user_data['block_time'] > TIME_NOW) {
                        $user_lock = DB::select('user_lock', 'user_id=' . $user_data['id']);
                        if ($user_lock) {
                            if ($user_lock['type'] == 1) {
                                //Khoá vĩnh viễn
                                User::LogOut();
                                DB::delete(_SESS_TABLE, 'user_id=' . $user_id, __LINE__ . __FILE__);
                                Url::access_denied();
                            } elseif ($user_lock['type'] == 3) {
                                //Khoá vĩnh viễn + cookie
                                User::lock4Ever(true, $user_data['id']);
                                Url::access_denied();
                            } else {
                                if ($user_lock['note']) {
                                    $user_lock['note'] = '\\nLý do: ' . str_replace(array('"', "'"), '', $user_lock['note']);
                                }
                                $alert = '<script>
											alert("Tài khoản của bạn đang tạm khoá tới ' . date('h:i, d/m/Y', $user_data['block_time']) . '!' . $user_lock['note'] . '");
											window.location="' . $href . '";
										</script>';
                                //$this->setFormError('user_name',"Tài khoản của bạn đang tạm khoá tới ".date('d/m/Y H:i',$user_data['block_time'])."!".$user_lock['note']);
                            }
                        }
                        $_SESSION['user_lock'] = true;
                    }
                    if (Url::get('set_cookie') == 'on') {
                        $year = 60 * 60 * 24 * 365 + TIME_NOW;
                        AZLib::my_setcookie("az_id", $user_data['id'], $year);
                        AZLib::my_setcookie("password", $user_data['password'], $year);
                    }
                    $_SESSION['is_load_page_first'] = 1;
                    // dung jQueryUI de load bang thong bao
                    User::LogIn($user_data['id']);
                    if (isset($_SESSION['user_lock']) && $_SESSION['user_lock']) {
                        echo $alert;
                        exit;
                    } else {
                        Url::redirect_url($href);
                    }
                }
            } else {
                $this->setFormError('user_name', "Tài khoản hoặc mật khẩu không đúng!");
            }
        }
    }
Exemple #9
0
 function fn_reset_pas()
 {
     $user_id = EClassApi::getParam('user_id');
     $user = User::getUser($user_id);
     if (!$user_id || !$user || !User::have_permit(user_all_perm) || !User::is_root()) {
         echo "no_perm";
         exit;
     }
     $gid = User::check_admin($user['gids']);
     if ($user_id != User::id() && ($gid == 9 || $gid == 1 && !User::is_root())) {
         //root ko đc đổi pass của root, admin ko đc đổi pass admin
         echo "no_perm";
         exit;
     }
     $checked = EClassApi::getParam('checked');
     //EClassApi::getParam('pas');//Chú ý đối với mật khẩu ko đc dùng qua hàm này vì dữ liệu sẽ bị biến dạng
     $pas = Url::get('pas');
     $user_name = $user['user_name'];
     if ($checked == 'on') {
         $messenger = file_get_contents(CGlobal::$curTemplate['folder'] . 'ForgotPassword/reset_password.html');
         $message = str_replace('[[|user_name|]]', $user_name, $messenger);
         $message = str_replace('[[|password|]]', $pas, $message);
         $subject = 'Khôi phục mật khẩu!';
         $row = DB::fetch('SELECT email FROM account WHERE id="' . $user_id . '"');
         if (System::sendEBEmail($row['email'], $subject, $message)) {
             $id_update = DB::update('account', array('password' => User::encode_password($pas)), "id ={$user_id}");
             if ($id_update) {
                 echo "success";
                 exit;
             }
         } else {
             echo "unsuccess";
             exit;
         }
     } else {
         $id_update = DB::update('account', array('password' => User::encode_password($pas)), 'id ="' . $user_id . '"');
         if ($id_update) {
             echo "success";
             exit;
         }
     }
 }
Exemple #10
0
 function on_submit()
 {
     $full_name = Url::get('full_name');
     $email = Url::get('email');
     $user_name = Url::get('register_user_name');
     $mobile_phone = AZLib::trimSpace(Url::get('mobile_phone'));
     $home_phone = AZLib::trimSpace(Url::get('home_phone'));
     $password = AZLib::trimSpace(Url::get('register_password'));
     $confirm_password = AZLib::trimSpace(Url::get('confirm_password'));
     $gender = (int) Url::get('gender');
     $yahoo_id = AZLib::trimSpace(Url::get('yahoo_id'));
     $skype_id = AZLib::trimSpace(Url::get('skype_id'));
     $address = AZLib::trimSpace(Url::get('address'));
     $website = AZLib::trimSpace(Url::get('website'));
     $this->checkFormInput('Tên đầy đủ', 'full_name', $full_name, 'str', false, '', 0, 50);
     $this->checkFormInput('Email', 'email', $email, 'email', true, '', 6, 50);
     $this->checkFormInput('Tên truy cập', 'user_name', $user_name, 'uname', true, '', 4, 50);
     $this->checkFormInput('Điện thoại di động', 'mobile_phone', $mobile_phone, 'str', false, '', 0, 50);
     $this->checkFormInput('Điện thoại bàn', 'home_phone', $home_phone, 'str', false, '', 0, 50);
     $this->checkFormInput('Mật khẩu truy cập', 'register_password', $password, 'str', true, '', 6, 50);
     $this->checkFormInput('Nhập lại mật khẩu', 'confirm_password', $confirm_password, 'str', true, '', 6, 50);
     if ($password != $confirm_password) {
         $this->setFormError('confirm_password', "Nhập lại Mật khẩu truy cập không khớp!");
         return;
     }
     if ($mobile_phone && !AZLib::is_mobile($mobile_phone)) {
         $mobile_phone = "";
     }
     if (!$this->errNum) {
         if (DB::exists('SELECT id FROM `user` WHERE `email`="' . $email . '"')) {
             $this->setFormError('email', "<b>Email</b> bạn chọn đã tồn tại, hãy chọn lại một <b>Email</b> khác!");
         } elseif (DB::exists('SELECT id FROM `user` WHERE `user_name`="' . $user_name . '"')) {
             $this->setFormError('email', "<b>Tên truy cập</b> bạn chọn đã tồn tại, hãy chọn lại một <b>Tên truy cập</b> khác!");
         } else {
             $user_info = array('user_name' => $user_name, 'email' => $email, 'password' => User::encode_password($password), 'full_name' => $full_name, 'mobile_phone' => $mobile_phone, 'home_phone' => $home_phone, 'create_time' => TIME_NOW, 'gender' => $gender == 1 ? 0 : 1, 'yahoo_id' => $yahoo_id, 'skype_id' => $skype_id, 'address' => $address, 'website' => $website, 'is_active' => (int) (bool) USER_ACTIVE_ON, 'reg_ip' => AZLib::ip());
             $id = DB::insert('user', $user_info);
             if ($id) {
                 if (USER_ACTIVE_ON && $user_info['is_active'] == 1) {
                     global $display;
                     $active = DB::select('user_active', 'user_id=' . $id);
                     $active_code = md5(TIME_NOW . $user_info['password']);
                     if ($active) {
                         $active = array('id' => $active['id'], 'user_id' => $id, 'active_code' => $active_code, 'time' => TIME_NOW);
                     } else {
                         $active = array('user_id' => $id, 'active_code' => $active_code, 'time' => TIME_NOW);
                     }
                     DB::insert('user_active', $active, true);
                     $display->add('eb_url', WEB_ROOT);
                     $display->add('user_id', $id);
                     $display->add('user_name', $user_info['user_name']);
                     $display->add('active_code', $active_code);
                     $content_email = $display->output('send_active_mail', 1, 'RegisterSuccess');
                     //Send email here;
                     if (System::sendEBEmail($user_info['email'], 'Kích hoạt tài khoản!', $content_email)) {
                         Url::redirect_current();
                     } else {
                         $this->setFormError('', '<b>Tạo mới tài khoản thành công!</b><br /><br />Tuy nhiên hệ thống chưa gửi được Mã kích hoạt tới E-mail: "' . $user_info['email'] . '"!');
                     }
                     $this->show_form = false;
                 } else {
                     Url::redirect_current();
                 }
             } else {
                 $this->setFormError('', "Chưa đăng ký được, mời bạn thử lại!");
             }
         }
     }
 }