|
@@ -215,3 +215,37 @@ function materio_user_block_view_alter(&$data, $block) {
|
|
|
}
|
|
|
|
|
|
|
|
|
+/**
|
|
|
+ * Define constants
|
|
|
+ */
|
|
|
+define('MATERIO_USER_CONFIRMED_USER_ROLE', 'Utilisateur'); // add role name here
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implement hook_user
|
|
|
+ */
|
|
|
+function materio_user_user_update(&$edit, $account, $category){
|
|
|
+ // This is only fired when a user confirms their email address, logintoboggan style
|
|
|
+ if (isset($account->logintoboggan_email_validated) && $account->logintoboggan_email_validated == TRUE) {
|
|
|
+ $confirmed_rid = materio_user_get_role_by_name(MATERIO_USER_CONFIRMED_USER_ROLE);
|
|
|
+ $roles = $account->roles + array($confirmed_rid => MATERIO_USER_CONFIRMED_USER_ROLE);
|
|
|
+
|
|
|
+ // we have to do this to stop an infinite loop, and also to allow lower weighted modules to possibly do something here
|
|
|
+ $user = $account;
|
|
|
+ unset($user->logintoboggan_email_validated);
|
|
|
+
|
|
|
+ user_save($user, array('roles' => $roles));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Returns a role ID based on role name
|
|
|
+ *
|
|
|
+ * @param $name
|
|
|
+ * name of role to return
|
|
|
+ * @return
|
|
|
+ * (int) Role ID
|
|
|
+ */
|
|
|
+function materio_user_get_role_by_name($name) {
|
|
|
+ return array_search($name, user_roles());
|
|
|
+}
|
|
|
+
|