Skip to content

Commit

Permalink
Add basic functioning login and logout feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tttzach committed Jun 11, 2020
1 parent 3d72e66 commit 2c553b5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,15 @@ public class AuthenticationServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html");

UserService userService = UserServiceFactory.getUserService();
String redirectUrl = "/index.html";
if (userService.isUserLoggedIn()) {
/*
String userEmail = userService.getCurrentUser().getEmail();
String urlToRedirectToAfterUserLogsOut = "/";
String logoutUrl = userService.createLogoutURL(urlToRedirectToAfterUserLogsOut);
response.getWriter().println("<p>Hello " + userEmail + "!</p>");
response.getWriter().println("<p>Logout <a href=\"" + logoutUrl + "\">here</a>.</p>");
*/
// Create list of podmates

response.getWriter().println("true");
String logoutUrl = userService.createLogoutURL(redirectUrl);
response.getWriter().println("<p>Logout <a href=\"" + logoutUrl + "\">here</a>.");
} else {
/*
String urlToRedirectToAfterUserLogsIn = "/";
String loginUrl = userService.createLoginURL(urlToRedirectToAfterUserLogsIn);
response.getWriter().println("<p>Hello stranger.</p>");
response.getWriter().println("<p>Login <a href=\"" + loginUrl + "\">here</a>.</p>");
*/
response.getWriter().println("false");
String loginUrl = userService.createLoginURL(redirectUrl);
response.getWriter().println("<p>Login <a href=\"" + loginUrl + "\">here</a>.");
}
}

}
2 changes: 1 addition & 1 deletion portfolio/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ <h1>definitely not zachary's website.</h1>
<div class="column-right">
<span>
<div id="greeting-container"></div>
<div id="login-status"></div>
<p class="about-me" onclick="openTab('about-me');">about me
<p class="technical" onclick="openTab('technical');">technical
<p class="personal" onclick="openTab('personal');">personal
Expand All @@ -31,6 +30,7 @@ <h1>definitely not zachary's website.</h1>
<div class="row">
<div id="comments" class="containerTab">
<span onclick="this.parentElement.style.display='none'" class="closebtn">x</span>
<div id="login-status"></div>
<div id="comments-form">
<form action="/new-comment" method="POST">
<p>Type a comment here: <input type="text" name="comment"><input type="submit"/>
Expand Down
10 changes: 4 additions & 6 deletions portfolio/src/main/webapp/libraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,9 @@ function drawCoronavirusChart() {

async function getLoginStatus() {
const response = await fetch('/authentication');
const responseText = await response.text();
const loggedIn = (responseText == 'true');
if (loggedIn) {
document.getElementById('login-status').innerHTML = "<p> You are logged in.";
} else {
document.getElementById('login-status').innerHTML = "<p> You are not logged in.";
const responseHtml = await response.text();
document.getElementById('login-status').innerHTML = responseHtml;
if (responseHtml.includes("Logout")) {
document.getElementById('comments-form').style.display = "block";
}
}
6 changes: 0 additions & 6 deletions portfolio/src/main/webapp/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ function getCommentForm() {

// Fetches comments from the datastore and adds them to the DOM
function loadComments(maxInt) {
/*
fetch('/authentication')
.then(response => (response.text() == 'true'))
.then(loggedIn => {
})*/
const max = maxInt.toString();
fetch('/list-comments?max=' + max)
.then(response => response.json())
Expand Down

0 comments on commit 2c553b5

Please sign in to comment.