2014-03-25 02:38:11 +04:00
OC . Lostpassword = {
2014-06-13 18:02:41 +04:00
sendErrorMsg : t ( 'core' , 'Couldn\'t send reset email. Please contact your administrator.' ) ,
2019-01-14 23:05:52 +03:00
sendSuccessMsg : t ( 'core' , 'We have send a password reset e-mail to the e-mail address known to us for this account. If you do not receive it within a reasonable amount of time, check your spam/junk folders.<br>If it is not there ask your local administrator.' ) ,
2014-06-13 18:03:13 +04:00
2017-01-02 23:24:37 +03:00
encryptedMsg : t ( 'core' , "Your files are encrypted. There will be no way to get your data back after your password is reset.<br />If you are not sure what to do, please contact your administrator before you continue. <br />Do you really want to continue?" )
2018-12-12 17:37:45 +03:00
+ ( '<br /><input type="checkbox" id="encrypted-continue" class="checkbox checkbox--white" value="Yes" />' )
2014-03-25 02:38:11 +04:00
+ '<label for="encrypted-continue">'
+ t ( 'core' , 'I know what I\'m doing' )
2014-10-20 21:05:48 +04:00
+ '</label><br />' ,
2014-06-13 18:03:13 +04:00
2014-03-25 02:38:11 +04:00
resetErrorMsg : t ( 'core' , 'Password can not be changed. Please contact your administrator.' ) ,
2014-06-13 18:03:13 +04:00
2014-03-25 02:38:11 +04:00
init : function ( ) {
2018-07-21 17:19:46 +03:00
$ ( '#lost-password[href=""]' ) . click ( OC . Lostpassword . resetLink ) ;
2017-11-02 14:02:51 +03:00
$ ( '#lost-password-back' ) . click ( OC . Lostpassword . backToLogin ) ;
2017-11-05 18:33:18 +03:00
$ ( 'form[name=login]' ) . submit ( OC . Lostpassword . onSendLink ) ;
2017-12-19 16:00:47 +03:00
$ ( '#reset-password #submit' ) . click ( OC . Lostpassword . resetPassword ) ;
2017-11-05 18:33:18 +03:00
OC . Lostpassword . resetButtons ( ) ;
} ,
resetButtons : function ( ) {
2017-11-05 07:45:32 +03:00
$ ( '#reset-password-wrapper .submit-icon' )
. addClass ( 'icon-confirm-white' )
2017-11-05 18:33:18 +03:00
. removeClass ( 'icon-loading-small-dark' ) ;
2017-11-05 07:45:32 +03:00
$ ( '#reset-password-submit' )
2017-11-05 18:33:18 +03:00
. attr ( 'value' , t ( 'core' , 'Reset password' ) )
. prop ( 'disabled' , false ) ;
$ ( '#user' ) . prop ( 'disabled' , false ) ;
$ ( '.login-additional' ) . fadeIn ( ) ;
2017-11-02 14:02:51 +03:00
} ,
2017-11-05 18:33:18 +03:00
backToLogin : function ( event ) {
2017-11-02 14:02:51 +03:00
event . preventDefault ( ) ;
$ ( '#reset-password-wrapper' ) . slideUp ( ) . fadeOut ( ) ;
$ ( '#lost-password' ) . slideDown ( ) . fadeIn ( ) ;
2017-11-05 20:14:52 +03:00
$ ( '#lost-password-back' ) . hide ( ) ;
2017-11-02 14:02:51 +03:00
$ ( '.remember-login-container' ) . slideDown ( ) . fadeIn ( ) ;
$ ( '#submit-wrapper' ) . slideDown ( ) . fadeIn ( ) ;
$ ( '.groupbottom' ) . slideDown ( ) . fadeIn ( ) ;
$ ( '#user' ) . parent ( ) . addClass ( 'grouptop' ) ;
2017-11-05 18:33:18 +03:00
$ ( '#password' ) . attr ( 'required' , true ) ;
$ ( 'form[name=login]' ) . removeAttr ( 'action' ) ;
2017-11-02 14:02:51 +03:00
$ ( '#user' ) . focus ( ) ;
2014-03-25 02:38:11 +04:00
} ,
2014-06-13 18:03:13 +04:00
2015-12-07 17:37:26 +03:00
resetLink : function ( event ) {
2014-03-25 02:38:11 +04:00
event . preventDefault ( ) ;
2017-11-02 14:02:51 +03:00
2017-11-05 20:14:52 +03:00
$ ( '#lost-password' ) . hide ( ) ;
2017-12-30 01:54:46 +03:00
$ ( '.wrongPasswordMsg' ) . hide ( ) ;
2017-11-05 20:14:52 +03:00
$ ( '#lost-password-back' ) . slideDown ( ) . fadeIn ( ) ;
2017-11-02 14:02:51 +03:00
$ ( '.remember-login-container' ) . slideUp ( ) . fadeOut ( ) ;
$ ( '#submit-wrapper' ) . slideUp ( ) . fadeOut ( ) ;
2017-11-05 18:33:18 +03:00
$ ( '.groupbottom' ) . slideUp ( ) . fadeOut ( function ( ) {
$ ( '#user' ) . parent ( ) . removeClass ( 'grouptop' ) ;
} ) ;
2017-11-02 14:02:51 +03:00
$ ( '#reset-password-wrapper' ) . slideDown ( ) . fadeIn ( ) ;
2017-11-05 18:33:18 +03:00
$ ( '#password' ) . attr ( 'required' , false ) ;
$ ( 'form[name=login]' ) . attr ( 'action' , 'lostpassword/email' ) ;
2017-11-02 14:02:51 +03:00
$ ( '#user' ) . focus ( ) ;
2017-11-05 18:33:18 +03:00
// Generate a browser warning for required fields if field empty
2017-11-05 07:45:32 +03:00
if ( $ ( '#user' ) . val ( ) . length === 0 ) {
2014-03-25 02:38:11 +04:00
$ ( '#submit' ) . trigger ( 'click' ) ;
} else {
2017-05-11 17:46:43 +03:00
if ( OC . config . lost _password _link === 'disabled' ) {
return ;
} else if ( OC . config . lost _password _link ) {
2017-05-01 06:45:41 +03:00
window . location = OC . config . lost _password _link ;
2015-12-07 17:37:26 +03:00
} else {
2017-11-05 07:45:32 +03:00
OC . Lostpassword . onSendLink ( ) ;
2015-12-07 17:37:26 +03:00
}
2014-03-25 02:38:11 +04:00
}
} ,
2014-06-13 18:03:13 +04:00
2017-11-05 18:33:18 +03:00
onSendLink : function ( event ) {
// Only if password reset form is active
if ( $ ( 'form[name=login][action]' ) . length === 1 ) {
if ( event ) {
event . preventDefault ( ) ;
}
$ ( '#reset-password-wrapper .submit-icon' )
. removeClass ( 'icon-confirm-white' )
. addClass ( 'icon-loading-small-dark' ) ;
$ ( '#reset-password-submit' )
. attr ( 'value' , t ( 'core' , 'Sending email …' ) )
. prop ( 'disabled' , true ) ;
$ ( '#user' ) . prop ( 'disabled' , true ) ;
$ ( '.login-additional' ) . fadeOut ( ) ;
$ . post (
OC . generateUrl ( '/lostpassword/email' ) ,
{
user : $ ( '#user' ) . val ( )
} ,
OC . Lostpassword . sendLinkDone
) . fail ( function ( ) {
OC . Lostpassword . sendLinkError ( OC . Lostpassword . sendErrorMsg ) ;
} ) ;
}
2017-11-05 07:45:32 +03:00
} ,
2014-03-25 02:38:11 +04:00
sendLinkDone : function ( result ) {
2014-05-28 21:13:07 +04:00
var sendErrorMsg ;
2014-06-13 18:03:13 +04:00
2014-03-25 02:38:11 +04:00
if ( result && result . status === 'success' ) {
OC . Lostpassword . sendLinkSuccess ( ) ;
} else {
if ( result && result . msg ) {
2014-05-28 21:13:07 +04:00
sendErrorMsg = result . msg ;
2014-03-25 02:38:11 +04:00
} else {
2014-05-28 21:13:07 +04:00
sendErrorMsg = OC . Lostpassword . sendErrorMsg ;
2014-03-25 02:38:11 +04:00
}
OC . Lostpassword . sendLinkError ( sendErrorMsg ) ;
}
} ,
2014-06-13 18:03:13 +04:00
2014-03-25 02:38:11 +04:00
sendLinkSuccess : function ( msg ) {
var node = OC . Lostpassword . getSendStatusNode ( ) ;
2014-06-13 17:54:09 +04:00
// update is the better success message styling
node . addClass ( 'update' ) . css ( { width : 'auto' } ) ;
2014-03-25 02:38:11 +04:00
node . html ( OC . Lostpassword . sendSuccessMsg ) ;
2017-11-05 20:14:52 +03:00
OC . Lostpassword . resetButtons ( ) ;
2014-03-25 02:38:11 +04:00
} ,
2014-06-13 18:03:13 +04:00
2014-03-25 02:38:11 +04:00
sendLinkError : function ( msg ) {
var node = OC . Lostpassword . getSendStatusNode ( ) ;
node . addClass ( 'warning' ) ;
node . html ( msg ) ;
2017-11-05 18:33:18 +03:00
OC . Lostpassword . resetButtons ( ) ;
2014-03-25 02:38:11 +04:00
} ,
2014-06-13 18:03:13 +04:00
2014-03-25 02:38:11 +04:00
getSendStatusNode : function ( ) {
if ( ! $ ( '#lost-password' ) . length ) {
$ ( '<p id="lost-password"></p>' ) . insertBefore ( $ ( '#remember_login' ) ) ;
} else {
$ ( '#lost-password' ) . replaceWith ( $ ( '<p id="lost-password"></p>' ) ) ;
}
return $ ( '#lost-password' ) ;
} ,
2014-06-13 18:03:13 +04:00
2014-03-25 02:38:11 +04:00
resetPassword : function ( event ) {
event . preventDefault ( ) ;
if ( $ ( '#password' ) . val ( ) ) {
$ . post (
$ ( '#password' ) . parents ( 'form' ) . attr ( 'action' ) ,
2014-05-28 21:13:07 +04:00
{
2014-10-20 21:05:48 +04:00
password : $ ( '#password' ) . val ( ) ,
2016-04-19 16:13:37 +03:00
proceed : $ ( '#encrypted-continue' ) . is ( ':checked' ) ? 'true' : 'false'
2014-03-25 02:38:11 +04:00
} ,
OC . Lostpassword . resetDone
) ;
}
2016-04-19 16:13:37 +03:00
if ( $ ( '#encrypted-continue' ) . is ( ':checked' ) ) {
2014-10-29 15:26:24 +03:00
$ ( '#reset-password #submit' ) . hide ( ) ;
2014-11-17 19:49:58 +03:00
$ ( '#reset-password #float-spinner' ) . removeClass ( 'hidden' ) ;
2014-10-29 15:26:24 +03:00
}
2014-03-25 02:38:11 +04:00
} ,
2014-06-13 18:03:13 +04:00
2014-03-25 02:38:11 +04:00
resetDone : function ( result ) {
2014-05-28 21:13:07 +04:00
var resetErrorMsg ;
2014-03-25 02:38:11 +04:00
if ( result && result . status === 'success' ) {
2018-06-19 18:02:20 +03:00
OC . Lostpassword . redirect ( '/login?user=' + result . user ) ;
2014-03-25 02:38:11 +04:00
} else {
if ( result && result . msg ) {
2014-05-28 21:13:07 +04:00
resetErrorMsg = result . msg ;
2014-05-28 01:09:08 +04:00
} else if ( result && result . encryption ) {
2014-05-28 21:13:07 +04:00
resetErrorMsg = OC . Lostpassword . encryptedMsg ;
2014-03-25 02:38:11 +04:00
} else {
2014-05-28 21:13:07 +04:00
resetErrorMsg = OC . Lostpassword . resetErrorMsg ;
2014-03-25 02:38:11 +04:00
}
OC . Lostpassword . resetError ( resetErrorMsg ) ;
}
} ,
2014-06-13 18:03:13 +04:00
2018-06-19 18:02:20 +03:00
redirect : function ( url ) {
window . location = OC . generateUrl ( url ) ;
2014-03-25 02:38:11 +04:00
} ,
2014-06-13 18:03:13 +04:00
2014-03-25 02:38:11 +04:00
resetError : function ( msg ) {
var node = OC . Lostpassword . getResetStatusNode ( ) ;
node . addClass ( 'warning' ) ;
node . html ( msg ) ;
} ,
2014-06-13 18:03:13 +04:00
2014-03-25 02:38:11 +04:00
getResetStatusNode : function ( ) {
if ( ! $ ( '#lost-password' ) . length ) {
2014-10-20 21:05:48 +04:00
$ ( '<p id="lost-password"></p>' ) . insertBefore ( $ ( '#reset-password fieldset' ) ) ;
2014-03-25 02:38:11 +04:00
} else {
$ ( '#lost-password' ) . replaceWith ( $ ( '<p id="lost-password"></p>' ) ) ;
}
return $ ( '#lost-password' ) ;
}
} ;
$ ( document ) . ready ( OC . Lostpassword . init ) ;