-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathactivate.js
121 lines (109 loc) · 4.35 KB
/
activate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
$(document).ready(function () {
//do not show when upgrade is in progress or an error message
//is visible on the login page
if (jQuery('#upgrade').length === 0 && jQuery('#body-login .error').length === 0) {
showSetPassword();
}
});
// Done when "colorBox" is displayed
function showSetPasswordComplete() {
$("#userSetPassword #passwordform").on('submit', function(e){
// TODO: implement basic tests (fields must be set, fields must be same)
if (($('#pass1').val() == '') || ($('#pass2').val() == '')) {
$('#passworderror').html(t('user_set_password', 'Both password fields must be set.'));
$('#passworderror').show();
return false;
}
if ($('#pass1').val() != $('#pass2').val()) {
$('#passworderror').html(t('user_set_password', 'Passwords differs.'));
$('#passworderror').show();
return false;
}
if ($('#pass1').val() !== '') {
var password = $('#pass1').val();
$.ajax({
type: 'POST',
url: OC.generateUrl('/apps/password_policy/policy/set_password'),
data: {password: password},
async: false
}).
done(function(data) {
if (data.status == 'success') {
var post = $( "#passwordform" ).serialize();
$('#passwordchanged').hide();
$('#passworderror').hide();
// Ajax foo
$.post(OC.generateUrl('/apps/user_set_password/api/1.0/changepassword'), post, function(data){
if ( data.status === "success" ){
$('.strengthify-wrapper').tipsy('hide');
OC.Notification.showTemporary( t('user_set_password', 'Password successfully changed') );
e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
$.colorbox.close();
}
else {
if (typeof(data.data) !== "undefined") {
$('#passworderror').html(data.data.msg);
} else {
$('#passworderror').html(t('user_set_password', 'Unable to change password'));
}
$('#passworderror').show();
}
});
return false;
}
else {
$('#passworderror').html(t('password_policy', 'Password does not comply with the Password Policy.'));
$('#passworderror').show();
e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
return false;
}
});
}
else {
$('#passwordchanged').hide();
$('#passworderror').show();
return false;
}
return false;
});
$('#pass1').strengthify({
zxcvbn: OC.linkTo('core','vendor/zxcvbn/dist/zxcvbn.js'),
titles: [
t('core', 'Very weak password'),
t('core', 'Weak password'),
t('core', 'So-so password'),
t('core', 'Good password'),
t('core', 'Strong password')
]
});
var setShowPassword = function(input, label) {
input.showPassword().keyup();
};
setShowPassword($('#pass1'), $('label[for=personal-show]'));
setShowPassword($('#pass2'), $('label[for=personal-confirm-show]'));
}
function check_password_policy(e) {
var password = $('#pass1').val();
$.ajax({
type: 'POST',
url: OC.generateUrl('/apps/password_policy/policy/set_password'),
data: {password: password},
success: function(data){
if (data.status == 'success') {
return true;
}
else {
$('#passworderror').html(t('password_policy', 'Password does not comply with the Password Policy.'));
$('#passworderror').show();
e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
return false;
}
}
});
}