mirror of
https://github.com/tim-krehan/shopping-list.git
synced 2024-11-23 22:30:41 +01:00
implemented full settings functionality
This commit is contained in:
parent
a73628d769
commit
43c21c010e
4 changed files with 103 additions and 7 deletions
|
@ -1,4 +1,6 @@
|
|||
$(document).ready(function () {
|
||||
$(".user-input").on("input", checkUserStrings);
|
||||
$("#userSaveButton").click(userChange);
|
||||
$(".password-input").on("input", checkPasswordStrings);
|
||||
$("#passwordSaveButton").click(savePassword);
|
||||
$("#export-recipe-button").click(exportRecipe);
|
||||
|
@ -46,6 +48,34 @@ $(document).ready(function () {
|
|||
});
|
||||
});
|
||||
|
||||
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").attr("disabled", false);
|
||||
|
@ -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) {
|
||||
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
|
||||
var downloadAnchorNode = document.createElement('a');
|
||||
|
|
|
@ -12,14 +12,14 @@
|
|||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" id="userPrepend">Benutzername</span>
|
||||
</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 class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" id="mailPrepend">Mail</span>
|
||||
</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 class="input-group mb-3">
|
||||
|
@ -28,7 +28,7 @@
|
|||
</div>
|
||||
<input type="text" class="form-control" value="<?php echo $user->last_login; ?>" aria-label="login" aria-describedby="loginPrepend" readonly>
|
||||
</div>
|
||||
<button class="btn btn-primary" id="userSaveButton">Speichern</button>
|
||||
<button class="btn btn-primary disabled" id="userSaveButton" disabled>Speichern</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -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){
|
||||
include $_SESSION["docroot"].'/php/connect.php';
|
||||
$result = $mysqli->query("UPDATE `users` SET `theme` = '$theme' WHERE `users`.`uid` = $this->uid;");
|
||||
|
|
|
@ -14,6 +14,13 @@
|
|||
$user->change_theme($_POST["theme"]);
|
||||
break;
|
||||
|
||||
case 'change-mail':
|
||||
$user->change_mail($_POST["mail"]);
|
||||
break;
|
||||
|
||||
case 'change-username':
|
||||
$user->change_username($_POST["username"]);
|
||||
break;
|
||||
|
||||
case 'new':
|
||||
$user->new($_POST["username"], $_POST["passwd"]);
|
||||
|
|
Loading…
Reference in a new issue