nextcloud/core/js/lostpassword.js

146 lines
4.0 KiB
JavaScript
Raw Normal View History

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.'),
2014-03-25 02:38:11 +04:00
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.'),
2014-06-13 18:03:13 +04: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?")
2014-03-25 02:38:11 +04:00
+ ('<br /><input type="checkbox" id="encrypted-continue" value="Yes" />')
+ '<label for="encrypted-continue">'
+ t('core', 'I know what I\'m doing')
+ '</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() {
$('#lost-password').click(OC.Lostpassword.resetLink);
2014-03-25 02:38:11 +04:00
$('#reset-password #submit').click(OC.Lostpassword.resetPassword);
},
2014-06-13 18:03:13 +04:00
resetLink : function(event){
2014-03-25 02:38:11 +04:00
event.preventDefault();
if (!$('#user').val().length){
$('#submit').trigger('click');
} else {
if (OC.config['lost_password_link']) {
window.location = OC.config['lost_password_link'];
} else {
$.post(
2014-06-03 02:24:27 +04:00
OC.generateUrl('/lostpassword/email'),
2014-05-28 21:13:07 +04:00
{
user : $('#user').val()
2014-05-28 21:13:07 +04:00
},
2014-03-25 02:38:11 +04:00
OC.Lostpassword.sendLinkDone
).fail(function() {
OC.Lostpassword.sendLinkError(OC.Lostpassword.sendErrorMsg);
});
}
2014-03-25 02:38:11 +04:00
}
},
2014-06-13 18:03:13 +04: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();
// 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);
},
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);
OC.Lostpassword.init();
},
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
{
password : $('#password').val(),
proceed: $('#encrypted-continue').is(':checked') ? 'true' : 'false'
2014-03-25 02:38:11 +04:00
},
OC.Lostpassword.resetDone
);
}
if($('#encrypted-continue').is(':checked')) {
$('#reset-password #submit').hide();
2014-11-17 19:49:58 +03:00
$('#reset-password #float-spinner').removeClass('hidden');
}
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'){
$.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);
}
},
2014-06-13 18:03:13 +04:00
2014-03-25 02:38:11 +04:00
redirect : function(msg){
if(OC.webroot !== '') {
window.location = OC.webroot;
} else {
window.location = '/';
}
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){
$('<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);