diff options
author | cash <cash.costello@gmail.com> | 2011-12-17 17:16:38 -0500 |
---|---|---|
committer | cash <cash.costello@gmail.com> | 2011-12-17 17:16:38 -0500 |
commit | aa9ed6f3eb46fb9508692d1b5d92c717c3648527 (patch) | |
tree | c5078f952b2ff8c362f3ab07e6208fcc2243e59f | |
parent | de76ce685a8bb37a4fc7daa621b496a3bbae3878 (diff) | |
download | elgg-aa9ed6f3eb46fb9508692d1b5d92c717c3648527.tar.gz elgg-aa9ed6f3eb46fb9508692d1b5d92c717c3648527.tar.bz2 |
added warnings for email/usernames
-rw-r--r-- | languages/en.php | 6 | ||||
-rw-r--r-- | lib/helpers.php | 54 | ||||
-rw-r--r-- | views/default/forms/openid_client/register.php | 20 | ||||
-rw-r--r-- | views/default/openid_client/register.php | 4 |
4 files changed, 79 insertions, 5 deletions
diff --git a/languages/en.php b/languages/en.php index d68517b01..4efb59463 100644 --- a/languages/en.php +++ b/languages/en.php @@ -13,9 +13,15 @@ $english = array( 'openid_client:provider:blogger' => 'Blogger',
'openid_client:provider:wordpress' => 'Wordpress',
+ 'openid_client:create' => 'Create an account',
+ 'openid_client:create:instructs' => 'Your account has been approved. We just need you to confirm or set the below information.',
+
'openid_client:success:register' => 'Your account has been created.',
'openid_client:error:bad_register' => 'Unable to create an account. Please contact a site administrator.',
'openid_client:error:bad_response' => 'Bad response from the OpenID server',
+ 'openid_client:warning:username_not_available' => 'The username %s is not available. Please pick another.',
+ 'openid_client:warning:username_valid' => 'The username %s is not valid as this site. Please pick another.',
+ 'openid_client:warning:email_not_available' => 'The email address %s is not available. Please pick another.',
);
add_translation('en', $english);
diff --git a/lib/helpers.php b/lib/helpers.php index 765fc0a61..3fc101c42 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -17,12 +17,16 @@ function openid_client_registration_page_handler(array $data) { return false; } - $title = 'register'; + $title = elgg_echo('openid_client:create'); $vars = openid_client_prepare_registration_vars($data); $content = elgg_view('openid_client/register', $vars); - $body = elgg_view_layout('one_column', array('content' => $content)); + $params = array( + 'title' => $title, + 'content' => $content, + ); + $body = elgg_view_layout('one_column', $params); echo elgg_view_page($title, $body); return true; @@ -49,7 +53,9 @@ function openid_client_prepare_registration_vars(array $data) { } // is the username available - $vars['is_username_available'] = true; + if ($vars['username']) { + $vars['is_username_available'] = openid_client_is_username_available($vars['username']); + } // is the username valid try { @@ -62,5 +68,47 @@ function openid_client_prepare_registration_vars(array $data) { $vars['email'] = elgg_extract('email', $data); $vars['name'] = elgg_extract('name', $data); + if ($vars['email']) { + $vars['is_email_available'] = openid_client_is_email_available($vars['email']); + } + return $vars; } + +/** + * Is this username available? + * + * @param string $username The username + * @return bool + */ +function openid_client_is_username_available($username) { + $db_prefix = elgg_get_config('dbprefix'); + $username = sanitize_string($username); + + $query = "SELECT count(*) AS total FROM {$db_prefix}users_entity WHERE username = '$username'"; + $result = get_data_row($query); + if ($result->total == 0) { + return true; + } else { + return false; + } +} + +/** + * Is this email address available? + * + * @param string $email Email address + * @return bool + */ +function openid_client_is_email_available($email) { + $db_prefix = elgg_get_config('dbprefix'); + $email = sanitize_string($email); + + $query = "SELECT count(*) AS total FROM {$db_prefix}users_entity WHERE email = '$email'"; + $result = get_data_row($query); + if ($result->total == 0) { + return true; + } else { + return false; + } +} diff --git a/views/default/forms/openid_client/register.php b/views/default/forms/openid_client/register.php index 63d5ba04e..279d298c4 100644 --- a/views/default/forms/openid_client/register.php +++ b/views/default/forms/openid_client/register.php @@ -7,10 +7,19 @@ * @uses $vars['is_username_available'] * @uses $vars['is_username_valid'] * @uses $vars['email'] + * @uses $vars['is_email_available'] * @uses $vars['name'] */ $username_label = elgg_echo('username'); +$username_warning = ''; +if (!elgg_extract('is_username_available', $vars, true)) { + $username_warning = elgg_echo('openid_client:warning:username_not_available', array($vars['username'])); + $username_warning = "($username_warning)"; +} else if (!elgg_extract('is_username_valid', $vars, true)) { + $username_warning = elgg_echo('openid_client:warning:username_valid', array($vars['username'])); + $username_warning = "($username_warning)"; +} $username_input = elgg_view('input/text', array( 'name' => 'username', 'value' => $vars['username'], @@ -23,9 +32,16 @@ $name_input = elgg_view('input/text', array( )); $email_label = elgg_echo('email'); +$email_available = elgg_extract('is_email_available', $vars, true); +$email_warning = ''; +if (!$email_available) { + $email_warning = elgg_echo('openid_client:warning:email_not_available', array($vars['email'])); + $email_warning = "($email_warning)"; +} $email_input = elgg_view('input/email', array( 'name' => 'email', 'value' => $vars['email'], + 'disabled' => !$email_available, )); $openid_input = elgg_view('input/hidden', array( @@ -36,7 +52,7 @@ $button = elgg_view('input/submit', array('value' => elgg_echo('save'))); echo <<<HTML <div> - <label>$username_label</label> + <label>$username_label</label> $username_warning $username_input </div> <div> @@ -44,7 +60,7 @@ echo <<<HTML $name_input </div> <div> - <label>$email_label</label> + <label>$email_label</label> $email_warning $email_input </div> <div class="elgg-foot"> diff --git a/views/default/openid_client/register.php b/views/default/openid_client/register.php index 0c3770ed2..be448ef54 100644 --- a/views/default/openid_client/register.php +++ b/views/default/openid_client/register.php @@ -4,4 +4,8 @@ * */ +echo '<p>'; +echo elgg_echo('openid_client:create:instructs'); +echo '<p>'; + echo elgg_view_form('openid_client/register', array(), $vars); |