Index: trunk/extensions/SignupAPI/SignupAPI.i18n.php |
— | — | @@ -22,6 +22,7 @@ |
23 | 23 | 'signupapi-badretype' => 'The passwords you entered do not match', |
24 | 24 | 'signupapi-passwordsmatch' => 'Passwords match', |
25 | 25 | 'signupapi-invalidemailaddress' => 'E-mail address is invalid', |
| 26 | + 'signupapi-invalidusername' => 'Username entered is invalid', |
26 | 27 | ); |
27 | 28 | |
28 | 29 | /** Message documentation (Message documentation) |
Index: trunk/extensions/SignupAPI/includes/ApiValidateSignup.php |
— | — | @@ -23,15 +23,18 @@ |
24 | 24 | |
25 | 25 | switch ( $params['field'] ) { |
26 | 26 | case "username": |
27 | | - $mUser = User::newFromName( $params['inputVal'], 'creatable' ); |
28 | | - if ( !is_object( $mUser ) ) { |
| 27 | + if( $params['inputVal'] == '' ) { |
| 28 | + # Username left blank |
29 | 29 | $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 |
34 | 33 | $result['result'] = wfMsg( 'signupapi-userexists' ); |
35 | 34 | $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"; |
36 | 39 | } else { |
37 | 40 | $result['result'] = wfMsg( 'signupapi-ok' ); |
38 | 41 | $result['icon'] = "MW-Icon-CheckMark.png"; |
Index: trunk/extensions/SignupAPI/includes/verification.js |
— | — | @@ -2,77 +2,87 @@ |
3 | 3 | |
4 | 4 | jQuery( document ).ready( function( $ ) { |
5 | 5 | |
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' ); |
9 | 9 | $.ajax({ |
10 | 10 | type: "POST", |
11 | 11 | 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 }, |
13 | 13 | dataType: 'json', |
14 | 14 | success: function( jsondata ){ |
15 | 15 | var image = "<img src='"+ imagePath + jsondata.signup.icon +"'>"; |
16 | 16 | var message = jsondata.signup.result; |
17 | | - valresult.innerHTML = image+message; |
| 17 | + valresult.innerHTML = image + message; |
18 | 18 | } |
19 | 19 | }); |
20 | 20 | } |
21 | 21 | |
22 | 22 | 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" ); |
28 | 28 | |
29 | 29 | if (pwd.value.length==0) { |
30 | 30 | strength.innerHTML = mw.message( 'signupapi-enterpassword' ); |
31 | | - } else if (pwd.value.length<minlength) { |
| 31 | + } else if ( pwd.value.length<minlength ) { |
32 | 32 | strength.innerHTML = mw.message( 'signupapi-passwordtooshort', minlength ); |
33 | 33 | $("#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) ) { |
36 | 36 | strength.innerHTML = '<span style="color:green">'+mw.message( 'signupapi-strong' )+'</span>'; |
37 | 37 | $("#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) ) { |
40 | 40 | strength.innerHTML = '<span style="color:orange">'+mw.message( 'signupapi-medium' )+'</span>'; |
41 | 41 | $("#progress").progressbar({value: 60}); |
42 | | - $("div.ui-progressbar-value").css("background","orange"); |
| 42 | + $("div.ui-progressbar-value").css( "background", "orange" ); |
43 | 43 | } else { |
44 | 44 | strength.innerHTML = '<span style="color:red">'+mw.message( 'signupapi-weak' )+'</span>'; |
45 | 45 | $("#progress").progressbar({value: 30}); |
46 | | - $("div.ui-progressbar-value").css("background","red"); |
| 46 | + $("div.ui-progressbar-value").css( "background", "red"); |
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | | - function checkRetype( pass,retype ) { |
51 | | - var valresult = document.getElementById('wpRetypeval'); |
| 50 | + function checkRetype( pass, retype ) { |
| 51 | + var valresult = document.getElementById( 'wpRetypeval' ); |
52 | 52 | var image = ""; |
53 | 53 | var message = ""; |
54 | | - if ( pass==retype ) { |
| 54 | + if ( pass == retype ) { |
55 | 55 | image = "<img src='"+ imagePath +"MW-Icon-CheckMark.png'>"; |
56 | 56 | message = mw.message( 'signupapi-passwordsmatch' ); |
57 | | - }else { |
| 57 | + } else { |
58 | 58 | image = "<img src='"+ imagePath +"MW-Icon-NoMark.png'>"; |
59 | 59 | message = mw.message( 'signupapi-badretype' ); |
60 | 60 | } |
61 | 61 | valresult.innerHTML = image+message; |
62 | 62 | } |
| 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 | + } |
63 | 73 | |
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" );} ); |
68 | 79 | |
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>' ); |
73 | 84 | |
74 | 85 | $("#progress").progressbar(); |
75 | | - console.log(); |
76 | | - $('div.ui-progressbar').css('background','#F2F5F7'); |
| 86 | + $('div.ui-progressbar').css( 'background', '#F2F5F7' ); |
77 | 87 | |
78 | 88 | var imagePath = window.wgServer+window.wgExtensionAssetsPath + "/SignupAPI/includes/images/"; |
79 | 89 | var minlength = window.wgMinimalPasswordLength; |