Skip to content

Commit

Permalink
Adapt code to OC9
Browse files Browse the repository at this point in the history
  • Loading branch information
ppaysant committed Dec 20, 2016
1 parent ee7d0dc commit ba3b00a
Show file tree
Hide file tree
Showing 10 changed files with 761 additions and 538 deletions.
9 changes: 5 additions & 4 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
*/
\OCP\Util::addStyle($c->query('AppName'), 'colorbox');
\OCP\Util::addScript($c->query('AppName'), 'jquery.colorbox');
\OCP\Util::addScript("core", 'jquery-showpassword');
\OCP\Util::addscript($c->query('AppName'), 'setpassword');

\OCP\Util::addStyle($c->query('AppName'), 'setpassword');

if (\OCP\User::isLoggedIn() and Helper::isEnabled()) {
\OC_Util::addScript( '3rdparty', 'strengthify/jquery.strengthify' );
\OC_Util::addStyle( '3rdparty', 'strengthify/strengthify' );
\OC_Util::addScript( '3rdparty', 'chosen/chosen.jquery.min' );
\OC_Util::addStyle( '3rdparty', 'chosen/chosen' );
\OC_Util::addVendorScript('strengthify/jquery.strengthify');
\OC_Util::addVendorStyle('strengthify/strengthify');
// \OC_Util::addScript( '3rdparty', 'chosen/chosen.jquery.min' );
// \OC_Util::addStyle( '3rdparty', 'chosen/chosen' );

\OCP\Util::addScript($c->query('AppName'), 'activate');
}
6 changes: 5 additions & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
<version>0.1</version>
<licence>AGPLv3</licence>
<author>Patrick Paysant / CNRS</author>
<require>7</require>
<dependencies>
<owncloud min-version="9.0" max-version="10.0"/>
</dependencies>
<repository type="git">https://github.com/CNRS-DSI-Dev/user_set_password</repository>
<bugs>https://github.com/CNRS-DSI-Dev/user_set_password/issues</bugs>
</info>
4 changes: 2 additions & 2 deletions controller/requestcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

namespace OCA\User_Set_Password\Controller;

use \OCP\AppFramework\APIController;
use \OCP\AppFramework\ApiController;
use \OCP\AppFramework\Http\JSONResponse;
use \OCP\IRequest;
use \OCP\IL10N;

use \OCA\User_Set_Password\lib\Helper;

class RequestController extends APIController
class RequestController extends ApiController
{
protected $l;

Expand Down
2 changes: 1 addition & 1 deletion css/setpassword.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
width: 24px;
margin-top: 14px;
margin-left: -36px;
background-image: url("../../../core/img/actions/toggle.png");
background-image: url("../../../core/img/actions/toggle.svg");
background-repeat: no-repeat;
background-position: center;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
Expand Down
77 changes: 43 additions & 34 deletions js/activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $(document).ready(function () {

// Done when "colorBox" is displayed
function showSetPasswordComplete() {
$("#userSetPassword #passwordform").on('submit', function(){
$("#userSetPassword #passwordform").on('submit', function(e){

// TODO: implement basic tests (fields must be set, fields must be same)
if (($('#pass1').val() == '') || ($('#pass2').val() == '')) {
Expand All @@ -24,38 +24,61 @@ function showSetPasswordComplete() {
}

if ($('#pass1').val() !== '') {
// Serialize the data
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.show( t('user_set_password', 'Password successfully changed') );
setTimeout(OC.Notification.hide, 7000);
$.colorbox.close();
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 {
if (typeof(data.data) !== "undefined") {
$('#passworderror').html(data.data.msg);
} else {
$('#passworderror').html(t('user_set_password', 'Unable to change password'));
}
$('#passworderror').html(t('password_policy', 'Password does not comply with the Password Policy.'));
$('#passworderror').show();

e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
return false;
}
});
return false;
}
else {
$('#passwordchanged').hide();
$('#passworderror').show();
return false;
}

return false;
});

$('#pass1').strengthify({
zxcvbn: OC.linkTo('3rdparty','zxcvbn/js/zxcvbn.js'),
zxcvbn: OC.linkTo('core','vendor/zxcvbn/dist/zxcvbn.js'),
titles: [
t('core', 'Very weak password'),
t('core', 'Weak password'),
Expand All @@ -70,18 +93,14 @@ function showSetPasswordComplete() {
};
setShowPassword($('#pass1'), $('label[for=personal-show]'));
setShowPassword($('#pass2'), $('label[for=personal-confirm-show]'));

$("#userSetPassword #passwordbutton").bindFirst('click',function(e){
check_password_policy(e);
});
}

function check_password_policy(e) {
var password = $('#pass1').val();

$.ajax({
type: 'POST',
url: OC.filePath('password_policy', 'ajax', 'testPassword.php'),
url: OC.generateUrl('/apps/password_policy/policy/set_password'),
data: {password: password},
success: function(data){
if (data.status == 'success') {
Expand All @@ -100,13 +119,3 @@ function check_password_policy(e) {
});

}

$.fn.bindFirst = function(name, fn) {
this.on(name, fn);

this.each(function() {
var handlers = $._data(this, 'events')[name.split('.')[0]];
var handler = handlers.pop();
handlers.splice(0, 0, handler);
});
};
Loading

0 comments on commit ba3b00a

Please sign in to comment.