Make sure you enter your normalized OpenID/i-name credentials here, i.e. with protocol and trailing slash for OpenID (e.g. http://openid.silverstripe.com/).
")); + $fields->push(new TextField("IdentityURL", "OpenID URL/i-name"), "IdentityURL"); + +/* + $fields->push(new PasswordField("ConfirmPassword", "Confirm Password")); + $fields->push(new ImageField("Avatar", "Upload avatar")); + $fields->push(new DropdownField("ForumRank", "User rating", + array("Community Member" => "Community Member", + "Administrator" => "Administrator", + "Moderator" => "Moderator", + "SilverStripe User" => "SilverStripe User", + "SilverStripe Developer" => "SilverStripe Developer", + "Core Development Team" => "Core Development Team", + "Google Summer of Code Hacker" => "Google Summer of Code Hacker", + "Lead Developer" => "Lead Developer") + ) + ); + }*/ + } + + /** + * Can the current user edit the given member? + * + * Only the user itself or an administrator can edit an user account. + * + * @return bool Returns TRUE if this member can be edited, FALSE otherwise + */ + function canEdit() { + if($this->owner->ID == Member::currentUserID()) + return true; + + $member = Member::currentUser(); + if($member) + return $member->isAdmin(); + + return false; + } + + + + + /** + * Factory method for the member validator + * + * @return Member_Validator Returns an instance of a + * {@link Member_Validator} object. + */ + function getValidator() { + die('Called getValidator()
'); + return new Member_Validator(); + } +} + + +?> \ No newline at end of file diff --git a/security/OpenIDAuthenticator.php b/security/OpenIDAuthenticator.php index 1b1d78095..4d5f6b5dc 100644 --- a/security/OpenIDAuthenticator.php +++ b/security/OpenIDAuthenticator.php @@ -39,13 +39,30 @@ require_once "Auth/OpenID/SReg.php"; */ class OpenIDAuthenticator extends Authenticator { + /** + * Callback function that is called when the authenticator is registered + * + * Use this method for initialization of a newly registered authenticator. + * Just overload this method and it will be called when the authenticator + * is registered. + * If the method returns FALSE, the authenticator won't be + * registered! + * + * @return bool Returns TRUE on success, FALSE otherwise. + */ + protected static function onRegister() { + Member::addRole('OpenIDAuthenticatedRole'); + return true; + } + + /** * Method to authenticate an user * * @param array $RAW_data Raw data to authenticate the user - * @param Form $form Optional: If passed, better error messages can be - * produced by using - * {@link Form::sessionMessage()} + * @param Form $form Optional: If passed, better error messages can be + * produced by using + * {@link Form::sessionMessage()} * @return bool Returns FALSE if authentication fails, otherwise the * method will not return at all because the browser will be * redirected to some other server. @@ -54,7 +71,16 @@ class OpenIDAuthenticator extends Authenticator { * (without rendering a form and using javascript) */ public function authenticate(array $RAW_data, Form $form = null) { - $openid = $RAW_data['OpenIDURL']; + $openid = trim($RAW_data['OpenIDURL']); + + if(strlen($openid) == 0) { + if(!is_null($form)) { + $form->sessionMessage("Please enter your OpenID URL or your i-name.", + "bad"); + } + return false; + } + $trust_root = Director::absoluteBaseURL(); $return_to_url = $trust_root . 'OpenIDAuthenticator_Controller'; @@ -74,8 +100,9 @@ class OpenIDAuthenticator extends Authenticator { return false; } - $SQL_user = Convert::raw2sql($auth_request->endpoint->claimed_id); - if(!($member = DataObject::get_one("Member", "Email = '$SQL_user'"))) { + $SQL_identity = Convert::raw2sql($auth_request->endpoint->claimed_id); + if(!($member = DataObject::get_one("Member", + "Member.IdentityURL = '$SQL_identity'"))) { if(!is_null($form)) { $form->sessionMessage("Either your account is not enabled for " . "OpenID/i-name authentication " . @@ -89,10 +116,12 @@ class OpenIDAuthenticator extends Authenticator { if($auth_request->shouldSendRedirect()) { // For OpenID 1, send a redirect. - $redirect_url = $auth_request->redirectURL($trust_root, $return_to_url); + $redirect_url = $auth_request->redirectURL($trust_root, + $return_to_url); if(Auth_OpenID::isFailure($redirect_url)) { - displayError("Could not redirect to server: " . $redirect_url->message); + displayError("Could not redirect to server: " . + $redirect_url->message); } else { Director::redirect($redirect_url); } @@ -102,16 +131,19 @@ class OpenIDAuthenticator extends Authenticator { // server. $form_id = 'openid_message'; $form_html = $auth_request->formMarkup($trust_root, $return_to_url, - false, array('id' => $form_id)); + false, + array('id' => $form_id)); if(Auth_OpenID::isFailure($form_html)) { - displayError("Could not redirect to server: " . $form_html->message); + displayError("Could not redirect to server: " . + $form_html->message); } else { $page_contents = array( "Click "Continue" to login. You are only seeing " . "this because you appear to have JavaScript disabled.
", @@ -129,8 +161,8 @@ class OpenIDAuthenticator extends Authenticator { /** * Method that creates the login form for this authentication method * - * @param Controller The parent controller, necessary to create the - * appropriate form action tag + * @param Controller The parent controller, necessary to create the + * appropriate form action tag * @return Form Returns the login form to use with this authentication * method */ @@ -139,12 +171,12 @@ class OpenIDAuthenticator extends Authenticator { } - /** - * Get the name of the authentication method - * - * @return string Returns the name of the authentication method. - */ - public static function getName() { + /** + * Get the name of the authentication method + * + * @return string Returns the name of the authentication method. + */ + public static function getName() { return "OpenID/i-name"; } } @@ -202,10 +234,9 @@ class OpenIDAuthenticator_Controller extends Controller { } else if($response->status == Auth_OpenID_SUCCESS) { $openid = $response->identity_url; - $user = $openid; if($response->endpoint->canonicalID) { - $user = $response->endpoint->canonicalID; + $openid = $response->endpoint->canonicalID; } @@ -213,10 +244,12 @@ class OpenIDAuthenticator_Controller extends Controller { Profiler::unmark("OpenIDAuthenticator_Controller"); - $SQL_user = Convert::raw2sql($user); - if($member = DataObject::get_one("Member", "Email = '$SQL_user'")) { + $SQL_identity = Convert::raw2sql($openid); + if($member = DataObject::get_one("Member", + "Member.IdentityURL = '$SQL_identity'")) { $firstname = Convert::raw2xml($member->FirstName); - Session::set("Security.Message.message", "Welcome Back, {$firstname}"); + Session::set("Security.Message.message", + "Welcome Back, {$firstname}"); Session::set("Security.Message.type", "good"); $member->LogIn( diff --git a/security/OpenIDLoginForm.php b/security/OpenIDLoginForm.php index 836e4460c..df083a250 100644 --- a/security/OpenIDLoginForm.php +++ b/security/OpenIDLoginForm.php @@ -111,7 +111,9 @@ class OpenIDLoginForm extends LoginForm { if($badLoginURL = Session::get("BadLoginURL")){ Director::redirect($badLoginURL); } else { - Director::redirectBack(); + // Show the right tab on failed login + Director::redirect(Director::absoluteURL(Security::Link("login")) . + '#' . $this->FormName() .'_tab'); } }