Skip to content

Commit

Permalink
Better validation Closes woocommerce#3059.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed May 1, 2013
1 parent ade1fd1 commit 2ed2be5
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions woocommerce-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,20 +657,21 @@ function woocommerce_process_login() {

$woocommerce->verify_nonce( 'login' );

if ( empty( $_POST['username'] ) ) $woocommerce->add_error( __( 'Username is required.', 'woocommerce' ) );
if ( empty( $_POST['password'] ) ) $woocommerce->add_error( __( 'Password is required.', 'woocommerce' ) );

if ( $woocommerce->error_count() == 0 ) {

try {
$creds = array();

if ( empty( $_POST['username'] ) )
throw new Exception( '<strong>' . __( 'Error', 'woocommerce' ) . ':</strong> ' . __( 'Username is required.', 'woocommerce' ) );
if ( empty( $_POST['password'] ) )
throw new Exception( '<strong>' . __( 'Error', 'woocommerce' ) . ':</strong> ' . __( 'Password is required.', 'woocommerce' ) );

if ( is_email( $_POST['username'] ) ) {
$user = get_user_by( 'email', $_POST['username'] );

if ( isset( $user->user_login ) )
$creds['user_login'] = $user->user_login;
else
$creds['user_login'] = '';
throw new Exception( '<strong>' . __( 'Error', 'woocommerce' ) . ':</strong> ' . __( 'A user could not be found with this email address.', 'woocommerce' ) );
} else {
$creds['user_login'] = $_POST['username'];
}
Expand All @@ -681,7 +682,7 @@ function woocommerce_process_login() {
$user = wp_signon( $creds, $secure_cookie );

if ( is_wp_error( $user ) ) {
$woocommerce->add_error( $user->get_error_message() );
throw new Exception( $user->get_error_message() );
} else {

if ( ! empty( $_POST['redirect'] ) ) {
Expand All @@ -694,8 +695,9 @@ function woocommerce_process_login() {

wp_redirect( apply_filters( 'woocommerce_login_redirect', $redirect, $user ) );
exit;

}
} catch (Exception $e) {
$woocommerce->add_error( $e->getMessage() );
}
}
}
Expand Down

0 comments on commit 2ed2be5

Please sign in to comment.