implemented full settings functionality

This commit is contained in:
Tim Krehan 2019-05-21 10:28:07 +02:00
parent a73628d769
commit 43c21c010e
4 changed files with 103 additions and 7 deletions

View file

@ -1,4 +1,6 @@
$(document).ready(function () { $(document).ready(function () {
$(".user-input").on("input", checkUserStrings);
$("#userSaveButton").click(userChange);
$(".password-input").on("input", checkPasswordStrings); $(".password-input").on("input", checkPasswordStrings);
$("#passwordSaveButton").click(savePassword); $("#passwordSaveButton").click(savePassword);
$("#export-recipe-button").click(exportRecipe); $("#export-recipe-button").click(exportRecipe);
@ -46,18 +48,46 @@ $(document).ready(function () {
}); });
}); });
function themeChange(){ function userChange() {
var mail = $('.user-input.is-valid[aria-label="email"]').val();
var userName = $('.user-input.is-valid[aria-label="Username"]').val();
if(mail != null){
$.post(
"/api/user/change-mail",
{
mail: mail
},
function(){
window.location.href = window.location.href;
}
)
}
if (userName != null) {
$.post(
"/api/user/change-username",
{
username: userName
},
function () {
window.location.href = window.location.href;
}
)
}
}
function themeChange() {
$("#themeSaveButton").removeClass("disabled"); $("#themeSaveButton").removeClass("disabled");
$("#themeSaveButton").attr("disabled", false); $("#themeSaveButton").attr("disabled", false);
} }
function changeTheme() { function changeTheme() {
$.post( $.post(
"/api/user/change-theme", "/api/user/change-theme",
{ {
theme: $('#changeThemePrepend option:selected').val() theme: $('#changeThemePrepend option:selected').val()
}, },
function(){ function () {
window.location.href = window.location.href; window.location.href = window.location.href;
} }
); );
@ -113,6 +143,42 @@ function checkPasswordStrings() {
} }
} }
function checkUserStrings() {
switch ($(this).attr("aria-label")) {
case "Username":
if ($(this).val().length >= 3) {
$("#userSaveButton").attr("disabled", false);
$("#userSaveButton").removeClass("disabled");
$(this).removeClass("is-invalid");
$(this).addClass("is-valid");
}
else {
$("#userSaveButton").attr("disabled", true);
$("#userSaveButton").addClass("disabled");
$(this).addClass("is-invalid");
$(this).removeClass("is-valid");
}
break;
case "email":
mailRegEx = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (($(this).val().length > 5) && (mailRegEx.exec($(this).val()) !== null)) {
$("#userSaveButton").attr("disabled", false);
$("#userSaveButton").removeClass("disabled");
$(this).removeClass("is-invalid");
$(this).addClass("is-valid");
}
else {
$("#userSaveButton").attr("disabled", true);
$("#userSaveButton").addClass("disabled");
$(this).addClass("is-invalid");
$(this).removeClass("is-valid");
}
break;
default:
break;
}
}
function downloadObjectAsJson(exportObj, exportName) { function downloadObjectAsJson(exportObj, exportName) {
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj)); var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
var downloadAnchorNode = document.createElement('a'); var downloadAnchorNode = document.createElement('a');

View file

@ -12,14 +12,14 @@
<div class="input-group-prepend"> <div class="input-group-prepend">
<span class="input-group-text" id="userPrepend">Benutzername</span> <span class="input-group-text" id="userPrepend">Benutzername</span>
</div> </div>
<input type="text" class="form-control" placeholder="<?php echo $user->username; ?>" aria-label="Username" aria-describedby="userPrepend"> <input type="text" class="user-input form-control" placeholder="<?php echo $user->username; ?>" aria-label="Username" aria-describedby="userPrepend">
</div> </div>
<div class="input-group mb-3"> <div class="input-group mb-3">
<div class="input-group-prepend"> <div class="input-group-prepend">
<span class="input-group-text" id="mailPrepend">Mail</span> <span class="input-group-text" id="mailPrepend">Mail</span>
</div> </div>
<input type="email" class="form-control" placeholder="<?php echo $user->email; ?>" aria-label="email" aria-describedby="mailPrepend"> <input type="email" class="user-input form-control" placeholder="<?php echo $user->email; ?>" aria-label="email" aria-describedby="mailPrepend">
</div> </div>
<div class="input-group mb-3"> <div class="input-group mb-3">
@ -28,7 +28,7 @@
</div> </div>
<input type="text" class="form-control" value="<?php echo $user->last_login; ?>" aria-label="login" aria-describedby="loginPrepend" readonly> <input type="text" class="form-control" value="<?php echo $user->last_login; ?>" aria-label="login" aria-describedby="loginPrepend" readonly>
</div> </div>
<button class="btn btn-primary" id="userSaveButton">Speichern</button> <button class="btn btn-primary disabled" id="userSaveButton" disabled>Speichern</button>
</div> </div>
</div> </div>

View file

@ -34,6 +34,29 @@
} }
} }
function change_mail($mailaddress){
include $_SESSION["docroot"].'/php/hash.php';
include $_SESSION["docroot"].'/php/connect.php';
$this->mail = $mailaddress;
$result = $mysqli->query("UPDATE `users` SET `email` = '$mailaddress' WHERE `users`.`uid` = $this->uid;");
$mysqli->close();
}
function change_username($newname){
include $_SESSION["docroot"].'/php/hash.php';
include $_SESSION["docroot"].'/php/connect.php';
$this->username = $newname;
$result = $mysqli->query("SELECT * WHERE `username` = $this->username;");
if($result->num_rows==0){
$result = $mysqli->query("UPDATE `users` SET `username` = '$newname' WHERE `users`.`uid` = $this->uid;");
print_r("0");
}
else{
print_r("1");
}
$mysqli->close();
}
function change_theme($theme){ function change_theme($theme){
include $_SESSION["docroot"].'/php/connect.php'; include $_SESSION["docroot"].'/php/connect.php';
$result = $mysqli->query("UPDATE `users` SET `theme` = '$theme' WHERE `users`.`uid` = $this->uid;"); $result = $mysqli->query("UPDATE `users` SET `theme` = '$theme' WHERE `users`.`uid` = $this->uid;");

View file

@ -13,7 +13,14 @@
case 'change-theme': case 'change-theme':
$user->change_theme($_POST["theme"]); $user->change_theme($_POST["theme"]);
break; break;
case 'change-mail':
$user->change_mail($_POST["mail"]);
break;
case 'change-username':
$user->change_username($_POST["username"]);
break;
case 'new': case 'new':
$user->new($_POST["username"], $_POST["passwd"]); $user->new($_POST["username"], $_POST["passwd"]);