From cb6963919ccfe5f34cd853b344ba492c462cf890 Mon Sep 17 00:00:00 2001 From: bachy Date: Wed, 13 Feb 2013 20:36:10 +0100 Subject: [PATCH] =?UTF-8?q?give=20defined=20ro=CC=82le=20on=20validate=20e?= =?UTF-8?q?mail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bachy --- materio_user.module | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/materio_user.module b/materio_user.module index 2167d734..0f7adde4 100644 --- a/materio_user.module +++ b/materio_user.module @@ -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()); +} +