diff options
author | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2014-03-25 01:38:11 +0300 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2014-06-13 15:34:51 +0200 |
commit | 23ed038a27901b947b75413b966d4beab21cd2bc (patch) | |
tree | 03d7522cc0f943160a35f07dc860de741dcd5d0b /core/js/lostpassword.js | |
parent | c09f5680c98d66d6e5a0fe793561194ecafed3ea (diff) | |
download | nextcloud-server-23ed038a27901b947b75413b966d4beab21cd2bc.tar.gz nextcloud-server-23ed038a27901b947b75413b966d4beab21cd2bc.zip |
Basics
Diffstat (limited to 'core/js/lostpassword.js')
-rw-r--r-- | core/js/lostpassword.js | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/core/js/lostpassword.js b/core/js/lostpassword.js new file mode 100644 index 00000000000..00dfe71be67 --- /dev/null +++ b/core/js/lostpassword.js @@ -0,0 +1,134 @@ + +OC.Lostpassword = { + sendErrorMsg : t('core', 'Couldn’t send reset email. Please contact your administrator.'), + + sendSuccessMsg : t('core', 'The link to reset your password has been sent to your email. 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.'), + + encryptedMsg : t('core', "Your files are encrypted. If you haven't enabled the recovery key, 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?") + + ('<br /><input type="checkbox" id="encrypted-continue" value="Yes" />') + + '<label for="encrypted-continue">' + + t('core', 'I know what I\'m doing') + + '</label><br />' + + '<a id="lost-password-encryption" href>' + + t('core', 'Reset password') + + '</a>', + + resetErrorMsg : t('core', 'Password can not be changed. Please contact your administrator.'), + + init : function() { + if ($('#lost-password-encryption').length){ + $('#lost-password-encryption').click(OC.Lostpassword.sendLink); + } else { + $('#lost-password').click(OC.Lostpassword.sendLink); + } + $('#reset-password #submit').click(OC.Lostpassword.resetPassword); + }, + + sendLink : function(event){ + event.preventDefault(); + if (!$('#user').val().length){ + $('#submit').trigger('click'); + } else { + $.post( + OC.filePath('core', 'ajax', 'password/lost'), + { + user : $('#user').val(), + proceed: $('#encrypted-continue').attr('checked') ? 'Yes' : 'No' + }, + OC.Lostpassword.sendLinkDone + ); + } + }, + + sendLinkDone : function(result){ + if (result && result.status === 'success'){ + OC.Lostpassword.sendLinkSuccess(); + } else { + if (result && result.msg){ + var sendErrorMsg = result.msg; + } else if (result && result.encryption) { + var sendErrorMsg = OC.Lostpassword.encryptedMsg; + } else { + var sendErrorMsg = OC.Lostpassword.sendErrorMsg; + } + OC.Lostpassword.sendLinkError(sendErrorMsg); + } + }, + + sendLinkSuccess : function(msg){ + var node = OC.Lostpassword.getSendStatusNode(); + node.addClass('success').css({width:'auto'}); + node.html(OC.Lostpassword.sendSuccessMsg); + }, + + sendLinkError : function(msg){ + var node = OC.Lostpassword.getSendStatusNode(); + node.addClass('warning'); + node.html(msg); + OC.Lostpassword.init(); + }, + + 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'); + }, + + resetPassword : function(event){ + event.preventDefault(); + if ($('#password').val()){ + $.post( + $('#password').parents('form').attr('action'), + { + password : $('#password').val() + }, + OC.Lostpassword.resetDone + ); + } + }, + + resetDone : function(result){ + if (result && result.status === 'success'){ + $.post( + OC.webroot + '/', + { + user : window.location.href.split('/').pop(), + password : $('#password').val() + }, + OC.Lostpassword.redirect + ); + } else { + if (result && result.msg){ + var resetErrorMsg = result.msg; + } else { + var resetErrorMsg = OC.Lostpassword.resetErrorMsg; + } + OC.Lostpassword.resetError(resetErrorMsg); + } + }, + + redirect : function(msg){ + window.location = OC.webroot; + }, + + resetError : function(msg){ + var node = OC.Lostpassword.getResetStatusNode(); + node.addClass('warning'); + node.html(msg); + }, + + getResetStatusNode : function (){ + if (!$('#lost-password').length){ + $('<p id="lost-password"></p>').insertAfter($('#submit')); + } else { + $('#lost-password').replaceWith($('<p id="lost-password"></p>')); + } + return $('#lost-password'); + } + +}; + +$(document).ready(OC.Lostpassword.init); |