Passed
Push — master ( 53c077...a32577 )
by Roeland
12:47
created

core/js/lostpassword.js (1 issue)

1
2
OC.Lostpassword = {
3
	sendErrorMsg : t('core', 'Couldn\'t send reset email. Please contact your administrator.'),
4
5
	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.'),
0 ignored issues
show
Line is too long.
Loading history...
6
7
	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?")
8
			+ ('<br /><input type="checkbox" id="encrypted-continue" class="checkbox checkbox--white" value="Yes" />')
9
			+ '<label for="encrypted-continue">'
10
			+ t('core', 'I know what I\'m doing')
11
			+ '</label><br />',
12
13
	resetErrorMsg : t('core', 'Password can not be changed. Please contact your administrator.'),
14
15
	init : function() {
16
		$('#lost-password[href=""]').click(OC.Lostpassword.resetLink);
17
		$('#lost-password-back').click(OC.Lostpassword.backToLogin);
18
		$('form[name=login]').submit(OC.Lostpassword.onSendLink);
19
		$('#reset-password #submit').click(OC.Lostpassword.resetPassword);
20
		OC.Lostpassword.resetButtons();
21
	},
22
23
	resetButtons : function() {
24
		$('#reset-password-wrapper .submit-icon')
25
			.addClass('icon-confirm-white')
26
			.removeClass('icon-loading-small-dark');
27
		$('#reset-password-submit')
28
			.attr('value', t('core', 'Reset password'))
29
			.prop('disabled', false);
30
		$('#user').prop('disabled', false);
31
		$('.login-additional').fadeIn();
32
	},
33
34
	backToLogin : function(event) {
35
		event.preventDefault();
36
37
		$('#reset-password-wrapper').slideUp().fadeOut();
38
		$('#lost-password').slideDown().fadeIn();
39
		$('#lost-password-back').hide();
40
		$('.remember-login-container').slideDown().fadeIn();
41
		$('#submit-wrapper').slideDown().fadeIn();
42
		$('.groupbottom').slideDown().fadeIn();
43
		$('#user').parent().addClass('grouptop');
44
		$('#password').attr('required', true);
45
		$('form[name=login]').removeAttr('action');
46
		$('#user').focus();
47
	},
48
49
	resetLink : function(event){
50
		event.preventDefault();
51
52
		$('#lost-password').hide();
53
		$('.wrongPasswordMsg').hide();
54
		$('#lost-password-back').slideDown().fadeIn();
55
		$('.remember-login-container').slideUp().fadeOut();
56
		$('#submit-wrapper').slideUp().fadeOut();
57
		$('.groupbottom').slideUp().fadeOut(function(){
58
			$('#user').parent().removeClass('grouptop');
59
		});
60
		$('#reset-password-wrapper').slideDown().fadeIn();
61
		$('#password').attr('required', false);
62
		$('form[name=login]').attr('action', 'lostpassword/email');
63
		$('#user').focus();
64
65
		// Generate a browser warning for required fields if field empty
66
		if ($('#user').val().length === 0) {
67
			$('#submit').trigger('click');
68
		} else {
69
			if (OC.config.lost_password_link === 'disabled') {
70
				return;
71
			} else if (OC.config.lost_password_link) {
72
				window.location = OC.config.lost_password_link;
73
			} else {
74
				OC.Lostpassword.onSendLink();
75
			}
76
		}
77
	},
78
79
	onSendLink: function (event) {
80
		// Only if password reset form is active
81
		if($('form[name=login][action]').length === 1) {
82
			if (event) {
83
				event.preventDefault();
84
			}
85
			$('#reset-password-wrapper .submit-icon')
86
				.removeClass('icon-confirm-white')
87
				.addClass('icon-loading-small-dark');
88
			$('#reset-password-submit')
89
				.attr('value', t('core', 'Sending email …'))
90
				.prop('disabled', true);
91
			$('#user').prop('disabled', true);
92
			$('.login-additional').fadeOut();
93
			$.post(
94
				OC.generateUrl('/lostpassword/email'),
95
				{
96
					user : $('#user').val()
97
				},
98
				OC.Lostpassword.sendLinkDone
99
			).fail(function() {
100
				OC.Lostpassword.sendLinkError(OC.Lostpassword.sendErrorMsg);
101
			});
102
		}
103
	},
104
105
	sendLinkDone : function(result){
106
		var sendErrorMsg;
107
108
		if (result && result.status === 'success'){
109
			OC.Lostpassword.sendLinkSuccess();
110
		} else {
111
			if (result && result.msg){
112
				sendErrorMsg = result.msg;
113
			} else {
114
				sendErrorMsg = OC.Lostpassword.sendErrorMsg;
115
			}
116
			OC.Lostpassword.sendLinkError(sendErrorMsg);
117
		}
118
	},
119
120
	sendLinkSuccess : function(msg){
121
		var node = OC.Lostpassword.getSendStatusNode();
122
		// update is the better success message styling
123
		node.addClass('update').css({width:'auto'});
124
		node.html(OC.Lostpassword.sendSuccessMsg);
125
		OC.Lostpassword.resetButtons();
126
	},
127
128
	sendLinkError : function(msg){
129
		var node = OC.Lostpassword.getSendStatusNode();
130
		node.addClass('warning');
131
		node.html(msg);
132
		OC.Lostpassword.resetButtons();
133
	},
134
135
	getSendStatusNode : function(){
136
		if (!$('#lost-password').length){
137
			$('<p id="lost-password"></p>').insertBefore($('#remember_login'));
138
		} else {
139
			$('#lost-password').replaceWith($('<p id="lost-password"></p>'));
140
		}
141
		return $('#lost-password');
142
	},
143
144
	resetPassword : function(event){
145
		event.preventDefault();
146
		if ($('#password').val()){
147
			$.post(
148
					$('#password').parents('form').attr('action'),
149
					{
150
						password : $('#password').val(),
151
						proceed: $('#encrypted-continue').is(':checked') ? 'true' : 'false'
152
					},
153
					OC.Lostpassword.resetDone
154
			);
155
		}
156
		if($('#encrypted-continue').is(':checked')) {
157
			$('#reset-password #submit').hide();
158
			$('#reset-password #float-spinner').removeClass('hidden');
159
		}
160
	},
161
162
	resetDone : function(result){
163
		var resetErrorMsg;
164
		if (result && result.status === 'success'){
165
			OC.Lostpassword.redirect('/login?user=' + result.user);
166
		} else {
167
			if (result && result.msg){
168
				resetErrorMsg = result.msg;
169
			} else if (result && result.encryption) {
170
				resetErrorMsg = OC.Lostpassword.encryptedMsg;
171
			} else {
172
				resetErrorMsg = OC.Lostpassword.resetErrorMsg;
173
			}
174
			OC.Lostpassword.resetError(resetErrorMsg);
175
		}
176
	},
177
178
	redirect : function(url){
179
		window.location = OC.generateUrl(url);
180
	},
181
182
	resetError : function(msg){
183
		var node = OC.Lostpassword.getResetStatusNode();
184
		node.addClass('warning');
185
		node.html(msg);
186
	},
187
188
	getResetStatusNode : function (){
189
		if (!$('#lost-password').length){
190
			$('<p id="lost-password"></p>').insertBefore($('#reset-password fieldset'));
191
		} else {
192
			$('#lost-password').replaceWith($('<p id="lost-password"></p>'));
193
		}
194
		return $('#lost-password');
195
	}
196
197
};
198
199
$(document).ready(OC.Lostpassword.init);
200