Example #1
0
 public function hand_registration()
 {
     try {
         $db = new PDO("mysql:dbname=xuthulu", 'root', 'password');
         if (isset($_POST['username']) || isset($_POST['sup_zip_code']) || isset($_POST['sup_city']) || isset($_POST['sup_email']) || isset($_POST['sup_pass'])) {
             $userService = new User($db, $_POST['sup_email'], $_POST['sup_pass']);
             try {
                 $userService->set_email($_POST['sup_email']);
                 $userService->set_username($_POST['username']);
                 $userService->set_city($_POST['sup_city']);
             } catch (Exception $e) {
                 echo "Error: {$e->getMessage()}";
             }
             // Create user
             $userService->sign_up();
             // Create the user session
             if ($user_id = $userService->login()) {
                 $userData = $userService->getUser();
                 header("Location:userpage.php");
             }
         }
     } catch (Exception $e) {
         echo "Error: {$e->getMessage()}";
     }
 }
Example #2
0
 public function create_user($username, $password, $email, $phone, $bdate, $information, $interests, $city, $image)
 {
     $user = new User();
     try {
         $user->set_username(Validation::username($username));
     } catch (Exception $ex) {
         echo 'Failed: ', $ex->getMessage();
         exit;
     }
     try {
         $user->set_password(Validation::password($password));
     } catch (Exception $ex) {
         echo 'Failed: ', $ex->getMessage();
         exit;
     }
     try {
         $user->set_email(Validation::email($email));
     } catch (Exception $ex) {
         echo 'Failed: ', $ex->getMessage();
         exit;
     }
     try {
         $user->set_phone(Validation::phone($phone));
     } catch (Exception $ex) {
         echo 'Failed: ', $ex->getMessage();
         exit;
     }
     try {
         $user->set_bdate(Validation::bdate($bdate));
     } catch (Exception $ex) {
         echo 'Failed: ', $ex->getMessage();
         exit;
     }
     try {
         $user->set_information(Validation::information($information));
     } catch (Exception $ex) {
         echo 'Failed: ', $ex->getMessage();
         exit;
     }
     try {
         $user->set_interests(Validation::interests($interests));
     } catch (Exception $ex) {
         echo 'Failed: ', $ex->getMessage();
         exit;
     }
     try {
         $user->set_city(Validation::city($city));
     } catch (Exception $ex) {
         echo 'Failed: ', $ex->getMessage();
         exit;
     }
     try {
         $user->set_image(Validation::image($image));
     } catch (Exception $ex) {
         echo 'Failed: ', $ex->getMessage();
         exit;
     }
     return $user;
 }
Example #3
0
 function authenticate_user($user_name, $user_pass)
 {
     // First determine if this is a local or ldap user
     if ($this->is_local_user($user_name, 'local')) {
         return $this->authenticate_local_user($user_name, $user_pass);
     } else {
         if (!($user_info = $this->authenticate_ldap_user($user_name, $user_pass))) {
             // Auth failed
             return false;
         }
         // Userinfo is an array which hold email and full name
         // Ok user is success fully authenticated
         // create user object and update / insert
         if (!($userid = $this->is_local_user($user_name, 'ldap'))) {
             $ldap_user = new User();
             $ldap_user->set_full_name($user_info["fullname"]);
             $ldap_user->set_email($user_info["email"]);
             $ldap_user->set_user_name($user_name);
             $ldap_user->set_user_type('ldap');
             // New user insert in local user
             if (!($userid = $ldap_user->insert())) {
                 // Unable to update local user cache
                 $this->error = $ldap_user->get_error();
                 return false;
             }
             // existing  user update in local user cache
         } else {
             $ldap_user = new User($userid);
             $ldap_user->set_full_name($user_info["fullname"]);
             $ldap_user->set_email($user_info["email"]);
             $ldap_user->set_user_name($user_name);
             $ldap_user->set_user_type('ldap');
             if (!$ldap_user->update()) {
                 // Unable to update local user cache
                 $this->error = $ldap_user->get_error();
                 return false;
             }
         }
         // get groups
         if (!($ldap_groups = $this->get_ldap_groups($user_name, $user_pass))) {
             return false;
         }
         if (!$this->update_ldap_groups($userid, $ldap_groups)) {
             // Unable to update local group cache
             return false;
         }
         return true;
     }
 }
 public function get_user($email, $password)
 {
     $this->db->connect();
     $user = null;
     $sql = "SELECT * from tbl_user WHERE email=? AND password=?";
     $stmt = $this->db->initStatement($sql);
     $stmt->bind_param("ss", $email, $password);
     $stmt->execute();
     $stmt->bind_result($id, $email, $password);
     while ($stmt->fetch()) {
         $user = new User();
         $user->set_id($id);
         $user->set_email($email);
     }
     $this->db->close();
     return $user;
 }
Example #5
0
 public function set_user_email($email)
 {
     parent::set_email($email);
 }
Example #6
0
function process_page($app, $action, &$var)
{
    $var['domain_count'] = Domain::count();
    $var['user_count'] = User::count();
    $var['domains'] = Domain::list_all();
    if (!isset($var['domain_id'])) {
        if (isset($_COOKIE['app/users/domain_id'])) {
            $var['domain_id'] = filter_var($_COOKIE['app/users/domain_id'], FILTER_SANITIZE_STRING);
            if (Domain::list_by_id($var['domain_id']) == null) {
                $var['domain_id'] = 0;
            }
        } else {
            $var['domain_id'] = 0;
        }
    }
    if ($var['domain_id'] != 0) {
        $var['users'] = User::list_by_domain_id($var['domain_id']);
        $var['active_domain'] = Domain::list_by_id($var['domain_id']);
    } else {
        $var['users'] = User::list_all();
    }
    switch ($app->action) {
        case 'select_domain':
            setcookie('app/users/domain_id', $var['domain_id']);
            $app->reload();
            break;
        case 'edit_user':
            $user = User::list_by_id($var['user_id']);
            $var['user_email'] = $user->get_email();
            $var['user_password'] = '';
            if ($user->is_admin()) {
                $var['user_admin'] = 'on';
            } else {
                unset($var['user_admin']);
            }
            break;
        case 'insert_new_user':
            $user = new User();
            $user->set_email($var['user_email']);
            $user->set_password($var['user_password']);
            $user->set_domain_id($var['domain_id']);
            $user->set_admin(isset($var['user_admin']));
            if ($user->insert()) {
                $app->reload();
            } else {
                $app->action = 'new_user';
            }
            break;
        case 'update_edit_user':
            $user = User::list_by_id($var['user_id']);
            $user->set_email($var['user_email']);
            $user->set_password($var['user_password']);
            $user->set_admin(isset($var['user_admin']));
            if ($user->update()) {
                $app->reload();
            } else {
                $app->action = 'edit_user';
            }
            break;
        case 'delete_user':
            $user = User::list_by_id($var['user_id']);
            if ($user->delete()) {
                $app->reload();
            }
            break;
    }
}
 private function create_first_admin_account($login, $password, $email, $locale, $theme, $timezone)
 {
     $user = new User();
     $user->set_display_name($login);
     $user->set_level(User::ADMIN_LEVEL);
     $user->set_email($email);
     $user->set_locale($locale);
     $user->set_theme($theme);
     $auth_method = new PHPBoostAuthenticationMethod($login, $password);
     return UserService::create($user, $auth_method);
 }
 private function save()
 {
     $user = new User();
     $user->set_display_name($this->form->get_value('display_name'));
     $user->set_level($this->form->get_value('rank')->get_raw_value());
     $user->set_email($this->form->get_value('email'));
     $login = $this->form->get_value('email');
     if ($this->form->get_value('custom_login', false)) {
         $login = $this->form->get_value('login');
     }
     $auth_method = new PHPBoostAuthenticationMethod($login, $this->form->get_value('password'));
     UserService::create($user, $auth_method);
     return $user->get_display_name();
 }
Example #9
0
function get_user_by_name($name)
{
    $mysqli = new mysqli(get_db_host(), get_db_user(), get_db_password(), get_db_database());
    $stmt = $mysqli->prepare("SELECT id, name, email, password_hash FROM user WHERE name = ? LIMIT 1");
    $stmt->bind_param("s", $name);
    $stmt->execute();
    $res = $stmt->get_result();
    if ($res->num_rows > 0) {
        $row = $res->fetch_assoc();
        $user = new User();
        $user->set_id($row['id']);
        $user->set_name($row['name']);
        $user->set_email($row['email']);
        $user->set_password_hash($row['password_hash']);
        $stmt->close();
        return $user;
    } else {
        return NULL;
    }
}
 /**
  * {@inheritDoc}
  */
 public function authenticate()
 {
     $data = $this->get_google_user_data();
     $google_id = $data['id'];
     try {
         $condition = 'WHERE method=:method AND identifier=:identifier';
         $parameters = array('method' => self::AUTHENTICATION_METHOD, 'identifier' => $google_id);
         return $this->querier->get_column_value(DB_TABLE_AUTHENTICATION_METHOD, 'user_id', $condition, $parameters);
     } catch (RowNotFoundException $e) {
         $email_exists = $this->querier->row_exists(DB_TABLE_MEMBER, 'WHERE email=:email', array('email' => $data['email']));
         if ($email_exists) {
             $this->error_msg = LangLoader::get_message('external-auth.account-exists', 'user-common');
         } else {
             $user = new User();
             $user->set_display_name(utf8_decode($data['name']));
             $user->set_level(User::MEMBER_LEVEL);
             $user->set_email($data['email']);
             $auth_method = new GoogleAuthenticationMethod();
             $fields_data = array('user_avatar' => $data['picture']);
             return UserService::create($user, $auth_method, $fields_data);
         }
     }
 }
Example #11
0
 /**
  * Helper function to create a user after applying checks on the
  * in parameters. Rather than throwing an exception, this returns
  * NULL if parameters are invalid.
  */
 public static function create($name, $password, $email)
 {
     $email = filter_var($email, FILTER_SANITIZE_EMAIL);
     if (!ctype_alnum($name) || $email != NULL && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return NULL;
     }
     $salt = base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM));
     $hash = hash('whirlpool', $salt . $password);
     $user = new User();
     $user->set_name($name);
     $user->set_email($email);
     $user->set_salt($salt);
     $user->set_password_hash($hash);
     return $user;
 }
Example #12
0
            echo "Mật khẩu không đúng.";
            $flag = FALSE;
        }
    }
    if ($flag == TRUE) {
        if ($_POST['txthoten'] != "") {
            $u->set_hoten($_POST['txthoten']);
        }
        if ($_POST['txtdiachi'] != "") {
            $u->set_diachi($_POST['txtdiachi']);
        }
        if ($_POST['txtdienthoai'] != "") {
            $u->set_dienthoai($_POST['txtdienthoai']);
        }
        if ($_POST['txtemail'] != "") {
            $u->set_email($_POST['txtemail']);
        }
        if ($_POST['txtpass'] != "") {
            $u->set_pass($_POST['txtpass1']);
        }
        $u->set_gioitinh($_POST['rgioitinh']);
        $ngaysinh = $_POST['date1_day'];
        $thangsinh = $_POST['date1_month'];
        $namsinh = $_POST['date1_year'];
        $ngay = $namsinh . "-" . $thangsinh . "-" . $ngaysinh;
        $u->set_ngaysinh($ngay);
        $u->update_chitiet();
        dongcuaso();
        exit;
    }
}
Example #13
0
 /**
  * Get a user object from a SQL row result.
  */
 public static function get_user_from_row($row)
 {
     if (!$row) {
         return NULL;
     }
     $user = new User();
     $user->set_id($row['user_id']);
     $user->set_name($row['user_name']);
     $user->set_email($row['user_email']);
     $user->set_salt($row['user_salt']);
     $user->set_password_hash($row['user_passwordhash']);
     return $user;
 }
Example #14
0
     if (!isset($_REQUEST["inactive_user"])) {
         $user->set_last_seen("change_user_info:name");
     }
     die("done");
 case "edit_dob":
     list($year, $month, $day) = explode("-", $_POST["datepicker"]);
     $user->set_dob($year, $month, $day);
     if (!isset($_REQUEST["inactive_user"])) {
         $user->set_last_seen("change_user_info:dob");
     }
     die("done");
 case "edit_email":
     if (!preg_match("/^(([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5}){1,25})+([;.](([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5}){1,25})+)*\$/", $_POST["email"])) {
         die("error_invalid");
     }
     $user->set_email($_POST["email"]);
     if (!isset($_REQUEST["inactive_user"])) {
         $user->set_last_seen("change_user_info:email");
     }
     die("done");
 case "edit_phone_home":
     if (!is_numeric($_POST["phone_home"])) {
         die("error_invalid");
     }
     $user->set_phone_home($_POST["phone_home"]);
     if (!isset($_REQUEST["inactive_user"])) {
         $user->set_last_seen("change_user_info:phone_home");
     }
     die("done");
 case "edit_cell_home":
     if (!is_numeric($_POST["phone_cell"])) {
Example #15
0
function updateUser()
{
    global $tool, $propertyForm;
    $tempInfo = array();
    $infoKey = array("id", "full", "user", "email");
    foreach ($infoKey as $index => $key) {
        $tempInfo[$key] = htmlspecialchars(trim($_POST[$key]), ENT_QUOTES);
    }
    //add slashes to these 2 to make sure it does not display wrongly
    $tempInfo[user] = addslashes($tempInfo[user]);
    $tempInfo[full] = addslashes($tempInfo[full]);
    $newUser = new User($tempInfo[id]);
    //checks if the name is empty, if not set all the names and insert them
    if ($newUser->set_user_name($tempInfo[user])) {
        //set all the values to the query
        $newUser->set_full_name($tempInfo[full]);
        $newUser->set_email($tempInfo[email]);
        //if the insert is sucessful reload the page with the new values
        if ($newUser->update()) {
            $status = "success";
            echo "<script language='javascript'>LoadPage(\"configurations.php?action=userManage&mode=edit&update=" . $status . "\", 'settingsInfo');</script>";
            //echo "<meta http-equiv=\"REFRESH\" content=\"0;url=".$_SERVER['PHP_SELF']."?action=userManage&add=$status\">";
        } else {
            $propertyForm->error("Warning: Failed to update user. Reason: " . $newUser->get_error(), $_GET['ID']);
        }
    } else {
        $propertyForm->error("Warning: Failed to update user. Reason: " . $newUser->get_error(), $_GET['ID']);
    }
}
Example #16
0
     }
 }
 if ($Messages->has_errors()) {
     // Stop registration if the errors exist
     break;
 }
 $DB->begin();
 $new_User = new User();
 $new_User->set('login', $login);
 $new_User->set_password($pass1);
 $new_User->set('ctry_ID', $country);
 $new_User->set('firstname', $firstname);
 $new_User->set('lastname', $lastname);
 $new_User->set('gender', $gender);
 $new_User->set('source', $source);
 $new_User->set_email($email);
 $new_User->set_datecreated($localtimenow);
 if ($registration_ask_locale) {
     // set locale if it was prompted, otherwise let default
     $new_User->set('locale', $locale);
 }
 if (!empty($invitation)) {
     // Invitation code was entered on the form
     $SQL = new SQL();
     $SQL->SELECT('ivc_source, ivc_grp_ID');
     $SQL->FROM('T_users__invitation_code');
     $SQL->WHERE('ivc_code = ' . $DB->quote($invitation));
     $SQL->WHERE_and('ivc_expire_ts > ' . $DB->quote(date('Y-m-d H:i:s', $localtimenow)));
     if ($invitation_code = $DB->get_row($SQL->get())) {
         // Set source and group from invitation code
         $new_User->set('source', $invitation_code->ivc_source);
 private function save()
 {
     $has_error = false;
     $registration_pass = $this->user_accounts_config->get_member_accounts_validation_method() == UserAccountsConfig::MAIL_USER_ACCOUNTS_VALIDATION ? KeyGenerator::generate_key(15) : '';
     $user_aprobation = $this->user_accounts_config->get_member_accounts_validation_method() == UserAccountsConfig::AUTOMATIC_USER_ACCOUNTS_VALIDATION;
     $user = new User();
     $user->set_display_name($this->form->get_value('display_name'));
     $user->set_level(User::MEMBER_LEVEL);
     $user->set_email($this->form->get_value('email'));
     $user->set_show_email(!$this->form->get_value('user_hide_mail'));
     $user->set_locale($this->form->get_value('lang')->get_raw_value());
     $user->set_editor($this->form->get_value('text-editor')->get_raw_value());
     $user->set_timezone($this->form->get_value('timezone')->get_raw_value());
     if ($this->form->has_field('theme')) {
         $user->set_theme($this->form->get_value('theme')->get_raw_value());
     }
     $login = $this->form->get_value('email');
     if ($this->form->get_value('custom_login')) {
         $login = $this->form->get_value('login');
     }
     $auth_method = new PHPBoostAuthenticationMethod($login, $this->form->get_value('password'));
     $auth_method->set_association_parameters($user_aprobation, $registration_pass);
     try {
         $user_id = UserService::create($user, $auth_method, $this->member_extended_fields_service);
     } catch (MemberExtendedFieldErrorsMessageException $e) {
         $has_error = true;
         $this->tpl->put('MSG', MessageHelper::display($e->getMessage(), MessageHelper::NOTICE));
     }
     if (!$has_error) {
         UserRegistrationService::send_email_confirmation($user_id, $user->get_email(), $this->form->get_value('display_name'), $login, $this->form->get_value('password'), $registration_pass);
         $this->confirm_registration($user_id);
     }
 }
Example #18
0
 /**
  * Event handler: called when a user attemps to login.
  *
  * This function will check if the user exists in the LDAP directory and create it locally if it does not.
  *
  * @param array 'login', 'pass' and 'pass_md5'
  */
 function LoginAttempt(&$params)
 {
     global $localtimenow;
     global $Settings, $Hit, $evo_charset;
     // Check if LDAP is available:
     if (!function_exists('ldap_connect')) {
         $this->debug_log('This PHP installation does not support LDAP functions.');
         return false;
         // Login failed!
     }
     // Get ready to go through ALL LDAP Servers configured in the plugin:
     $search_sets = $this->Settings->get('search_sets');
     if (empty($search_sets)) {
         $this->debug_log('No LDAP servers have been configured in the LDAP plugin settings.');
         return false;
         // Login failed!
     }
     // Detect if we already have a local user with the same login:
     $UserCache =& get_Cache('UserCache');
     if ($local_User =& $UserCache->get_by_login($params['login'])) {
         $this->debug_log('User <b>' . $params['login'] . '</b> already exists locally. We will UPDATE it with the latest LDAP attibutes.');
         $update_mode = true;
         // Try to find a number of a search set which was used on successful logging previous time by current user:
         $user_search_set_num = intval($this->UserSettings->get('search_set_num', $local_User->ID));
         if ($user_search_set_num > 0 && isset($search_sets[$user_search_set_num])) {
             // We have found this, Reorder the array to use the successful set firstly:
             $success_search_set = $search_sets[$user_search_set_num];
             unset($search_sets[$user_search_set_num]);
             $search_sets = array($user_search_set_num => $success_search_set) + $search_sets;
         }
     } else {
         $update_mode = false;
     }
     $this->debug_log(sprintf('LDAP plugin will attempt to login with login=<b>%s</b> / pass=<b>%s</b> / MD5 pass=<b>%s</b>', $params['login'], $params['pass'], $params['pass_md5']));
     // ------ Loop through list of configured LDAP Servers: ------
     foreach ($search_sets as $l_id => $l_set) {
         $this->debug_log('Step 1 : STARTING LDAP AUTH WITH SERVER #' . $l_id);
         // --- CONNECT TO SERVER ---
         $server_port = explode(':', $l_set['server']);
         $server = $server_port[0];
         $port = isset($server_port[1]) ? $server_port[1] : 389;
         if (!empty($l_set['disabled'])) {
             $this->debug_log('Skipping disabled LDAP server &laquo;' . $server . ':' . $port . '&raquo;!');
             continue;
         }
         if (!($ldap_conn = @ldap_connect($server, $port))) {
             $this->debug_log('Could not connect to LDAP server &laquo;' . $server . ':' . $port . '&raquo;!');
             continue;
         }
         $this->debug_log('Connected to server &laquo;' . $server . ':' . $port . '&raquo;..');
         $ldap_rdn = str_replace('%s', $params['login'], $l_set['rdn']);
         $this->debug_log('Using RDN &laquo;' . $ldap_rdn . '&raquo; for binding...');
         // --- SET PROTOCOL VERSION ---
         // Get protocol version to use:
         if (!ldap_get_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, $initial_protocol_version)) {
             $this->debug_log('Failed to get LDAP_OPT_PROTOCOL_VERSION.');
             $initial_protocol_version = null;
         }
         $protocol_version = isset($l_set['protocol_version']) ? $l_set['protocol_version'] : 'auto';
         // new setting in 2.01
         if ($protocol_version[0] == 'v') {
             // transform "vX" => "X"
             $try_versions = array(substr($protocol_version, 1));
         } else {
             // "auto"
             $try_versions = array(3, 2);
             if (isset($initial_protocol_version)) {
                 array_unshift($try_versions, $initial_protocol_version);
             }
             $try_versions = array_unique($try_versions);
         }
         $this->debug_log('We will try protocol versions: ' . implode(', ', $try_versions));
         // --- VERIFY USER CREDENTIALS BY BINDING TO SERVER ---
         // you might use this for testing with Apache DS: if( !@ldap_bind($ldap_conn, 'uid=admin,ou=system', 'secret') )
         // Bind:
         $bound = false;
         $bind_errors = array();
         foreach ($try_versions as $try_version) {
             $this->debug_log(sprintf('Trying to connect with protocol version: %s / RDN: %s / pass: %s', $try_version, $ldap_rdn, $params['pass']));
             ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, $try_version);
             if (@ldap_bind($ldap_conn, $ldap_rdn, $params['pass'])) {
                 // Success
                 $this->debug_log('Binding worked.');
                 $bound = true;
                 break;
             } else {
                 $this->debug_log('Binding failed. Errno: ' . ldap_errno($ldap_conn) . ' Error: ' . ldap_error($ldap_conn));
             }
         }
         if (!$bound) {
             if (isset($initial_protocol_version)) {
                 // Reset this for the next search set:
                 ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, $initial_protocol_version);
             }
             continue;
         }
         $this->debug_log('User successfully bound to server.');
         // --- STEP 2 : TRY TO OBTAIN MORE INFO ABOUT USER ---
         // Search user info
         $filter = str_replace('%s', $params['login'], $l_set['search_filter']);
         $this->debug_log(sprintf('Step 2 : Now querying for additional user info. base_dn: <b>%s</b>, filter: <b>%s</b>', $l_set['base_dn'], $filter));
         $search_result = @ldap_search($ldap_conn, $l_set['base_dn'], $filter);
         if (!$search_result) {
             // this may happen with an empty base_dn
             $this->debug_log('Invalid ldap_search result. Skipping to next search set. Errno: ' . ldap_errno($ldap_conn) . ' Error: ' . ldap_error($ldap_conn));
             continue;
         }
         $search_info = ldap_get_entries($ldap_conn, $search_result);
         //$this->debug_log( 'Results returned by LDAP Server: <pre>'.var_export( $search_info, true ).'</pre>' );
         if ($search_info['count'] != 1) {
             // We have found 0 or more than 1 users, which is a problem...
             $this->debug_log('# of entries found with search: ' . $search_info['count'] . ' - Skipping...');
             /*
             for ($i=0; $i<$search_info["count"]; $i++) {
             	echo "dn: ". $search_info[$i]["dn"] ."<br>";
             	echo "first cn entry: ". $search_info[$i]["cn"][0] ."<br>";
             	echo "first email entry: ". $search_info[$i]["mail"][0] ."<p>";
             }
             */
             continue;
         }
         $this->debug_log('User info has been found.');
         // --- CREATE OR UPDATE USER ACCOUNT IN B2EVO ---
         if ($update_mode == false) {
             $this->debug_log('Step 3 : Creating a local user in b2evolution...');
             $local_User = new User();
             $local_User->set('login', $params['login']);
             $local_User->set('locale', locale_from_httpaccept());
             // use the browser's locale
             $local_User->set_datecreated($localtimenow);
             // $local_User->set( 'level', 1 );
         } else {
             // User exists already exists
             $this->debug_log('Step 3 : Updating the existing local user.');
         }
         $this->debug_log('Randomize password in b2evolution DB and autoactivate user.');
         // Generate a random password (we never want LDAP users to be able to login without a prior LDAP check) (also on update, just in case...
         $local_User->set_password(generate_random_passwd(32));
         // $params['pass'] );
         $local_User->set('status', 'autoactivated');
         // Activate the user automatically (no email activation necessary)
         // Convert each input string to current server encoding:
         $exclude_encoding_fields = array('uid', 'mail', 'jpegphoto');
         if (isset($search_info[0]) && is_array($search_info[0])) {
             foreach ($search_info[0] as $search_info_key => $search_info_data) {
                 if (isset($search_info_data[0]) && is_string($search_info_data[0]) && !in_array($search_info_key, $exclude_encoding_fields)) {
                     // Convert string from LDAP server encoding to current server encoding:
                     $search_info[0][$search_info_key][0] = convert_charset($search_info_data[0], $l_set['encoding'], $evo_charset);
                 }
             }
         }
         // Make some updates:
         // mail -> email:
         if (isset($search_info[0]['mail'][0])) {
             $local_User->set_email($search_info[0]['mail'][0]);
         }
         // uid -> nickname
         if (isset($search_info[0]['uid'][0])) {
             $this->debug_log('UID: <b>' . $search_info[0]['uid'][0] . '</b>');
             $local_User->set('nickname', $search_info[0]['uid'][0]);
         } else {
             // if not found, use login.
             $local_User->set('nickname', $params['login']);
         }
         // givenname -> Firstname:
         if (isset($search_info[0]['givenname'][0])) {
             $this->debug_log('First name (givenname): <b>' . $search_info[0]['givenname'][0] . '</b>');
             $local_User->set('firstname', $search_info[0]['givenname'][0]);
         }
         // sn -> Lastname:
         if (isset($search_info[0]['sn'][0])) {
             $this->debug_log('Last name (sn): <b>' . $search_info[0]['sn'][0] . '</b>');
             $local_User->set('lastname', $search_info[0]['sn'][0]);
         }
         // roomnumber -> user field "roomnumber" (if not found, autocreate it in group "Address")
         if (isset($search_info[0]['roomnumber'][0])) {
             $this->debug_log('Room number: <b>' . $search_info[0]['roomnumber'][0] . '</b>');
             $this->userfield_update_by_code($local_User, 'roomnumber', $search_info[0]['roomnumber'][0], 'Address', 'Room Number', 'word');
         }
         // businesscategory -> user field "businesscategory" (if not found, autocreate it in group "About me")
         if (isset($search_info[0]['businesscategory'][0])) {
             $this->debug_log('Business Category: <b>' . $search_info[0]['businesscategory'][0] . '</b>');
             $this->userfield_update_by_code($local_User, 'businesscategory', $search_info[0]['businesscategory'][0], 'About me', 'Business Category', 'text');
         }
         // telephonenumber -> user field "officephone" (if not found, autocreate it in group "Phone")
         if (isset($search_info[0]['telephonenumber'][0])) {
             $this->debug_log('Office phone: <b>' . $search_info[0]['telephonenumber'][0] . '</b>');
             $this->userfield_update_by_code($local_User, 'officephone', $search_info[0]['telephonenumber'][0], 'Phone', 'Office phone', 'phone');
         }
         // mobile -> user field "cellphone" (if not found, autocreate it in group "Phone")
         if (isset($search_info[0]['mobile'][0])) {
             $this->debug_log('Cell phone: <b>' . $search_info[0]['mobile'][0] . '</b>');
             $this->userfield_update_by_code($local_User, 'cellphone', $search_info[0]['mobile'][0], 'Phone', 'Cell phone', 'phone');
         }
         // employeenumber -> user field "employeenumber" (if not found, autocreate it in group "About me")
         if (isset($search_info[0]['employeenumber'][0])) {
             $this->debug_log('Employee number: <b>' . $search_info[0]['employeenumber'][0] . '</b>');
             $this->userfield_update_by_code($local_User, 'employeenumber', $search_info[0]['employeenumber'][0], 'About me', 'Employee number', 'word');
         }
         // title -> user field "title" (if not found, autocreate it in group "About me")
         if (isset($search_info[0]['title'][0])) {
             $this->debug_log('Title: <b>' . $search_info[0]['title'][0] . '</b>');
             $this->userfield_update_by_code($local_User, 'title', $search_info[0]['title'][0], 'About me', 'Title', 'word');
             $userfield_title = $search_info[0]['title'][0];
             // Use this as role for all organizations below
         } else {
             $userfield_title = '';
         }
         // departmentnumber -> join Organization with the same name (create if doesn't exist)
         if (isset($search_info[0]['departmentnumber'][0])) {
             $this->debug_log('Department Number: <b>' . $search_info[0]['departmentnumber'][0] . '</b>');
             $this->userorg_update_by_name($local_User, $search_info[0]['departmentnumber'][0], $userfield_title);
         }
         // o -> join Organization with the same name (create if doesn't exist)
         if (isset($search_info[0]['o'][0])) {
             $this->debug_log('Organization: <b>' . $search_info[0]['o'][0] . '</b>');
             $this->userorg_update_by_name($local_User, $search_info[0]['o'][0], $userfield_title);
         }
         // telexnumber -> user field "officefax" (if not found, autocreate it in group "Phone")
         if (isset($search_info[0]['telexnumber'][0])) {
             $this->debug_log('Office FAX: <b>' . $search_info[0]['telexnumber'][0] . '</b>');
             $this->userfield_update_by_code($local_User, 'officefax', $search_info[0]['telexnumber'][0], 'Phone', 'Office FAX', 'phone');
         }
         // ---- GROUP STUFF ----
         if ($update_mode == true) {
             // Updating existing user
             $this->debug_log('Updating existing user: we do NOT touch the primary group.');
             $local_User->dbupdate();
             $this->debug_log('OK -- User has been updated.');
         } else {
             // Try to assign prilary group from the search results:
             $assigned_group = false;
             if (!empty($l_set['assign_user_to_group_by'])) {
                 $this->debug_log('Plugin is configured to assign the Primary Group by the ' . $l_set['assign_user_to_group_by'] . ' key...');
                 if (isset($search_info[0][$l_set['assign_user_to_group_by']]) && isset($search_info[0][$l_set['assign_user_to_group_by']][0])) {
                     // There is info we want to assign by
                     $assign_by_value = $search_info[0][$l_set['assign_user_to_group_by']][0];
                     $this->debug_log('User info says has ' . $l_set['assign_user_to_group_by'] . ' = "<b>' . $assign_by_value . '</b>"');
                     $GroupCache =& get_Cache('GroupCache');
                     if ($users_Group =& $GroupCache->get_by_name($assign_by_value, false)) {
                         // A group with the users value returned exists.
                         $local_User->set_Group($users_Group);
                         $assigned_group = true;
                         $this->debug_log('Assigning User to existing Primary Group.');
                     } else {
                         $this->debug_log('Group with that name does not exist...');
                         if ($new_Group =& $this->usergroup_create($l_set['tpl_new_grp_ID'], $assign_by_value)) {
                             // Link the user to new created group:
                             $local_User->set_Group($new_Group);
                             $assigned_group = true;
                             $this->debug_log('Assigned User to new Primary Group.');
                         }
                     }
                 }
             }
             if (!$assigned_group) {
                 // Default group:
                 $this->debug_log('Falling back to default primary group...');
                 $users_Group = NULL;
                 $fallback_grp_ID = $this->Settings->get('fallback_grp_ID');
                 if (empty($fallback_grp_ID)) {
                     $this->debug_log('No default/fallback primary group configured.');
                     $this->debug_log('User NOT created, try next LDAP server...');
                     //Continue to next LDAP server:
                     continue;
                 } else {
                     $GroupCache =& get_Cache('GroupCache');
                     $users_Group =& $GroupCache->get_by_ID($fallback_grp_ID);
                     if ($users_Group) {
                         // either $this->default_group_name is not given or wrong
                         $local_User->set_Group($users_Group);
                         $assigned_group = true;
                         $this->debug_log('Using default/fallback primary group: <b>' . $users_Group->get('name') . '</b>');
                     } else {
                         $this->debug_log('Default/fallback primary group does not exist (' . $fallback_grp_ID . ').');
                         $this->debug_log('User NOT created, try next LDAP server...');
                         //Continue to next LDAP server:
                         continue;
                     }
                 }
             }
             $local_User->dbinsert();
             $UserCache->add($local_User);
             $this->debug_log('OK -- User has been created.');
         }
         // Remember this settings number in order use this first in next logging time by current user:
         $this->UserSettings->set('search_set_num', $l_id, $local_User->ID);
         $this->UserSettings->dbupdate();
         // Assign user to organizations:
         $this->userorg_assign_to_user($local_User);
         // jpegphoto -> Save as profile pictue "ldap.jpeg" and associate with user
         if (isset($search_info[0]['jpegphoto'][0])) {
             $this->debug_log('Photo: <img src="data:image/jpeg;base64,' . base64_encode($search_info[0]['jpegphoto'][0]) . '" />');
             // Save to disk and attach to user:
             $this->userimg_attach_photo($local_User, $search_info[0]['jpegphoto'][0], !empty($l_set['expand_pics']));
         }
         // --- EXTRA GROUPS ---
         if (!empty($l_set['secondary_grp_search_filter'])) {
             global $app_version;
             if (evo_version_compare($app_version, '6.7.0-alpha') < 0) {
                 // The plugin is used on b2evo 6.6
                 $this->debug_log('Secondary groups not handled. This feature requires b2evolution v6.7.0-alpha or newer.');
             } elseif (empty($l_set['secondary_grp_name_attribute'])) {
                 $this->debug_log('Missing name attribute for secondary groups');
             } else {
                 $filter = str_replace('%s', $params['login'], $l_set['secondary_grp_search_filter']);
                 $grp_name_attribute = $l_set['secondary_grp_name_attribute'];
                 $this->debug_log(sprintf('Step 4 : Now querying for secondary groups. base_dn: <b>%s</b>, filter: <b>%s</b>, name attribue=<b>%s</b>', $l_set['secondary_grp_base_dn'], $filter, $grp_name_attribute));
                 $search_result = @ldap_search($ldap_conn, $l_set['secondary_grp_base_dn'], $filter, array($grp_name_attribute));
                 if (!$search_result) {
                     // this may happen with an empty base_dn
                     $this->debug_log('Invalid ldap_search result. No secondary groups will be assigned. Errno: ' . ldap_errno($ldap_conn) . ' Error: ' . ldap_error($ldap_conn));
                 } else {
                     $search_info = ldap_get_entries($ldap_conn, $search_result);
                     // $this->debug_log( 'Results returned by LDAP Server: <pre>'.var_export( $search_info, true ).'</pre>' );
                     $secondary_groups = array();
                     // $this->debug_log( 'Secondary groups name prefix: <pre>'.var_export( $l_set['secondary_grp_name_prefix'], true ).'</pre>' );
                     // Walk through results:
                     foreach ($search_info as $group_candidate) {
                         if (is_array($group_candidate) && isset($group_candidate[$grp_name_attribute][0])) {
                             $group_candidate_cn = $group_candidate[$grp_name_attribute][0];
                             if (empty($l_set['secondary_grp_name_prefix']) || strpos($group_candidate_cn, $l_set['secondary_grp_name_prefix']) === 0) {
                                 // prefix is ok
                                 $this->debug_log('Accepted Secondary Group: ' . $group_candidate_cn);
                                 $secondary_groups[] = $group_candidate_cn;
                             } else {
                                 // prefix is NOT ok
                                 $this->debug_log('REJECTED Secondary Group: ' . $group_candidate_cn);
                             }
                         }
                     }
                     // Hardcode two secondary groups:
                     // $secondary_groups = array( 'Blog B members', 'Blog D Members' );
                     $this->debug_log('Secondary groups to be assigned: <pre>' . var_export($secondary_groups, true) . '</pre>');
                     // Update secondary groups for the User:
                     $this->usersecgroup_update($local_User, $secondary_groups, $l_set['tpl_new_secondary_grp_ID']);
                 }
             }
         }
         if (isset($initial_protocol_version)) {
             ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, $initial_protocol_version);
         }
         // --- CONSIDER THE LOGIN ATTEMPT TO BE SUCCESSFUL AND WE ACCEPT IT ---
         // Update this value which has been passed by REFERENCE:
         $params['pass_ok'] = true;
         return true;
         // Login was a success (but return "true" does not trigger anything special in b2evolution)
     }
     if (isset($initial_protocol_version)) {
         ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, $initial_protocol_version);
     }
     return false;
     // Login failed!
 }
 private function add_user()
 {
     if (PersistenceContext::get_querier()->row_exists(DB_TABLE_INTERNAL_AUTHENTICATION, 'WHERE login=:login', array('login' => $this->login))) {
         throw new Exception($this->login . ' login already use');
     } else {
         if (UserService::user_exists('WHERE email=:email', array('email' => $this->email))) {
             throw new Exception($this->email . ' email already use');
         } else {
             $user = new User();
             $user->set_display_name($this->login);
             $user->set_level($this->get_real_value($this->level, $this->level_possible_values));
             $user->set_email($this->email);
             $auth_method = new PHPBoostAuthenticationMethod($this->login, $this->password);
             $auth_method->set_association_parameters($this->get_real_value($this->approbation, $this->approbation_possible_values));
             UserService::create($user, $auth_method);
             CLIOutput::writeln('User added successfull');
         }
     }
 }
Example #20
0
         $loi[] = "Số điện thoại không hợp lê <br />";
     }
 }
 if ($loi != "") {
     echo "<ul>";
     foreach ($loi as $err) {
         echo "<li>{$err}</li>";
     }
     echo "</ul>";
 } else {
     if ($u && $p && $e && $ht && $dc && $dt) {
         $lv = 1;
         $dk = new User();
         $dk->set_user($u);
         $dk->set_pass($p);
         $dk->set_email($e);
         $dk->set_hoten($ht);
         $dk->set_diachi($dc);
         $dk->set_dienthoai($dt);
         $dk->set_level($lv);
         $ngaydk = date("d");
         $thangdk = date("m");
         $namdk = date("Y");
         $ngaydk = "{$namdk}-{$thangdk}-{$ngaydk}";
         $ngaysinh = "{$namsinh}-{$thangsinh}-{$ngaysinh}";
         $dk->set_ngaydangky($ngaydk);
         $dk->set_ngaysinh($ngaysinh);
         if ($dk->check_user() == FALSE) {
             echo "<div align='center' style='margin:10px;'><font size='+1' color='#FF0033'>Tên này đã có người dùng</font></div>";
         }
         if ($dk->check_email() == FALSE) {