public function admincreateusers($user_data)
 {
     // Check that the user is not already on the system
     $users = new LoveUser();
     $userlist = $users->getUserList();
     $newUsers = array();
     $returnUsers = array();
     foreach ($user_data as $user) {
         if (!$this->searchMultiArray($userlist, 'username', $user['username'])) {
             $counter = 1;
             $user_nick = $user['nickname'];
             while ($this->searchMultiArray($userlist, 'nickname', $user['nickname'])) {
                 $user['nickname'] = $user_nick . "+" . (string) $counter;
                 $counter++;
             }
             $newUsers[] = $user;
         } else {
             // Check if the user was removed, and if so, readd him
             foreach ($userlist as $singleUser) {
                 if ($singleUser['username'] == $user['username']) {
                     if ($singleUser['removed'] == 1) {
                         // Unset removed flag
                         $user['removed'] = 0;
                         $user_obj = new LoveUser();
                         $user_obj->loadByUsername($user['username']);
                         $user_obj->setPassword($user['password']);
                         $user_obj->setRemoved(0);
                         $user_obj->save();
                         // And add it to the create list
                         $returnUsers[] = array('uid' => $user_obj->id, 'user_data' => $user);
                     }
                 }
             }
         }
     }
     if (count($newUsers) > 0) {
         return array_merge($returnUsers, $users->insertUsers($newUsers));
     } else {
         return $returnUsers;
     }
 }
 /**
  * Authenticate the user
  *
  * @var Controller_Action
  * @var Username
  * @var Password
  * @return if success user's object otherwise NULL.
  */
 public function authenticate(Controller_Action $controller, $username, $password)
 {
     $user = NULL;
     if (!$this->ldapConnect()) {
         $controller->setError('Could not connect to the LDAP Server.');
         return $user;
     }
     //If the login id is not the COMMON_NAME_ATTRIBUTE, find the value to bind
     if (defined('LDAP_ALT_LOGIN_ATTRIBUTE') && LDAP_ALT_LOGIN_ATTRIBUTE !== false) {
         $ldap_commonName = $this->getLdapCommonName(LDAP_ALT_LOGIN_ATTRIBUTE . '=' . $username);
     } else {
         $ldap_commonName = $username;
     }
     $ldap_username = $this->getLdapUsername($ldap_commonName);
     error_log("Ldap: {$ldap_commonName} : {$ldap_username}");
     $login_status = $this->ldapBind($ldap_username, $password);
     if ($login_status) {
         //             if ($sr=ldap_read($this->ldap_connection, LDAP_USER_DN,"(objectclass=*)",array('samaccountname'))) {
         //		error_log("LdapDump: ".json_encode(ldap_get_entries($this->ldap_connection,$sr)));
         //	     }
         $ldapEmail = $this->getLdapEmail(LDAP_COMMON_NAME_ATTRIBUTE . "=" . $ldap_commonName);
         if ($this->user->loadByUsername($ldapEmail)) {
             if ($this->user->isActive()) {
                 $user = $this->user;
             } else {
                 $controller->setError("User is deactivated.");
             }
         } else {
             //Ldap users are already authenticated. If they don't exist yet, take care of it.
             $user = new LoveUser();
             $data = array("Username" => $ldapEmail, "Password" => 'LDAP', "Nickname" => array_shift(split('@', $ldapEmail)), "Active" => 1, "Confirmed" => 1, "Removed" => 0, "Admin" => 0, "Token" => '', "DateAdded" => 0, "DateModified" => 0);
             $user->loadData($data);
             try {
                 $id = $user->save();
                 $result = $id;
             } catch (Exception $e) {
                 $controller->setError($e->getMessage());
             }
         }
     } else {
         $controller->setError("Invalid login");
     }
     $this->ldapClose();
     return $user;
 }
Esempio n. 3
0
 /**
  * Change password controller function
  *
  * Changes the password
  *
  * @return json|xml True on success otherwise false
  */
 public function changepassword()
 {
     try {
         $error_flag = false;
         $message = '';
         $user = new LoveUser();
         if ($user->loadByUsername($_REQUEST['username'])) {
             if ($user->getToken() == $_REQUEST['token']) {
                 $user->setPassword($_REQUEST['password']);
                 $user->setToken(md5(uniqid()));
                 $user->save();
                 echo json_encode(array('success' => true, 'message' => 'Password changed.'));
                 exit(0);
             }
             echo json_encode(array('success' => false, 'message' => 'Token not correct.'));
             exit(0);
         } else {
             echo json_encode(array('success' => false, 'message' => 'User not found.'));
             exit(0);
         }
     } catch (Exception $e) {
         $msg = 'An error occured while updating:' . "\n";
         $msg .= "\n" . ' ' . $e->getMessage();
         if (defined('APPLICATION_ENV') && APPLICATION_ENV == 'development') {
             $msg .= "\n\nFile: " . $e->getFile();
             $msg .= "\nLine: " . $e->getLine();
             $msg .= "\n" . $e->getTraceAsString();
         } else {
             if (defined('APPLICATION_ENV') && APPLICATION_ENV == 'testing') {
                 $msg .= "<br /><br />File: " . $e->getFile();
                 $msg .= "<br />Line: " . $e->getLine();
                 $msg .= "<br />" . $e->getTraceAsString();
             }
         }
         echo $msg;
         exit;
     }
 }