|
|
@@ -1,6 +1,7 @@
|
|
|
<?php
|
|
|
|
|
|
Lib::loadClass('RouteBase');
|
|
|
+Lib::loadClass('UI');
|
|
|
|
|
|
class Route_ChangePassword extends RouteBase {
|
|
|
|
|
|
@@ -11,27 +12,22 @@ class Route_ChangePassword extends RouteBase {
|
|
|
}
|
|
|
|
|
|
public function defaultAction() {
|
|
|
- SE_Layout::gora();
|
|
|
- try {
|
|
|
- $action = V::get('action', 'showForm', $_POST);
|
|
|
- switch ($action) {
|
|
|
- case "showForm":
|
|
|
- self::showForm();
|
|
|
- break;
|
|
|
- case "changePassword":
|
|
|
- self::changePassword();
|
|
|
- break;
|
|
|
- default:
|
|
|
- throw new Exception("Błąd formularza");
|
|
|
- }
|
|
|
- } catch (Exception $e) {
|
|
|
- SE_Layout::alert('danger', $e->getMessage());
|
|
|
+ $action = V::get('action', 'showForm', $_POST);
|
|
|
+ switch ($action) {
|
|
|
+ case "showForm": return UI::layout([ $this, 'showFormView' ], [ 'showMenu' => false ]);
|
|
|
+ case "changePassword": return UI::layout([ $this, 'changePasswordPostAction' ], [ 'showMenu' => false ]);
|
|
|
+ default: return UI::layout([ $this, 'nonExistsActionView' ], [ 'showMenu' => false ]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static function showForm() {
|
|
|
+ function nonExistsActionView() {
|
|
|
+ UI::startTag('div', [ 'class' => "col-sm-6 col-sm-offset-3" ]);
|
|
|
+ UI::alert('danger', "Błąd formularza");
|
|
|
+ UI::endTag('div');
|
|
|
+ }
|
|
|
+
|
|
|
+ function showFormView() {
|
|
|
?>
|
|
|
-<div class="container">
|
|
|
<div class="row">
|
|
|
<div class="col-sm-12 text-center">
|
|
|
<h2>Zmiana hasła</h2>
|
|
|
@@ -72,19 +68,17 @@ class Route_ChangePassword extends RouteBase {
|
|
|
</div>
|
|
|
</div>
|
|
|
</form>
|
|
|
-</div>
|
|
|
-<script language="JavaScript">
|
|
|
-<!--
|
|
|
+<script>
|
|
|
$("input[type=password]").keyup(function(){
|
|
|
- var ucase = new RegExp("[A-Z]+");
|
|
|
+ var ucase = new RegExp("[A-Z]+");
|
|
|
var lcase = new RegExp("[a-z]+");
|
|
|
var num = new RegExp("[0-9]+");
|
|
|
- ok = 0;
|
|
|
+ var ok = 0;
|
|
|
|
|
|
if($("#oldPass").val().length > 0){
|
|
|
ok++;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if($("#newPass").val().length >= 8){
|
|
|
$("#8char").removeClass("glyphicon-remove");
|
|
|
$("#8char").addClass("glyphicon-ok");
|
|
|
@@ -95,7 +89,7 @@ $("input[type=password]").keyup(function(){
|
|
|
$("#8char").addClass("glyphicon-remove");
|
|
|
$("#8char").css("color","#FF0004");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if(ucase.test($("#newPass").val())){
|
|
|
$("#ucase").removeClass("glyphicon-remove");
|
|
|
$("#ucase").addClass("glyphicon-ok");
|
|
|
@@ -106,7 +100,7 @@ $("input[type=password]").keyup(function(){
|
|
|
$("#ucase").addClass("glyphicon-remove");
|
|
|
$("#ucase").css("color","#FF0004");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if(lcase.test($("#newPass").val())){
|
|
|
$("#lcase").removeClass("glyphicon-remove");
|
|
|
$("#lcase").addClass("glyphicon-ok");
|
|
|
@@ -117,7 +111,7 @@ $("input[type=password]").keyup(function(){
|
|
|
$("#lcase").addClass("glyphicon-remove");
|
|
|
$("#lcase").css("color","#FF0004");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if(num.test($("#newPass").val())){
|
|
|
$("#num").removeClass("glyphicon-remove");
|
|
|
$("#num").addClass("glyphicon-ok");
|
|
|
@@ -128,7 +122,7 @@ $("input[type=password]").keyup(function(){
|
|
|
$("#num").addClass("glyphicon-remove");
|
|
|
$("#num").css("color","#FF0004");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if(($("#newPass").val() == $("#newPassConfirm").val()) && ($("#newPass").val().length > 0)){
|
|
|
$("#pwmatch").removeClass("glyphicon-remove");
|
|
|
$("#pwmatch").addClass("glyphicon-ok");
|
|
|
@@ -146,24 +140,39 @@ $("input[type=password]").keyup(function(){
|
|
|
document.getElementById('submit').disabled = true;
|
|
|
}
|
|
|
});
|
|
|
--->
|
|
|
</script>
|
|
|
<?php
|
|
|
+ echo UI::h('div', [ 'class' => "col-sm-6 col-sm-offset-3", 'style' => "margin-top:32px" ], [
|
|
|
+ "Wróć do ",
|
|
|
+ UI::h('a', [ 'href' => Router::getRoute('Menu')->getLink() ], "menu"),
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
- private function changePassword() {
|
|
|
- $oldPass = V::get('oldPass', '', $_POST);
|
|
|
- $newPass = V::get('newPass', '', $_POST);
|
|
|
- $newPassConfirm = V::get('newPassConfirm', '', $_POST);
|
|
|
- if (!($oldPass && $newPass && ($newPass == $newPassConfirm))) throw new Exception("Błąd formularza");
|
|
|
-
|
|
|
+ function changePasswordPostAction() {
|
|
|
try {
|
|
|
- $result = User::changePassword($oldPass, $newPass);
|
|
|
- if ($result) SE_Layout::alert('success', "Pomyślnie zmieniono hasło");
|
|
|
- else SE_Layout::alert('warning', "Nie zmieniono hasła");
|
|
|
+ $oldPass = V::get('oldPass', '', $_POST);
|
|
|
+ $newPass = V::get('newPass', '', $_POST);
|
|
|
+ $newPassConfirm = V::get('newPassConfirm', '', $_POST);
|
|
|
+ if (!($oldPass && $newPass && ($newPass == $newPassConfirm))) throw new Exception("Błąd formularza");
|
|
|
+ if ($oldPass == $newPass) throw new Exception("Wprowadź inne hasło niż poprzednio");
|
|
|
+
|
|
|
+ $result = User::changePassword(User::getLogin(), $oldPass, $newPass);
|
|
|
+
|
|
|
+ echo UI::h('div', [ 'class' => "col-sm-6 col-sm-offset-3" ], [
|
|
|
+ ($result)
|
|
|
+ ? UI::h('div', [ 'class' => 'alert alert-success' ], "Pomyślnie zmieniono hasło")
|
|
|
+ : UI::h('div', [ 'class' => 'alert alert-warning' ], "Nie zmieniono hasła"),
|
|
|
+ '<br>',
|
|
|
+ "Wróć do ",
|
|
|
+ UI::h('a', [ 'href' => Router::getRoute('ChangePassword')->getLink() ], "zmiany hasła"),
|
|
|
+ " lub do ",
|
|
|
+ UI::h('a', [ 'href' => Router::getRoute('Menu')->getLink() ], "menu"),
|
|
|
+ ]);
|
|
|
} catch (Exception $e) {
|
|
|
- SE_Layout::alert('danger', $e->getMessage());
|
|
|
- self::showForm();
|
|
|
+ UI::startTag('div', [ 'class' => "col-sm-6 col-sm-offset-3" ]);
|
|
|
+ UI::alert('danger', $e->getMessage());
|
|
|
+ UI::endTag('div');
|
|
|
+ $this->showFormView();
|
|
|
}
|
|
|
}
|
|
|
|