@ -9,6 +9,7 @@ define([
'/common/common-hash.js' ,
'/customize/messages.js' ,
'/common/hyperscript.js' ,
'/customize/credential.js' ,
'/customize/application_config.js' ,
'/api/config' ,
@ -27,6 +28,7 @@ define([
Hash ,
Messages ,
h ,
Cred ,
AppConfig ,
ApiConfig
)
@ -375,22 +377,87 @@ define([
var $div = $ ( '<div>' , { 'class' : 'cp-settings-change-password cp-sidebarlayout-element' } ) ;
$ ( '<span>' , { 'class' : 'label' } ) . text ( "TODO Change your password" ) . appendTo ( $div ) ; // XXX
$ ( '<span>' , { 'class' : 'label' } ) . text ( Messages . settings _changePasswordTitle ) . appendTo ( $div ) ;
$ ( '<span>' , { 'class' : 'cp-sidebarlayout-description' } )
. append ( "TODO" ) . appendTo ( $div ) ; // XXX
. append ( Messages . settings _changePasswordHint ) . appendTo ( $div ) ;
// var publicKey = privateData.edPublic;
var form = h ( 'div' , [
UI . passwordInput ( {
id : 'cp-settings-change-password-current' ,
placeholder : Messages . settings _changePasswordCurrent
} , true ) ,
h ( 'br' ) ,
UI . passwordInput ( {
id : 'cp-settings-change-password-new' ,
placeholder : Messages . settings _changePasswordNew
} , true ) ,
UI . passwordInput ( {
id : 'cp-settings-change-password-new2' ,
placeholder : Messages . settings _changePasswordNewConfirm
} , true ) ,
h ( 'button.btn.btn-primary' , Messages . settings _changePasswordButton )
] ) ;
$ ( form ) . appendTo ( $div ) ;
var updateBlock = function ( data , cb ) {
sframeChan . query ( 'Q_WRITE_LOGIN_BLOCK' , data , function ( err , obj ) {
if ( err || obj . error ) { return void cb ( { error : err || obj . error } ) ; }
cb ( obj ) ;
} ) ;
} ;
updateBlock = updateBlock ; // jshint..
var todo = function ( ) {
var oldPassword = $ ( form ) . find ( '#cp-settings-change-password-current' ) . val ( ) ;
var newPassword = $ ( form ) . find ( '#cp-settings-change-password-new' ) . val ( ) ;
var newPasswordConfirm = $ ( form ) . find ( '#cp-settings-change-password-new2' ) . val ( ) ;
/* basic validation */
if ( ! Cred . isLongEnoughPassword ( newPassword ) ) {
var warning = Messages . _getKey ( 'register_passwordTooShort' , [
Cred . MINIMUM _PASSWORD _LENGTH
] ) ;
return void UI . alert ( warning ) ;
}
if ( newPassword !== newPasswordConfirm ) {
UI . alert ( Messages . register _passwordsDontMatch ) ;
return ;
}
UI . confirm ( Messages . settings _changePasswordConfirm ,
function ( yes ) {
if ( ! yes ) { return ; }
// TODO
console . log ( oldPassword , newPassword , newPasswordConfirm ) ;
} , {
ok : Messages . register _writtenPassword ,
cancel : Messages . register _cancel ,
cancelClass : 'safe' ,
okClass : 'danger' ,
reverseOrder : true ,
done : function ( $dialog ) {
$dialog . find ( '> div' ) . addClass ( 'half' ) ;
} ,
} , true ) ;
} ;
$ ( form ) . find ( 'button' ) . click ( function ( ) {
todo ( ) ;
} ) ;
$ ( form ) . find ( 'input' ) . keydown ( function ( e ) {
// Save on Enter
if ( e . which === 13 ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
todo ( ) ;
}
} ) ;
return $div ;
} ;