Example #1
0
 public function get_unique_invitation_code()
 {
     $invitation_code = md5(uniqid(rand(), true) . fetch_salt(4));
     if ($this->fetch_row('invitation', "invitation_code = '" . $this->quote($invitation_code) . "'")) {
         return $this->get_unique_invitation_code();
     } else {
         return $invitation_code;
     }
 }
Example #2
0
 public function save_user_action()
 {
     if ($_POST['uid']) {
         if (!($user_info = $this->model('account')->get_user_info_by_uid($_POST['uid']))) {
             H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('用户不存在')));
         }
         if ($user_info['group_id'] == 1 and !$this->user_info['permission']['is_administortar']) {
             H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('你没有权限编辑管理员账号')));
         }
         if ($_POST['user_name'] != $user_info['user_name'] and $this->model('account')->get_user_info_by_username($_POST['user_name'])) {
             H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('用户名已存在')));
         }
         if ($_POST['email'] != $user_info['email'] and $this->model('account')->get_user_info_by_username($_POST['email'])) {
             H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('E-mail 已存在')));
         }
         if ($_FILES['user_avatar']['name']) {
             AWS_APP::upload()->initialize(array('allowed_types' => 'jpg,jpeg,png,gif', 'upload_path' => get_setting('upload_dir') . '/avatar/' . $this->model('account')->get_avatar($user_info['uid'], '', 1), 'is_image' => TRUE, 'max_size' => get_setting('upload_avatar_size_limit'), 'file_name' => $this->model('account')->get_avatar($user_info['uid'], '', 2), 'encrypt_name' => FALSE))->do_upload('user_avatar');
             if (AWS_APP::upload()->get_error()) {
                 switch (AWS_APP::upload()->get_error()) {
                     default:
                         H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('错误代码') . ': ' . AWS_APP::upload()->get_error()));
                         break;
                     case 'upload_invalid_filetype':
                         H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('文件类型无效')));
                         break;
                     case 'upload_invalid_filesize':
                         H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('文件尺寸过大, 最大允许尺寸为 %s KB', get_setting('upload_size_limit'))));
                         break;
                 }
             }
             if (!($upload_data = AWS_APP::upload()->data())) {
                 H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('上传失败, 请与管理员联系')));
             }
             if ($upload_data['is_image'] == 1) {
                 foreach (AWS_APP::config()->get('image')->avatar_thumbnail as $key => $val) {
                     $thumb_file[$key] = $upload_data['file_path'] . $this->model('account')->get_avatar($user_info['uid'], $key, 2);
                     AWS_APP::image()->initialize(array('quality' => 90, 'source_image' => $upload_data['full_path'], 'new_image' => $thumb_file[$key], 'width' => $val['w'], 'height' => $val['h']))->resize();
                 }
             }
             $update_data['avatar_file'] = $this->model('account')->get_avatar($user_info['uid'], null, 1) . basename($thumb_file['min']);
         }
         if ($_POST['email']) {
             $update_data['email'] = htmlspecialchars($_POST['email']);
         }
         $update_data['invitation_available'] = intval($_POST['invitation_available']);
         $verify_apply = $this->model('verify')->fetch_apply($user_info['uid']);
         if ($verify_apply) {
             $update_data['verified'] = $_POST['verified'];
             if (!$update_data['verified']) {
                 $this->model('verify')->decline_verify($user_info['uid']);
             } else {
                 if ($update_data['verified'] != $verify_apply['type']) {
                     $this->model('verify')->update_apply($user_info['uid'], null, null, null, null, $update_data['verified']);
                 }
             }
         } else {
             if ($_POST['verified']) {
                 $verified_id = $this->model('verify')->add_apply($user_info['uid'], null, null, $_POST['verified']);
                 $this->model('verify')->approval_verify($verified_id);
             }
         }
         $update_data['valid_email'] = intval($_POST['valid_email']);
         $update_data['forbidden'] = intval($_POST['forbidden']);
         $update_data['group_id'] = intval($_POST['group_id']);
         if ($update_data['group_id'] == 1 and !$this->user_info['permission']['is_administortar']) {
             unset($update_data['group_id']);
         }
         $update_data['province'] = htmlspecialchars($_POST['province']);
         $update_data['city'] = htmlspecialchars($_POST['city']);
         $update_data['job_id'] = intval($_POST['job_id']);
         $update_data['mobile'] = htmlspecialchars($_POST['mobile']);
         $update_data['sex'] = intval($_POST['sex']);
         $this->model('account')->update_users_fields($update_data, $user_info['uid']);
         if ($_POST['delete_avatar']) {
             $this->model('account')->delete_avatar($user_info['uid']);
         }
         if ($_POST['password']) {
             $this->model('account')->update_user_password_ingore_oldpassword($_POST['password'], $user_info['uid'], fetch_salt(4));
         }
         $this->model('account')->update_users_attrib_fields(array('signature' => htmlspecialchars($_POST['signature']), 'qq' => htmlspecialchars($_POST['qq']), 'homepage' => htmlspecialchars($_POST['homepage'])), $user_info['uid']);
         if ($_POST['user_name'] != $user_info['user_name']) {
             $this->model('account')->update_user_name($_POST['user_name'], $user_info['uid']);
         }
         H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('用户资料更新成功')));
     } else {
         $_POST['user_name'] = trim($_POST['user_name']);
         $_POST['email'] = trim($_POST['email']);
         $_POST['password'] = trim($_POST['password']);
         $_POST['group_id'] = intval($_POST['group_id']);
         if (!$_POST['user_name']) {
             H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请输入用户名')));
         }
         if ($this->model('account')->check_username($_POST['user_name'])) {
             H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('用户名已经存在')));
         }
         if ($this->model('account')->check_email($_POST['email'])) {
             H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('E-Mail 已经被使用, 或格式不正确')));
         }
         if (strlen($_POST['password']) < 6 or strlen($_POST['password']) > 16) {
             H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('密码长度不符合规则')));
         }
         $uid = $this->model('account')->user_register($_POST['user_name'], $_POST['password'], $_POST['email']);
         $this->model('active')->set_user_email_valid_by_uid($uid);
         $this->model('active')->active_user_by_uid($uid);
         if ($_POST['group_id'] == 1 and !$this->user_info['permission']['is_administortar']) {
             $_POST['group_id'] = 4;
         }
         if ($_POST['group_id'] != 4) {
             $this->model('account')->update('users', array('group_id' => $_POST['group_id']), 'uid = ' . $uid);
         }
         H::ajax_json_output(AWS_APP::RSM(array('url' => get_js_url('/admin/user/list/')), 1, null));
     }
 }
Example #3
0
 /**
  * 插入用户数据
  *
  * @param string
  * @param string
  * @param string
  * @param int
  * @param string
  * @return int
  */
 public function insert_user($user_name, $password, $email = null, $sex = 0, $mobile = null)
 {
     /*    if (!$user_name OR !$password)
             {
                 return false;
             }
     
             if ($this->check_username($user_name))
             {
                 return false;
             }
     
             if ($email AND $user_info = $this->get_user_info_by_email($email, false))
             {
                 return false;
             }
     */
     $salt = fetch_salt(4);
     if ($uid = $this->insert('users', array('user_name' => $user_name, 'password' => compile_password($password, $salt), 'salt' => $salt, 'email' => $email, 'sex' => intval($sex), 'mobile' => $mobile, 'reg_time' => time(), 'reg_ip' => ip2long(fetch_ip()), 'email_settings' => serialize(get_setting('new_user_email_setting'))))) {
         $this->insert('users_attrib', array('uid' => $uid));
         $this->update_notification_setting_fields(get_setting('new_user_notification_setting'), $uid);
         //$this->model('search_fulltext')->push_index('user', $user_name, $uid);
     }
     return $uid;
     /*
        	$username = '******';
        	$password = '******';
        	$database = 'test1';
        	$dbc = mysqli_connect($host, $username, $password, $database);
        	$query = "INSERT INTO users(user_name,password,salt,email,sex,mobile,reg_time,reg_ip,email_settings) VALUES ('$user_name',compile_password($password, $salt),'$salt','$email',intval($sex),'$mobile',time(),ip2long(fetch_ip()),serialize(get_setting('new_user_email_setting')))";
        	mysqli_query($dbc,$query) or die("Error!!");
        	mysqli_close($dbc);
        	header('Location: user.php');
     */
 }
Example #4
0
 /**
  * 插入用户数据
  *
  * @param string
  * @param string
  * @param string
  * @param int
  * @param string
  * @return int
  */
 public function insert_user($user_name, $password, $email = null, $sex = 0, $mobile = null)
 {
     if (!$user_name or !$password) {
         return false;
     }
     if ($this->check_username($user_name)) {
         return false;
     }
     if ($email and $user_info = $this->get_user_info_by_email($email, false)) {
         return false;
     }
     $salt = fetch_salt(4);
     if ($uid = $this->insert('users', array('user_name' => htmlspecialchars($user_name), 'password' => compile_password($password, $salt), 'salt' => $salt, 'email' => htmlspecialchars($email), 'sex' => intval($sex), 'mobile' => htmlspecialchars($mobile), 'reg_time' => time(), 'reg_ip' => ip2long(fetch_ip()), 'email_settings' => serialize(get_setting('new_user_email_setting'))))) {
         $this->insert('users_attrib', array('uid' => $uid));
         $this->update_notification_setting_fields(get_setting('new_user_notification_setting'), $uid);
         //$this->model('search_fulltext')->push_index('user', $user_name, $uid);
     }
     return $uid;
 }
Example #5
0
                $base_url = substr_replace($base_url, '', -8);
            }
            $insert_query = str_replace('[#UPLOAD_URL#]', serialize($base_url . "/uploads"), $insert_query);
            $insert_query = str_replace('[#UPLOAD_DIR#]', serialize(str_replace("\\", "/", ROOT_PATH) . "uploads"), $insert_query);
        }
        $insert_query = str_replace('[#FROM_EMAIL#]', serialize($_POST['email']), $insert_query);
        $insert_query = str_replace('[#DB_VERSION#]', serialize(G_VERSION_BUILD), $insert_query);
        //$db->query($insert_query);
        $sql_query = str_replace("\n", "\r", $insert_query);
        $db_table_querys = explode(";\r", $sql_query);
        foreach ($db_table_querys as $_sql) {
            if ($query_string = trim(str_replace(array("\r", "\n", "\t"), '', $_sql))) {
                try {
                    $db->query($query_string);
                } catch (Exception $e) {
                    die('SQL Error: ' . $e->getMessage() . '<br /><br />Query: ' . $query_string);
                }
            }
        }
        $db->insert($db_prefix . 'system_setting', array('varname' => 'register_agreement', 'value' => serialize(file_get_contents(ROOT_PATH . 'install/db/register_agreement.txt'))));
        if (!defined('IN_SAE')) {
            $config_file = file_get_contents(AWS_PATH . 'config.dist.php');
            $config_file = str_replace('{G_COOKIE_PREFIX}', fetch_salt(3) . '_', $config_file);
            $config_file = str_replace('{G_SECUKEY}', fetch_salt(12), $config_file);
            $config_file = str_replace('{G_COOKIE_HASH_KEY}', fetch_salt(15), $config_file);
            file_put_contents(AWS_PATH . 'config.inc.php', $config_file);
            file_put_contents(AWS_PATH . 'config/install.lock.php', time());
        }
        TPL::output('install/success');
        break;
}