userinfo ausgeben

This commit is contained in:
Lukas Nowy 2018-11-20 23:32:20 +01:00
parent 0ba4a11d23
commit 4421f6b307
3 changed files with 44 additions and 25 deletions

View File

@ -1,6 +1,8 @@
$(document).ready(function() { $(document).ready(function() {
refresh(); refresh();
userinfo();
$(document).on("click", ".btn_detail", function() { $(document).on("click", ".btn_detail", function() {
window.location.replace("/shoppinglist_json/" + $(this).closest("tr").attr("id")); window.location.replace("/shoppinglist_json/" + $(this).closest("tr").attr("id"));
}); });
@ -29,8 +31,9 @@ $(document).ready(function() {
} }
}); });
}); });
});
function refresh() { function refresh() {
$("tbody").empty(); $("tbody").empty();
@ -56,5 +59,16 @@ $(document).ready(function() {
} }
} }
}); });
}
function userinfo() {
$.ajax({
type: "GET",
url: "/userinfo_json",
success(data) {
$(".userinfo").empty();
$(".userinfo").append("Logged in as: " + data.profile.displayName);
$(".user_img").attr("src", data.profile.photos[0].value);
} }
}); });
}

View File

@ -134,4 +134,8 @@ router.get("/test1", (req, res) => {
res.render("index1"); res.render("index1");
}); });
router.get("/userinfo_json", (req, res) => {
res.send(req.session.passport.user);
});
module.exports = router; module.exports = router;

View File

@ -12,7 +12,8 @@
<body> <body>
<div class="container"> <div class="container">
<p>Logged in as: testuser1</p> <p class="userinfo">Logged in as: testuser1</p>
<img class="user_img">
<br> <br>
<div class="col s6"> <div class="col s6">
<a href="/logout" class="waves-effect waves-light btn">Logout</a> <a href="/logout" class="waves-effect waves-light btn">Logout</a>