Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/Ltb/Ppolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,6 @@ static function smarty_assign_ppolicy($smarty, $pwd_show_policy_pos, $pwd_show_p
if (isset($pwd_show_policy_pos)) {
$smarty->assign('pwd_show_policy_pos', $pwd_show_policy_pos);
$smarty->assign('pwd_show_policy', $pwd_show_policy);
$smarty->assign('pwd_show_policy_onerror', true);
if ( $pwd_show_policy === "onerror" ) {
if ( !preg_match( "/tooshort|toobig|minlower|minupper|mindigit|minspecial|forbiddenchars|sameasold|notcomplex|sameaslogin|pwned|specialatends/" , $result) ) {
$smarty->assign('pwd_show_policy_onerror', false);
} else {
$smarty->assign('pwd_show_policy_onerror', true);
}
}
self::smarty_assign_variable($smarty, $pwd_policy_config);

// send policy to a JSON object usable in javascript
Expand Down
4 changes: 2 additions & 2 deletions src/ppolicy/html/policy.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{if $pwd_show_policy === "onerror" and !$pwd_show_policy_onerror }
{else}
{if ($pwd_show_policy === "always") || ($pwd_show_policy === "onerror" && $resetpasswordresult && $resetpasswordresult !== "passwordchanged") }
<div class="ppolicy alert shadow alert-warning">
{$msg_policy|unescape: "html" nofilter}
<ul class="fa-ul text-left">
Expand Down Expand Up @@ -128,3 +127,4 @@
</div>
{/if}
<div id="json-policy" data-policy='{$json_policy}'></div>
<div id="resetpasswordresult" data-result='{$resetpasswordresult}'></div>
13 changes: 12 additions & 1 deletion src/ppolicy/js/ppolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,18 @@
};
return $(document).trigger(e, info);
};
if ( (local_policy != null) && $('#newpassword').length) {
var resetpasswordresult = $("#resetpasswordresult").data('result');
if ( (local_policy != null) &&
(
local_policy.pwd_show_policy == "always"
||
(
local_policy.pwd_show_policy == "onerror" &&
resetpasswordresult != "" &&
resetpasswordresult != "passwordchanged"
)
) &&
$('#newpassword').length) {
checkpassword('');
$('#newpassword').keyup(function(e) {
checkpassword(e.target.value);
Expand Down
64 changes: 0 additions & 64 deletions tests/Ltb/PpolicyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,6 @@ public function test_smarty_assign_ppolicy()
$smarty->shouldreceive('assign')
->once()
->with("pwd_show_policy", $pwd_show_policy );
$smarty->shouldreceive('assign')
->once()
->with("pwd_show_policy_onerror", true );

foreach ($pwd_policy_config as $param => $value) {
if( isset($value) )
Expand All @@ -368,65 +365,4 @@ public function test_smarty_assign_ppolicy()

}

public function test_smarty_assign_ppolicy_show_policy_onerror()
{

$pwd_policy_config = array();

$smarty = Mockery::mock('Smarty');
$pwd_show_policy_pos = "above";
$pwd_show_policy = "onerror";
$result = "forbiddenchars";

$smarty->shouldreceive('assign')
->once()
->with("pwd_show_policy_pos", $pwd_show_policy_pos );
$smarty->shouldreceive('assign')
->once()
->with("pwd_show_policy", $pwd_show_policy );
$smarty->shouldreceive('assign')
->twice()
->with("pwd_show_policy_onerror", true );

$smarty->shouldreceive('assign')
->once()
->with("json_policy", base64_encode(json_encode( $pwd_policy_config )) );

\Ltb\Ppolicy::smarty_assign_ppolicy($smarty, $pwd_show_policy_pos, $pwd_show_policy, $result, $pwd_policy_config);

$this->assertNotNull($smarty, "smarty variable is null while testing smarty_assign_ppolicy" );

}

public function test_smarty_assign_ppolicy_show_policy_onerror_dummy()
{

$pwd_policy_config = array();

$smarty = Mockery::mock('Smarty');
$pwd_show_policy_pos = "above";
$pwd_show_policy = "onerror";
$result = "dummy";

$smarty->shouldreceive('assign')
->once()
->with("pwd_show_policy_pos", $pwd_show_policy_pos );
$smarty->shouldreceive('assign')
->once()
->with("pwd_show_policy", $pwd_show_policy );
$smarty->shouldreceive('assign')
->with("pwd_show_policy_onerror", true );
$smarty->shouldreceive('assign')
->with("pwd_show_policy_onerror", false );

$smarty->shouldreceive('assign')
->once()
->with("json_policy", base64_encode(json_encode( $pwd_policy_config )) );

\Ltb\Ppolicy::smarty_assign_ppolicy($smarty, $pwd_show_policy_pos, $pwd_show_policy, $result, $pwd_policy_config);

$this->assertNotNull($smarty, "smarty variable is null while testing smarty_assign_ppolicy" );

}

}