nextcloud/core/js/lostpassword.js

139 lines
3.9 KiB
JavaScript
Raw Normal View History

2014-03-25 02:38:11 +04:00
OC.Lostpassword = {
sendErrorMsg : t('core', 'Couldnt 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(
2014-06-03 02:24:27 +04:00
OC.generateUrl('/lostpassword/email'),
2014-05-28 21:13:07 +04:00
{
2014-03-25 02:38:11 +04:00
user : $('#user').val(),
proceed: $('#encrypted-continue').attr('checked') ? 'Yes' : 'No'
2014-05-28 21:13:07 +04:00
},
2014-03-25 02:38:11 +04:00
OC.Lostpassword.sendLinkDone
);
}
},
sendLinkDone : function(result){
2014-05-28 21:13:07 +04:00
var sendErrorMsg;
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);
}
},
sendLinkSuccess : function(msg){
var node = OC.Lostpassword.getSendStatusNode();
// 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);
},
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'),
2014-05-28 21:13:07 +04:00
{
2014-03-25 02:38:11 +04:00
password : $('#password').val()
},
OC.Lostpassword.resetDone
);
}
},
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'){
$.post(
OC.webroot + '/',
{
user : window.location.href.split('/').pop(),
password : $('#password').val()
},
OC.Lostpassword.redirect
);
} 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);
}
},
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);