diff --git a/password_policy.module b/password_policy.module index 6de50f5..6949c1a 100644 --- a/password_policy.module +++ b/password_policy.module @@ -1544,3 +1544,41 @@ JS; drupal_add_js($data, 'setting'); } } + +function password_policy_entity_property_info_alter(&$entities){ + // Add the force_change field to the user entity (and all bundles) + $entities['user']['properties']['force_change'] = array( + 'label' => t("Force Password Change"), + 'type' => 'integer', + 'getter callback' => 'password_policy_get_value', + 'setter callback' => 'password_policy_set_value', + 'description' => t("Whether or not a user is required to change password on next login."), + ); +} + +/** + * Getter function for helping entity return the value of this field + * @param $user + * @return mixed + */ +function password_policy_get_value(&$user) { + return db_select('password_policy_force_change', 'p') + ->fields('p',array('force_change')) + ->condition('uid', $user->uid) + ->execute() + ->fetchField(); +} + +/** + * Setter function for applying the specified value to this user + * @param $user + * @param $field + * @param $value + * @return \DatabaseStatementInterface + */ +function password_policy_set_value(&$user, $field, $value) { + return db_update('password_policy_force_change') + ->fields(array('force_change' => $value)) + ->condition('uid', $user->uid) + ->execute(); +} \ No newline at end of file