Skip to content

Instantly share code, notes, and snippets.

@bcmiller
Created June 22, 2010 19:41
Show Gist options
  • Save bcmiller/448955 to your computer and use it in GitHub Desktop.
Save bcmiller/448955 to your computer and use it in GitHub Desktop.
diff -u -p -r1.4 force_password_change.module
--- force_password_change.module 3 Feb 2010 02:19:23 -0000 1.4
+++ force_password_change.module 22 Jun 2010 19:36:53 -0000
@@ -5,6 +5,7 @@ function force_password_change_perm()
return array
(
'Administer force password change',
+ 'force password change',
);
}
@@ -33,7 +34,8 @@ function force_password_change_init()
function force_password_change_user($op, &$edit, &$account, $category = NULL)
{
- if($op == 'validate' && $account->force_password_change)
+ global $user;
+ if($op == 'validate' && $user->uid == $account->uid && $account->force_password_change)
{
if($edit['pass'] == '')
{
@@ -58,7 +60,7 @@ function force_password_change_user($op,
}
}
}
- if($op == 'update' && $account->force_password_change)
+ if($op == 'update' && $account->force_password_change && arg(0) . '/' . arg(1) != 'user/reset' )
{
db_query
(
@@ -160,4 +162,36 @@ function force_password_change_settings_
{
drupal_set_message(t('No roles were selected.'));
}
-}
\ No newline at end of file
+}
+
+/**
+ * Implementation of hook_form_alter().
+ *
+ * @param <type> $form
+ * @param <type> $form_state
+ * @param <type> $form_id
+ */
+function force_password_change_form_alter($form, $form_state, $form_id) {
+ if (($form_id == 'user_register' || $form_id == 'user_profile_form') && user_access('force password change')) {
+ if (is_numeric($form['#uid'])) {
+ $account = user_load($form['#uid']);
+ }
+ $form['password'] = array(
+ '#type' => 'fieldset',
+ '#title' => 'Password Settings',
+ );
+ $form['password']['force_password_change'] = array(
+ '#type' => 'checkbox',
+ '#title' => 'Force password change on next login',
+ '#default_value' => $account->force_password_change,
+ );
+ }
+}
+
+/**
+ * Implementation of hook_views_api().
+ * @return <type>
+ */
+function force_password_change_views_api() {
+ return array('api' => 2.0);
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment