|
From: Greg M. <bli...@us...> - 2008-02-09 22:19:32
|
Update of /cvsroot/phpwebsite-comm/modules/openid/class In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6536/class Modified Files: OpenID_Admin.php OpenID_MyPage.php OpenID_User.php Log Message: More work completed on OpenID mapping and new user signup. Index: OpenID_Admin.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/openid/class/OpenID_Admin.php,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** OpenID_Admin.php 4 Feb 2008 04:54:31 -0000 1.1.1.1 --- OpenID_Admin.php 9 Feb 2008 22:19:05 -0000 1.2 *************** *** 97,100 **** --- 97,107 ---- PHPWS_Settings::set('openid', 'allow_openid', (int)isset($_POST['allow_openid'])); + if (PHPWS_Settings::get('openid', 'no_password_md5') == 0) + { + /* Generate random MD5 to use as password for accounts created by OpenID. + * Only do this once so all accounts with no real password have same MD5. */ + PHPWS_Settings::set('openid', 'no_password_md5', md5(rand())); + } + if (isset($_POST['delegate'])) { Index: OpenID_User.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/openid/class/OpenID_User.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OpenID_User.php 6 Feb 2008 04:40:24 -0000 1.2 --- OpenID_User.php 9 Feb 2008 22:19:05 -0000 1.3 *************** *** 44,51 **** case 'completeLogin': ! $tags['TITLE'] = dgettext('openid', 'First Log In'); $tags['CONTENT'] = OpenID_User::completeLogin(); break; case 'removeMapping': OpenID_User::removeMapping(); --- 44,56 ---- case 'completeLogin': ! $tags['TITLE'] = dgettext('openid', 'New Account Sign-up'); $tags['CONTENT'] = OpenID_User::completeLogin(); break; + case 'createUser': + $tags['TITLE'] = dgettext('openid', 'New Account Sign-up'); + $tags['CONTENT'] = OpenID_User::createUser(); + break; + case 'removeMapping': OpenID_User::removeMapping(); *************** *** 198,206 **** if (!empty($result)) { ! // Log in user ! $user = new PHPWS_User($result); ! $user->login(); ! $_SESSION['User'] = $user; ! PHPWS_Core::returnToBookmark(); } else if (Current_User::isLogged()) --- 203,220 ---- if (!empty($result)) { ! if (!Current_User::isLogged()) ! { ! // Log in user ! $user = new PHPWS_User($result[0]); ! if ($user->approved && $user->active) ! { ! $user->login(); ! $_SESSION['User'] = $user; ! PHPWS_Core::returnToBookmark(); ! } ! ! $_SESSION['openid_message'] = dgettext('openid', 'User account for this site is not active.'); ! } ! OpenID_ReturnToBookmark(); } else if (Current_User::isLogged()) *************** *** 240,251 **** } ! function createUserForm($session_key, $email, $nickname, $fullname) { ! return 'TODO'; } function removeMapping() { ! // TODO OpenID_ReturnToBookmark(); --- 254,352 ---- } ! function createUserForm($session_key, $email, $nickname, $fullname, $error=NULL) { ! $form = new PHPWS_Form; ! $form->addHidden('module', 'openid'); ! $form->addHidden('user', 'createUser'); ! $form->addHidden('session_key', $session_key); ! ! $form->addText('username', $nickname); ! $form->setLabel('username', dgettext('openid', 'Username')); ! $form->setSize('username', 30, 30); ! ! $form->addText('displayname', $fullname); ! $form->setLabel('displayname', dgettext('openid', 'Display Name')); ! $form->setSize('displayname', 30, 30); ! ! $form->addText('email', $email); ! $form->setLabel('email', dgettext('openid', 'Email Address')); ! $form->setSize('email', 50, 100); ! ! $form->addSubmit('submit', dgettext('openid', 'Finish')); ! ! $tags = $form->getTemplate(); ! $tags['INSTRUCTIONS'] = dgettext('openid', ! 'Verify your account information then click finish to complete registration.'); ! $tags['OPENID_LABEL'] = dgettext('openid', 'OpenID'); ! $tags['OPENID'] = $_SESSION['openid_identifier'][$session_key]; ! ! if (is_array($error)) ! { ! $tags = array_merge($tags, $error); ! } ! ! return PHPWS_Template::process($tags, 'openid', 'createuser.tpl'); ! } ! ! function createUser() ! { ! PHPWS_Core::initModClass('users', 'Action.php'); ! $user = new PHPWS_User; ! ! if (PEAR::isError($user->setUsername($_POST['username'])) || !User_Action::testForbidden($user)) ! { ! $error['USERNAME_ERROR'] = dgettext('openid', 'Please try another user name.'); ! } ! ! if (PEAR::isError($user->setDisplayName($_POST['displayname']))) ! { ! $error['DISPLAYNAME_ERROR'] = dgettext('openid', 'Please try another display name.'); ! } ! ! if (empty($_POST['email'])) ! { ! $error['EMAIL_ERROR'] = dgettext('openid', 'Missing an email address.'); ! } ! else if (PEAR::isError($user->setEmail($_POST['email']))) ! { ! $error['EMAIL_ERROR'] = dgettext('openid', 'This email address cannot be used.'); ! } ! ! if (is_array($error)) ! { ! $content = OpenID_User::createUserForm($_POST['session_key'], $_POST['email'], ! $_POST['username'], $_POST['displayname'], $error); ! } ! else ! { ! $user->setPassword(PHPWS_Settings::get('openid', 'no_password_md5'), false); ! $content = User_Action::successfulSignup($user); ! ! if ($user->id > 0) ! { ! /* Need to set password again to no_password_md5 password. The call to ! * successfulSignup above will call md5() on the password before saving. */ ! $user->setPassword(PHPWS_Settings::get('openid', 'no_password_md5'), false); ! $user->saveLocalAuthorization(); ! ! $db = new PHPWS_DB('openid_mapping'); ! $values['user_id'] = $user->id; ! $values['openid_identifier'] = $_SESSION['openid_identifier'][$_POST['session_key']]; ! $db->addValue($values); ! $db->insert(); ! ! unset($_SESSION['openid_identifier'][$_POST['session_key']]); ! } ! } ! ! return $content; } function removeMapping() { ! $db = new PHPWS_DB('openid_mapping'); ! $db->addWhere('user_id', Current_User::getId()); ! $db->addWhere('id', $_REQUEST['mapping_id']); ! PHPWS_Error::logIfError($db->count()); OpenID_ReturnToBookmark(); Index: OpenID_MyPage.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/openid/class/OpenID_MyPage.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OpenID_MyPage.php 6 Feb 2008 04:40:24 -0000 1.1 --- OpenID_MyPage.php 9 Feb 2008 22:19:05 -0000 1.2 *************** *** 71,77 **** { static $num_openid = 0; $template['OPENID_IDENTIFIER'] = $row['openid_identifier']; ! $template['ACTION'] = NULL; if ($num_openid == 0) --- 71,78 ---- { static $num_openid = 0; + static $no_password = -1; $template['OPENID_IDENTIFIER'] = $row['openid_identifier']; ! $template['ACTION'] = ''; if ($num_openid == 0) *************** *** 86,90 **** } ! if (($num_openid > 1) /* || TODO: password set */) { $vars['user'] = 'removeMapping'; --- 87,104 ---- } ! if ($no_password == -1) ! { ! $db_user = new PHPWS_DB('user_authorization'); ! $db_user->addWhere('username', Current_User::getUsername()); ! $db_user->addWhere('password', PHPWS_Settings::get('openid', 'no_password_md5')); ! $result = $db_user->count(); ! if (!PHPWS_Error::logIfError($result)) ! { ! $no_password = $result; ! } ! } ! ! /* Only allow user to remove OpenID if this isn't the last OpenID and no password is set. */ ! if (($num_openid > 1) || ($no_password == 0)) { $vars['user'] = 'removeMapping'; |