예제 #1
0
function send_password_expiration_reminders()
{
    $password_expiration_notification = config_option('password_expiration_notification', 0);
    if ($password_expiration_notification > 0) {
        _log("Sending password expiration reminders...");
        $count = UserPasswords::sendPasswordExpirationReminders();
        _log("{$count} password expiration reminders sent.");
    }
}
예제 #2
0
 /**
  * Validate data before save
  *
  * @access public
  * @param array $errors
  * @return void
  */
 function validate(&$errors)
 {
     // Validate min length for the password
     if (!UserPasswords::validateMinLength($this->password_temp)) {
         $min_pass_length = config_option('min_password_length', 0);
         $errors[] = lang('password invalid min length', $min_pass_length);
     }
     // if
     // Validate password numbers
     if (!UserPasswords::validateNumbers($this->password_temp)) {
         $pass_numbers = config_option('password_numbers', 0);
         $errors[] = lang('password invalid numbers', $pass_numbers);
     }
     // if
     // Validate uppercase characters
     if (!UserPasswords::validateUppercaseCharacters($this->password_temp)) {
         $pass_uppercase = config_option('password_uppercase_characters', 0);
         $errors[] = lang('password invalid uppercase', $pass_uppercase);
     }
     // if
     // Validate metacharacters
     if (!UserPasswords::validateMetacharacters($this->password_temp)) {
         $pass_metacharacters = config_option('password_metacharacters', 0);
         $errors[] = lang('password invalid metacharacters', $pass_metacharacters);
     }
     // if
     // Validate against password history
     if (!UserPasswords::validateAgainstPasswordHistory($this->getUserId(), $this->password_temp)) {
         $errors[] = lang('password exists history');
     }
     // if
     // Validate new password character difference
     if (!UserPasswords::validateCharDifferences($this->getUserId(), $this->password_temp)) {
         $errors[] = lang('password invalid difference');
     }
     // if
 }
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return UserPasswords 
  */
 function manager()
 {
     if (!$this->manager instanceof UserPasswords) {
         $this->manager = UserPasswords::instance();
     }
     return $this->manager;
 }
 /**
  * Send password expiration reminders to users
  *
  * @access public
  * @return int
  */
 static function sendPasswordExpirationReminders()
 {
     $sent = 0;
     $password_expiration_days = config_option('password_expiration', 0);
     $password_expiration_notification = config_option('password_expiration_notification', 0);
     $user_passwords = UserPasswords::getNewestUserPasswords();
     foreach ($user_passwords as $password) {
         $diff_days = self::getUserPasswordDays($password);
         if ($diff_days == $password_expiration_days - $password_expiration_notification) {
             $user = Users::findById($password->getUserId());
             if ($user instanceof User) {
                 if (Notifier::passwordExpiration($user, $password_expiration_notification)) {
                     $sent++;
                 }
             }
         }
     }
     return $sent;
 }
예제 #5
0
 /**
  * Delete this object
  *
  * @param void
  * @return boolean
  */
 function delete()
 {
     if ($this->isAccountOwner()) {
         return false;
     }
     // if
     $this->deleteAvatar();
     //$this->deletePersonalProject();
     MailAccountUsers::deleteByUser($this);
     GroupUsers::clearByUser($this);
     Contacts::updateUserIdOnUserDelete($this->getId());
     ProjectUsers::clearByUser($this);
     ObjectSubscriptions::clearByUser($this);
     ObjectReminders::clearByUser($this);
     EventInvitations::clearByUser($this);
     UserPasswords::clearByUser($this);
     return parent::delete();
 }
예제 #6
0
function create_user($user_data, $permissionsString)
{
    $user = new User();
    $user->setUsername(array_var($user_data, 'username'));
    $user->setDisplayName(array_var($user_data, 'display_name'));
    $user->setEmail(array_var($user_data, 'email'));
    $user->setCompanyId(array_var($user_data, 'company_id'));
    $user->setType(array_var($user_data, 'type'));
    $user->setTimezone(array_var($user_data, 'timezone'));
    if (!logged_user() instanceof User || can_manage_security(logged_user())) {
        $user->setCanEditCompanyData(array_var($user_data, 'can_edit_company_data'));
        $user->setCanManageSecurity(array_var($user_data, 'can_manage_security'));
        $user->setCanManageWorkspaces(array_var($user_data, 'can_manage_workspaces'));
        $user->setCanManageConfiguration(array_var($user_data, 'can_manage_configuration'));
        $user->setCanManageContacts(array_var($user_data, 'can_manage_contacts'));
        $user->setCanManageTemplates(array_var($user_data, 'can_manage_templates'));
        $user->setCanManageReports(array_var($user_data, 'can_manage_reports'));
        $user->setCanManageTime(array_var($user_data, 'can_manage_time'));
        $user->setCanAddMailAccounts(array_var($user_data, 'can_add_mail_accounts'));
        $other_permissions = array();
        Hook::fire('add_user_permissions', $user, $other_permissions);
        foreach ($other_permissions as $k => $v) {
            $user->setColumnValue($k, array_var($user_data, $k));
        }
    }
    if (array_var($user_data, 'password_generator', 'random') == 'random') {
        // Generate random password
        $password = UserPasswords::generateRandomPassword();
    } else {
        // Validate input
        $password = array_var($user_data, 'password');
        if (trim($password) == '') {
            throw new Error(lang('password value required'));
        }
        // if
        if ($password != array_var($user_data, 'password_a')) {
            throw new Error(lang('passwords dont match'));
        }
        // if
    }
    // if
    $user->setPassword($password);
    $user->save();
    $user_password = new UserPassword();
    $user_password->setUserId($user->getId());
    $user_password->setPasswordDate(DateTimeValueLib::now());
    $user_password->setPassword(cp_encrypt($password, $user_password->getPasswordDate()->getTimestamp()));
    $user_password->password_temp = $password;
    $user_password->save();
    if (array_var($user_data, 'autodetect_time_zone', 1) == 1) {
        set_user_config_option('autodetect_time_zone', 1, $user->getId());
    }
    if ($user->getType() == 'admin') {
        if ($user->getCompanyId() != owner_company()->getId() || logged_user() instanceof User && !can_manage_security(logged_user())) {
            // external users can't be admins or logged user has no rights to create admins => set as Normal
            $user->setType('normal');
        } else {
            $user->setAsAdministrator(true);
        }
    }
    /* create contact for this user*/
    if (array_var($user_data, 'create_contact', 1)) {
        // if contact with same email exists take it, else create new
        $contact = Contacts::getByEmail($user->getEmail(), true);
        if (!$contact instanceof Contact) {
            $contact = new Contact();
            $contact->setEmail($user->getEmail());
        } else {
            if ($contact->isTrashed()) {
                $contact->untrash();
            }
        }
        $contact->setFirstname($user->getDisplayName());
        $contact->setUserId($user->getId());
        $contact->setTimezone($user->getTimezone());
        $contact->setCompanyId($user->getCompanyId());
        $contact->save();
    } else {
        $contact_id = array_var($user_data, 'contact_id');
        $contact = Contacts::findById($contact_id);
        if ($contact instanceof Contact) {
            // user created from a contact
            $contact->setUserId($user->getId());
            $contact->save();
        } else {
            // if contact with same email exists use it as user's contact, without changing it
            $contact = Contacts::getByEmail($user->getEmail(), true);
            if ($contact instanceof Contact) {
                $contact->setUserId($user->getId());
                if ($contact->isTrashed()) {
                    $contact->untrash();
                }
                $contact->save();
            }
        }
    }
    $contact = $user->getContact();
    if ($contact instanceof Contact) {
        // update contact data with data entered for this user
        $contact->setCompanyId($user->getCompanyId());
        if ($contact->getEmail() != $user->getEmail()) {
            // make user's email the contact's main email address
            if ($contact->getEmail2() == $user->getEmail()) {
                $contact->setEmail2($contact->getEmail());
            } else {
                if ($contact->getEmail3() == $user->getEmail()) {
                    $contact->setEmail3($contact->getEmail());
                } else {
                    if ($contact->getEmail2() == "") {
                        $contact->setEmail2($contact->getEmail());
                    } else {
                        $contact->setEmail3($contact->getEmail());
                    }
                }
            }
        }
        $contact->setEmail($user->getEmail());
        $contact->save();
    }
    if (!$user->isGuest()) {
        /* create personal project or assing the selected*/
        //if recived a personal project assing this
        //project as personal project for this user
        $new_project = null;
        $personalProjectId = array_var($user_data, 'personal_project', 0);
        $project = Projects::findById($personalProjectId);
        if (!$project instanceof Project) {
            $project = new Project();
            $wname = new_personal_project_name($user->getUsername());
            $project->setName($wname);
            $wdesc = Localization::instance()->lang(lang('personal workspace description'));
            if (!is_null($wdesc)) {
                $project->setDescription($wdesc);
            }
            $project->setCreatedById($user->getId());
            $project->save();
            //Save to set an ID number
            $project->setP1($project->getId());
            //Set ID number to the first project
            $project->save();
            $new_project = $project;
        }
        $user->setPersonalProjectId($project->getId());
        $project_user = new ProjectUser();
        $project_user->setProjectId($project->getId());
        $project_user->setUserId($user->getId());
        $project_user->setCreatedById($user->getId());
        $project_user->setAllPermissions(true);
        $project_user->save();
        /* end personal project */
    }
    $user->save();
    ApplicationLogs::createLog($user, null, ApplicationLogs::ACTION_ADD);
    //TODO - Make batch update of these permissions
    if ($permissionsString && $permissionsString != '') {
        $permissions = json_decode($permissionsString);
    } else {
        $permissions = null;
    }
    if (is_array($permissions) && (!logged_user() instanceof User || can_manage_security(logged_user()))) {
        foreach ($permissions as $perm) {
            if (ProjectUser::hasAnyPermissions($perm->pr, $perm->pc)) {
                if (!$personalProjectId || $personalProjectId != $perm->wsid) {
                    $relation = new ProjectUser();
                    $relation->setProjectId($perm->wsid);
                    $relation->setUserId($user->getId());
                    $relation->setCheckboxPermissions($perm->pc, $user->isGuest() ? false : true);
                    $relation->setRadioPermissions($perm->pr, $user->isGuest() ? false : true);
                    $relation->save();
                }
            }
        }
    }
    // if
    if ($new_project instanceof Project && logged_user() instanceof User && logged_user()->isProjectUser($new_project)) {
        evt_add("workspace added", array("id" => $new_project->getId(), "name" => $new_project->getName(), "color" => $new_project->getColor()));
    }
    // Send notification...
    try {
        if (array_var($user_data, 'send_email_notification')) {
            Notifier::newUserAccount($user, $password);
        }
        // if
    } catch (Exception $e) {
    }
    // try
    return $user;
}
 /**
  * Delete rows that match specific conditions. If $conditions is NULL all rows from table will be deleted
  *
  * @access public
  * @param string $conditions Query conditions
  * @return boolean
  */
 function delete($condition = null)
 {
     if (isset($this) && instance_of($this, 'UserPasswords')) {
         return parent::delete($condition);
     } else {
         return UserPasswords::instance()->delete($condition);
     }
     // if
 }
 /**
  * Show and change password form
  *
  * @param void
  * @return null
  */
 function change_password()
 {
     $user = Users::findById(get_id());
     if (!$user instanceof User) {
         return;
     }
     tpl_assign('user_id', get_id());
     if (array_var($_GET, 'msg') && array_var($_GET, 'msg') == 'expired') {
         $reason = lang('password expired');
     } else {
         $reason = lang('password invalid');
     }
     tpl_assign('reason', $reason);
     if (is_array(array_var($_POST, 'changePassword'))) {
         $changePassword_data = array_var($_POST, 'changePassword');
         $username = array_var($changePassword_data, 'username');
         $old_password = array_var($changePassword_data, 'oldPassword');
         $new_password = array_var($changePassword_data, 'newPassword');
         $repeat_password = array_var($changePassword_data, 'repeatPassword');
         if (trim($username) != $user->getUsername()) {
             tpl_assign('error', new Error(lang('invalid login data')));
             $this->render();
         }
         if (trim($old_password) == '') {
             tpl_assign('error', new Error(lang('old password required')));
             $this->render();
         }
         // if
         if (!$user->isValidPassword($old_password)) {
             tpl_assign('error', new Error(lang('invalid old password')));
             $this->render();
         }
         // if
         if (trim($new_password == '')) {
             tpl_assign('error', new Error(lang('password value missing')));
             $this->render();
         }
         // if
         if ($new_password != $repeat_password) {
             tpl_assign('error', new Error(lang('passwords dont match')));
             $this->render();
         }
         // if
         if (!UserPasswords::validateMinLength($new_password)) {
             $min_pass_length = config_option('min_password_length', 0);
             tpl_assign('error', new Error(lang('password invalid min length', $min_pass_length)));
             $this->render();
         }
         if (!UserPasswords::validateNumbers($new_password)) {
             $pass_numbers = config_option('password_numbers', 0);
             tpl_assign('error', new Error(lang('password invalid numbers', $pass_numbers)));
             $this->render();
         }
         if (!UserPasswords::validateUppercaseCharacters($new_password)) {
             $pass_uppercase = config_option('password_uppercase_characters', 0);
             tpl_assign('error', new Error(lang('password invalid uppercase', $pass_uppercase)));
             $this->render();
         }
         if (!UserPasswords::validateMetacharacters($new_password)) {
             $pass_metacharacters = config_option('password_metacharacters', 0);
             tpl_assign('error', new Error(lang('password invalid metacharacters', $pass_metacharacters)));
             $this->render();
         }
         if (!UserPasswords::validateAgainstPasswordHistory($user->getId(), $new_password)) {
             tpl_assign('error', new Error(lang('password exists history')));
             $this->render();
         }
         if (!UserPasswords::validateCharDifferences($user->getId(), $new_password)) {
             tpl_assign('error', new Error(lang('password invalid difference')));
             $this->render();
         }
         $user_password = new UserPassword();
         $user_password->setPasswordDate(DateTimeValueLib::now());
         $user_password->setUserId($user->getId());
         $user_password->setPassword(cp_encrypt($new_password, $user_password->getPasswordDate()->getTimestamp()));
         $user_password->password_temp = $new_password;
         $user_password->save();
         $user->setPassword($new_password);
         $user->save();
         try {
             CompanyWebsite::instance()->logUserIn($user, $remember);
         } catch (Exception $e) {
             tpl_assign('error', new Error(lang('invalid login data')));
             $this->render();
         }
         // try
         $ref_controller = null;
         $ref_action = null;
         $ref_params = array();
         foreach ($login_data as $k => $v) {
             if (str_starts_with($k, 'ref_')) {
                 $ref_var_name = trim(substr($k, 4, strlen($k)));
                 switch ($ref_var_name) {
                     case 'c':
                         $ref_controller = $v;
                         break;
                     case 'a':
                         $ref_action = $v;
                         break;
                     default:
                         $ref_params[$ref_var_name] = $v;
                 }
                 // switch
             }
             // if
         }
         // if
         if (!count($ref_params)) {
             $ref_params = null;
         }
         if ($ref_controller && $ref_action) {
             $this->redirectTo($ref_controller, $ref_action, $ref_params);
         } else {
             $this->redirectTo('dashboard');
         }
         // if
     }
 }