r113625 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113624‎ | r113625 | r113626 >
Date:15:29, 12 March 2012
Author:akshay
Status:deferred
Tags:
Comment:
Fixed Bug 31664
Added a 'signupapi-invalidusername' message
Removed blank username checking from server-side to client-side
Removed 'console.log' from verification.js which was left out during testing
Formatted includes/verification.js for some coding conventions
Modified paths:
  • /trunk/extensions/SignupAPI/SignupAPI.i18n.php (modified) (history)
  • /trunk/extensions/SignupAPI/includes/ApiValidateSignup.php (modified) (history)
  • /trunk/extensions/SignupAPI/includes/verification.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SignupAPI/SignupAPI.i18n.php
@@ -22,6 +22,7 @@
2323 'signupapi-badretype' => 'The passwords you entered do not match',
2424 'signupapi-passwordsmatch' => 'Passwords match',
2525 'signupapi-invalidemailaddress' => 'E-mail address is invalid',
 26+ 'signupapi-invalidusername' => 'Username entered is invalid',
2627 );
2728
2829 /** Message documentation (Message documentation)
Index: trunk/extensions/SignupAPI/includes/ApiValidateSignup.php
@@ -23,15 +23,18 @@
2424
2525 switch ( $params['field'] ) {
2626 case "username":
27 - $mUser = User::newFromName( $params['inputVal'], 'creatable' );
28 - if ( !is_object( $mUser ) ) {
 27+ if( $params['inputVal'] == '' ) {
 28+ # Username left blank
2929 $result['result'] = wfMsg( 'signupapi-noname' );
30 - $result['icon'] = 'MW-Icon-AlertMark.png';
31 - }
32 -
33 - if ( 0 != $mUser->idForName() ) {
 30+ $result['icon'] = "MW-Icon-AlertMark.png";
 31+ } else if ( !is_null( User::idFromName( $params['inputVal'] ) ) ) {
 32+ # User Exists
3433 $result['result'] = wfMsg( 'signupapi-userexists' );
3534 $result['icon'] = "MW-Icon-NoMark.png";
 35+ } else if( !User::isValidUserName( $params['inputval'] ) ) {
 36+ # Illegal name
 37+ $result['result'] = wfMsg( 'signupapi-invalidusername' );
 38+ $result['icon'] = "MW-Icon-NoMark.png";
3639 } else {
3740 $result['result'] = wfMsg( 'signupapi-ok' );
3841 $result['icon'] = "MW-Icon-CheckMark.png";
Index: trunk/extensions/SignupAPI/includes/verification.js
@@ -2,77 +2,87 @@
33
44 jQuery( document ).ready( function( $ ) {
55
6 - function validateInput( fieldtype,fieldid ) {
7 - var inputVal = document.getElementById(fieldid).value;
8 - var valresult = document.getElementById(fieldid+'val');
 6+ function validateInput( fieldtype, fieldid ) {
 7+ var inputVal = document.getElementById( fieldid ).value;
 8+ var valresult = document.getElementById( fieldid + 'val' );
99 $.ajax({
1010 type: "POST",
1111 url: mw.util.wikiScript('api'),
12 - data: {'action':'validatesignup', 'format':'json', 'field':fieldtype, 'inputVal':inputVal },
 12+ data: { 'action':'validatesignup', 'format':'json', 'field':fieldtype, 'inputVal':inputVal },
1313 dataType: 'json',
1414 success: function( jsondata ){
1515 var image = "<img src='"+ imagePath + jsondata.signup.icon +"'>";
1616 var message = jsondata.signup.result;
17 - valresult.innerHTML = image+message;
 17+ valresult.innerHTML = image + message;
1818 }
1919 });
2020 }
2121
2222 function passwordStrength() {
23 - var strength = document.getElementById('wpPassword2val');
24 - var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
25 - var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
26 - var enoughRegex = new RegExp("(?=.{6,}).*", "g");
27 - var pwd = document.getElementById("wpPassword2");
 23+ var strength = document.getElementById( 'wpPassword2val' );
 24+ var strongRegex = new RegExp( "^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g" );
 25+ var mediumRegex = new RegExp( "^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g" );
 26+ var enoughRegex = new RegExp( "(?=.{6,}).*", "g" );
 27+ var pwd = document.getElementById( "wpPassword2" );
2828
2929 if (pwd.value.length==0) {
3030 strength.innerHTML = mw.message( 'signupapi-enterpassword' );
31 - } else if (pwd.value.length<minlength) {
 31+ } else if ( pwd.value.length<minlength ) {
3232 strength.innerHTML = mw.message( 'signupapi-passwordtooshort', minlength );
3333 $("#progress").progressbar({value: 10});
34 - $("div.ui-progressbar-value").css("background","red");
35 - } else if (strongRegex.test(pwd.value)) {
 34+ $("div.ui-progressbar-value").css( "background", "red" );
 35+ } else if ( strongRegex.test(pwd.value) ) {
3636 strength.innerHTML = '<span style="color:green">'+mw.message( 'signupapi-strong' )+'</span>';
3737 $("#progress").progressbar({value: 100});
38 - $("div.ui-progressbar-value").css("background","green");
39 - } else if (mediumRegex.test(pwd.value)) {
 38+ $("div.ui-progressbar-value").css( "background", "green" );
 39+ } else if ( mediumRegex.test(pwd.value) ) {
4040 strength.innerHTML = '<span style="color:orange">'+mw.message( 'signupapi-medium' )+'</span>';
4141 $("#progress").progressbar({value: 60});
42 - $("div.ui-progressbar-value").css("background","orange");
 42+ $("div.ui-progressbar-value").css( "background", "orange" );
4343 } else {
4444 strength.innerHTML = '<span style="color:red">'+mw.message( 'signupapi-weak' )+'</span>';
4545 $("#progress").progressbar({value: 30});
46 - $("div.ui-progressbar-value").css("background","red");
 46+ $("div.ui-progressbar-value").css( "background", "red");
4747 }
4848 }
4949
50 - function checkRetype( pass,retype ) {
51 - var valresult = document.getElementById('wpRetypeval');
 50+ function checkRetype( pass, retype ) {
 51+ var valresult = document.getElementById( 'wpRetypeval' );
5252 var image = "";
5353 var message = "";
54 - if ( pass==retype ) {
 54+ if ( pass == retype ) {
5555 image = "<img src='"+ imagePath +"MW-Icon-CheckMark.png'>";
5656 message = mw.message( 'signupapi-passwordsmatch' );
57 - }else {
 57+ } else {
5858 image = "<img src='"+ imagePath +"MW-Icon-NoMark.png'>";
5959 message = mw.message( 'signupapi-badretype' );
6060 }
6161 valresult.innerHTML = image+message;
6262 }
 63+
 64+ function checkUsername( fieldid ) {
 65+ var inputVal = document.getElementById( fieldid ).value;
 66+ var valresult = document.getElementById( fieldid + 'val' );
 67+ if( inputVal == '' ) {
 68+ var image = "<img src='"+ imagePath + "MW-Icon-AlertMark.png'>";
 69+ var message = mw.message( 'signupapi-noname' );
 70+ valresult.innerHTML = image + message;
 71+ }
 72+ }
6373
64 - $('#wpName2').change(function() {validateInput("username","wpName2");});
65 - $('#wpPassword2').keyup(function() {passwordStrength();});
66 - $('#wpRetype').change(function() {checkRetype(document.getElementById("wpPassword2").value,document.getElementById("wpRetype").value);});
67 - $('#wpEmail').change(function() {validateInput( "email","wpEmail" );});
 74+ $('#wpName2').blur( function() {checkUsername( "wpName2" );} );
 75+ $('#wpName2').change( function() {validateInput( "username", "wpName2" );} );
 76+ $('#wpPassword2').keyup( function() {passwordStrength();} );
 77+ $('#wpRetype').change( function() {checkRetype(document.getElementById( "wpPassword2" ).value,document.getElementById( "wpRetype" ).value);} );
 78+ $('#wpEmail').change( function() {validateInput( "email","wpEmail" );} );
6879
69 - $('#wpName2').after('<span id="wpName2val" class="wpName2val"></span>');
70 - $('#wpPassword2').after('<span id="wpPassword2val"></span><div id="progress" class="progress" style="width:30%; float: right;"></div>');
71 - $('#wpRetype').after('<span id="wpRetypeval" class="wpRetypeval"></span>');
72 - $('#wpEmail').after('<span id="wpEmailval" class="wpEmailval"></span>');
 80+ $('#wpName2').after( '<span id="wpName2val" class="wpName2val"></span>' );
 81+ $('#wpPassword2').after( '<span id="wpPassword2val"></span><div id="progress" class="progress" style="width:30%; float: right;"></div>' );
 82+ $('#wpRetype').after( '<span id="wpRetypeval" class="wpRetypeval"></span>' );
 83+ $('#wpEmail').after( '<span id="wpEmailval" class="wpEmailval"></span>' );
7384
7485 $("#progress").progressbar();
75 - console.log();
76 - $('div.ui-progressbar').css('background','#F2F5F7');
 86+ $('div.ui-progressbar').css( 'background', '#F2F5F7' );
7787
7888 var imagePath = window.wgServer+window.wgExtensionAssetsPath + "/SignupAPI/includes/images/";
7989 var minlength = window.wgMinimalPasswordLength;

Status & tagging log