First pass at allowing username/password selection upon install. Includes some extra cleanup of the patch. Props dancole. See #10396

git-svn-id: http://svn.automattic.com/wordpress/trunk@13134 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dd32 2010-02-14 03:07:47 +00:00
parent 5871a56009
commit 470f62dd8c
4 changed files with 109 additions and 17 deletions

View File

@ -1 +1 @@
html{background:#f7f7f7;}body{background:#fff;color:#333;font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;margin:2em auto 0 auto;width:700px;padding:1em 2em;-moz-border-radius:11px;-khtml-border-radius:11px;-webkit-border-radius:11px;border-radius:11px;border:1px solid #dfdfdf;}a{color:#2583ad;text-decoration:none;}a:hover{color:#d54e21;}h1{border-bottom:1px solid #dadada;clear:both;color:#666;font:24px Georgia,"Times New Roman",Times,serif;margin:5px 0 0 -4px;padding:0;padding-bottom:7px;}h2{font-size:16px;}p,li{padding-bottom:2px;font-size:12px;line-height:18px;}code{font-size:13px;}ul,ol{padding:5px 5px 5px 22px;}#logo{margin:6px 0 14px 0;border-bottom:none;}.step{margin:20px 0 15px;}.step,th{text-align:left;padding:0;}.submit input,.button,.button-secondary{font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;text-decoration:none;font-size:14px!important;line-height:16px;padding:6px 12px;cursor:pointer;border:1px solid #bbb;color:#464646;-moz-border-radius:15px;-khtml-border-radius:15px;-webkit-border-radius:15px;border-radius:15px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;-khtml-box-sizing:content-box;box-sizing:content-box;}.button:hover,.button-secondary:hover,.submit input:hover{color:#000;border-color:#666;}.button,.submit input,.button-secondary{background:#f2f2f2 url(../images/white-grad.png) repeat-x scroll left top;}.button:active,.submit input:active,.button-secondary:active{background:#eee url(../images/white-grad-active.png) repeat-x scroll left top;}.form-table{border-collapse:collapse;margin-top:1em;width:100%;}.form-table td{margin-bottom:9px;padding:10px;border-bottom:8px solid #fff;font-size:12px;}.form-table th{font-size:13px;text-align:left;padding:16px 10px 10px 10px;border-bottom:8px solid #fff;width:110px;vertical-align:top;}.form-table tr{background:#f3f3f3;}.form-table code{line-height:18px;font-size:18px;}.form-table p{margin:4px 0 0 0;font-size:11px;}.form-table input{line-height:20px;font-size:15px;padding:2px;}#error-page{margin-top:50px;}#error-page p{font-size:12px;line-height:18px;margin:25px 0 20px;}#error-page code{font-family:Consolas,Monaco,Courier,monospace;} html{background:#f7f7f7;}body{background:#fff;color:#333;font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;margin:2em auto 0 auto;width:700px;padding:1em 2em;-moz-border-radius:11px;-khtml-border-radius:11px;-webkit-border-radius:11px;border-radius:11px;border:1px solid #dfdfdf;}a{color:#2583ad;text-decoration:none;}a:hover{color:#d54e21;}h1{border-bottom:1px solid #dadada;clear:both;color:#666;font:24px Georgia,"Times New Roman",Times,serif;margin:5px 0 0 -4px;padding:0;padding-bottom:7px;}h2{font-size:16px;}p,li{padding-bottom:2px;font-size:12px;line-height:18px;}code{font-size:13px;}ul,ol{padding:5px 5px 5px 22px;}#logo{margin:6px 0 14px 0;border-bottom:none;}.step{margin:20px 0 15px;}.step,th{text-align:left;padding:0;}.submit input,.button,.button-secondary{font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;text-decoration:none;font-size:14px!important;line-height:16px;padding:6px 12px;cursor:pointer;border:1px solid #bbb;color:#464646;-moz-border-radius:15px;-khtml-border-radius:15px;-webkit-border-radius:15px;border-radius:15px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;-khtml-box-sizing:content-box;box-sizing:content-box;}.button:hover,.button-secondary:hover,.submit input:hover{color:#000;border-color:#666;}.button,.submit input,.button-secondary{background:#f2f2f2 url(../images/white-grad.png) repeat-x scroll left top;}.button:active,.submit input:active,.button-secondary:active{background:#eee url(../images/white-grad-active.png) repeat-x scroll left top;}.form-table{border-collapse:collapse;margin-top:1em;width:100%;}.form-table td{margin-bottom:9px;padding:10px;border-bottom:8px solid #fff;font-size:12px;}.form-table th{font-size:13px;text-align:left;padding:16px 10px 10px 10px;border-bottom:8px solid #fff;width:110px;vertical-align:top;}.form-table tr{background:#f3f3f3;}.form-table code{line-height:18px;font-size:18px;}.form-table p{margin:4px 0 0 0;font-size:11px;}.form-table input{line-height:20px;font-size:15px;padding:2px;}#error-page{margin-top:50px;}#error-page p{font-size:12px;line-height:18px;margin:25px 0 20px;}#error-page code{font-family:Consolas,Monaco,Courier,monospace;}#pass-strength-result{background-color:#eee;border-color:#ddd!important;border-style:solid;border-width:1px;float:left;margin:12px 5px 5px 1px;padding:5px;text-align:center;width:200px;}#pass-strength-result.bad{background-color:#ffb78c;border-color:#ff853c!important;}#pass-strength-result.good{background-color:#ffec8b;border-color:#fc0!important;}#pass-strength-result.short{background-color:#ffa0a0;border-color:#f04040!important;}#pass-strength-result.strong{background-color:#c3ff88;border-color:#8dff1c!important;}

View File

@ -131,3 +131,35 @@ ul, ol { padding: 5px 5px 5px 22px; }
} }
#error-page code { font-family: Consolas, Monaco, Courier, monospace; } #error-page code { font-family: Consolas, Monaco, Courier, monospace; }
#pass-strength-result {
background-color: #eee;
border-color: #ddd !important;
border-style: solid;
border-width: 1px;
float: left;
margin: 12px 5px 5px 1px;
padding: 5px;
text-align: center;
width: 200px;
}
#pass-strength-result.bad {
background-color: #ffb78c;
border-color: #ff853c !important;
}
#pass-strength-result.good {
background-color: #ffec8b;
border-color: #ffcc00 !important;
}
#pass-strength-result.short {
background-color: #ffa0a0;
border-color: #f04040 !important;
}
#pass-strength-result.strong {
background-color: #c3ff88;
border-color: #8dff1c !important;
}

View File

@ -31,9 +31,10 @@ if ( !function_exists('wp_install') ) :
* @param string $user_email User's email. * @param string $user_email User's email.
* @param bool $public Whether blog is public. * @param bool $public Whether blog is public.
* @param null $deprecated Optional. Not used. * @param null $deprecated Optional. Not used.
* @param string $user_password Optional. User's chosen password. Will default to a random password.
* @return array Array keys 'url', 'user_id', 'password', 'password_message'. * @return array Array keys 'url', 'user_id', 'password', 'password_message'.
*/ */
function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '' ) { function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '' ) {
global $wp_rewrite; global $wp_rewrite;
if ( !empty( $deprecated ) ) if ( !empty( $deprecated ) )
@ -60,13 +61,16 @@ function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated
// Create default user. If the user already exists, the user tables are // Create default user. If the user already exists, the user tables are
// being shared among blogs. Just set the role in that case. // being shared among blogs. Just set the role in that case.
$user_id = username_exists($user_name); $user_id = username_exists($user_name);
if ( !$user_id ) { $user_password = trim($user_password);
$random_password = wp_generate_password(); if ( !$user_id && empty($user_password) ) {
$user_password = wp_generate_password();
$message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.'); $message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.');
$user_id = wp_create_user($user_name, $random_password, $user_email); $user_id = wp_create_user($user_name, $user_password, $user_email);
update_user_option($user_id, 'default_password_nag', true, true); update_user_option($user_id, 'default_password_nag', true);
} else if ( !$user_id ) {
$message = __('<strong><em>Note that password</em></strong> carefully!');
$user_id = wp_create_user($user_name, $user_password, $user_email);
} else { } else {
$random_password = '';
$message = __('User already exists. Password inherited.'); $message = __('User already exists. Password inherited.');
} }
@ -77,11 +81,11 @@ function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated
$wp_rewrite->flush_rules(); $wp_rewrite->flush_rules();
wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password); wp_new_blog_notification($blog_title, $guessurl, $user_id, $user_password);
wp_cache_flush(); wp_cache_flush();
return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password, 'password_message' => $message); return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
} }
endif; endif;

View File

@ -20,6 +20,9 @@ require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
/** Load WordPress Administration Upgrade API */ /** Load WordPress Administration Upgrade API */
require_once( dirname( __FILE__ ) . '/includes/upgrade.php' ); require_once( dirname( __FILE__ ) . '/includes/upgrade.php' );
/** Load wpdb */
require_once(dirname(dirname(__FILE__)) . '/wp-includes/wp-db.php');
$step = isset( $_GET['step'] ) ? $_GET['step'] : 0; $step = isset( $_GET['step'] ) ? $_GET['step'] : 0;
/** /**
@ -53,11 +56,19 @@ function display_header() {
* @subpackage Installer * @subpackage Installer
*/ */
function display_setup_form( $error = null ) { function display_setup_form( $error = null ) {
global $wpdb;
$user_table = ( $wpdb->get_var("SHOW TABLES LIKE '$wpdb->users'") != null ) ? true : false;
// Ensure that Blogs appear in search engines by default // Ensure that Blogs appear in search engines by default
$blog_public = 1; $blog_public = 1;
if ( isset( $_POST ) && ! empty( $_POST ) ) if ( isset( $_POST ) && ! empty( $_POST ) )
$blog_public = isset( $_POST['blog_public'] ); $blog_public = isset( $_POST['blog_public'] );
$weblog_title = isset( $_POST['weblog_title'] ) ? trim( stripslashes( $_POST['weblog_title'] ) ) : '';
$user_name = isset($_POST['user_name']) ? trim( stripslashes( $_POST['user_name'] ) ) : 'admin';
$admin_password = isset($_POST['admin_password']) ? trim( stripslashes( $_POST['admin_password'] ) ) : '';
$admin_email = isset( $_POST['admin_email'] ) ? trim( stripslashes( $_POST['admin_email'] ) ) : '';
if ( ! is_null( $error ) ) { if ( ! is_null( $error ) ) {
?> ?>
<p><?php printf( __( '<strong>ERROR</strong>: %s' ), $error ); ?></p> <p><?php printf( __( '<strong>ERROR</strong>: %s' ), $error ); ?></p>
@ -66,11 +77,33 @@ function display_setup_form( $error = null ) {
<table class="form-table"> <table class="form-table">
<tr> <tr>
<th scope="row"><label for="weblog_title"><?php _e( 'Blog Title' ); ?></label></th> <th scope="row"><label for="weblog_title"><?php _e( 'Blog Title' ); ?></label></th>
<td><input name="weblog_title" type="text" id="weblog_title" size="25" value="<?php echo ( isset( $_POST['weblog_title'] ) ? esc_attr( $_POST['weblog_title'] ) : '' ); ?>" /></td> <td><input name="weblog_title" type="text" id="weblog_title" size="25" value="<?php echo esc_attr( $weblog_title ); ?>" /></td>
</tr> </tr>
<tr>
<th scope="row"><label for="user_name"><?php _e('User Name'); ?></label></th>
<td>
<?php
if ( $user_table ) {
_e('User(s) already exists.');
} else {
?><input name="user_name" type="text" id="user_login" size="25" value="<?php echo esc_attr( $user_name ); ?>" /><?php
} ?>
</td>
</tr>
<?php if ( ! $user_table ) : ?>
<tr>
<th scope="row"><label for="admin_password"><?php _e('Password'); ?></label></th>
<td>
<input name="admin_password" type="password" id="pass1" size="25" value="<?php echo esc_attr( $admin_password ); ?>" />
<br /><?php _e('A password will be automatically generated for you if you leave this field blank.'); ?>
<br /><div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
<p class="description indicator-hint"><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).'); ?></p>
</td>
</tr>
<?php endif; ?>
<tr> <tr>
<th scope="row"><label for="admin_email"><?php _e( 'Your E-mail' ); ?></label></th> <th scope="row"><label for="admin_email"><?php _e( 'Your E-mail' ); ?></label></th>
<td><input name="admin_email" type="text" id="admin_email" size="25" value="<?php echo ( isset( $_POST['admin_email'] ) ? esc_attr( $_POST['admin_email'] ) : '' ); ?>" /><br /> <td><input name="admin_email" type="text" id="admin_email" size="25" value="<?php echo esc_attr( $admin_email ); ?>" /><br />
<?php _e( 'Double-check your email address before continuing.' ); ?></td> <?php _e( 'Double-check your email address before continuing.' ); ?></td>
</tr> </tr>
<tr> <tr>
@ -125,12 +158,18 @@ switch($step) {
display_header(); display_header();
// Fill in the data we gathered // Fill in the data we gathered
$weblog_title = isset( $_POST['weblog_title'] ) ? stripslashes( $_POST['weblog_title'] ) : ''; $weblog_title = isset( $_POST['weblog_title'] ) ? trim( stripslashes( $_POST['weblog_title'] ) ) : '';
$admin_email = isset( $_POST['admin_email'] ) ? stripslashes( $_POST['admin_email'] ) : ''; $user_name = isset($_POST['user_name']) ? trim( stripslashes( $_POST['user_name'] ) ) : 'admin';
$admin_password = isset($_POST['admin_password']) ? trim( stripslashes( $_POST['admin_password'] ) ) : '';
$admin_email = isset( $_POST['admin_email'] ) ?trim( stripslashes( $_POST['admin_email'] ) ) : '';
$public = isset( $_POST['blog_public'] ) ? (int) $_POST['blog_public'] : 0; $public = isset( $_POST['blog_public'] ) ? (int) $_POST['blog_public'] : 0;
// check e-mail address // check e-mail address
$error = false; $error = false;
if ( empty( $admin_email ) ) { if ( empty( $user_name ) ) {
// TODO: poka-yoke
display_setup_form( __('you must provide a valid user name.') );
$error = true;
} else if ( empty( $admin_email ) ) {
// TODO: poka-yoke // TODO: poka-yoke
display_setup_form( __( 'you must provide an e-mail address.' ) ); display_setup_form( __( 'you must provide an e-mail address.' ) );
$error = true; $error = true;
@ -142,7 +181,7 @@ switch($step) {
if ( $error === false ) { if ( $error === false ) {
$wpdb->show_errors(); $wpdb->show_errors();
$result = wp_install( $weblog_title, 'admin', $admin_email, $public ); $result = wp_install($weblog_title, $user_name, $admin_email, $public, '', $admin_password);
extract( $result, EXTR_SKIP ); extract( $result, EXTR_SKIP );
?> ?>
@ -153,13 +192,13 @@ switch($step) {
<table class="form-table"> <table class="form-table">
<tr> <tr>
<th><?php _e( 'Username' ); ?></th> <th><?php _e( 'Username' ); ?></th>
<td><code>admin</code></td> <td><code><?php echo esc_html($user_name); ?></code></td>
</tr> </tr>
<tr> <tr>
<th><?php _e( 'Password' ); ?></th> <th><?php _e( 'Password' ); ?></th>
<td><?php <td><?php
if ( ! empty( $password ) ) if ( ! empty( $password ) )
echo "<code>$password</code><br />"; echo '<code>'. esc_html($password) .'</code><br />';
echo "<p>$password_message</p>"; ?> echo "<p>$password_message</p>"; ?>
</td> </td>
</tr> </tr>
@ -173,5 +212,22 @@ switch($step) {
} }
?> ?>
<script type="text/javascript">var t = document.getElementById('weblog_title'); if (t){ t.focus(); }</script> <script type="text/javascript">var t = document.getElementById('weblog_title'); if (t){ t.focus(); }</script>
<script type="text/javascript" src="../wp-includes/js/jquery/jquery.js"></script>
<script type="text/javascript" src="js/password-strength-meter.js"></script>
<script type="text/javascript" src="js/user-profile.js"></script>
<script type="text/javascript" src="js/utils.js"></script>
<script type='text/javascript'>
/* <![CDATA[ */
try{convertEntities(commonL10n);}catch(e){};
var pwsL10n = {
empty: "Strength indicator",
short: "Very weak",
bad: "Weak",
good: "Medium",
strong: "Strong"
};
try{convertEntities(pwsL10n);}catch(e){};
/* ]]> */
</script>
</body> </body>
</html> </html>