Commit 7e174459 authored by s7_spruge_k's avatar s7_spruge_k
Browse files

Merge branch 'master' into 'calendar-controller'

Master

See merge request s7_spruge_k/calendar!12
parents 3f68917f 99e7ad0d
......@@ -31,4 +31,7 @@ db.lock.db
.vscode/
### MAC files ###
.DS_Store
\ No newline at end of file
.DS_Store
.DS_Store
db.h2.db
db.h2.db.mv.db
package com.example.calendar.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
......@@ -55,6 +57,16 @@ public class UserController {
@GetMapping({"/", "/welcome"})
public String welcome(Model model) {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof UserDetails) {
String username = ((UserDetails)principal).getUsername();
System.out.println(username);
} else {
String username = principal.toString();
System.out.println(username);
}
return "welcome";
}
}
\ No newline at end of file
......@@ -12,5 +12,5 @@ import com.example.calendar.models.Event;
@Repository
public interface EventRepo extends CrudRepository<Event, Integer> {
ArrayList<Event> findAllByCalendar(Calendar calendar);
ArrayList<Event> findAllByLocalDate(LocalDate localDate);
ArrayList<Event> findAllByStartDate(LocalDate startDate);
}
......@@ -14,26 +14,33 @@
<body>
<div class="container">
<div class="container w-50">
<form action="#" method="POST" th:action="@{/login}" class="form-signin">
<h2 class="form-heading">Log in</h2>
<br> <h2 class="form-heading text-center">Log in to Your SimpleCal</h2> <br>
<div class="form-group">
<div class="alert alert-danger" th:if="${message}">
<p th:text="${message}"></p>
</div>
<input name="username" type="text" class="form-control" placeholder="Username"
autofocus="true"/>
<input name="password" type="password" class="form-control" placeholder="Password"/>
<br>
<input name="password" type="password" class="form-control" placeholder="Password"/><br>
<div class="alert alert-danger" th:if="${error}">
<p th:text="${error}"></p>
</div>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<button class="btn btn-lg btn-primary btn-block" type="submit">Log In</button>
<h4 class="text-center"><a href="/registration">Create an account</a></h4>
<div class="alert alert-success" th:if="${message}">
<p th:text="${message}"></p>
</div>
<br>
<h6 class="text-center">Not registered? <a href="/registration">Create an account now</a></h6>
</div>
</form>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
......
......@@ -14,27 +14,28 @@
<body>
<div class="container">
<div class="container w-50">
<form action="#" method="POST" th:action="@{/registration}" class="form-signin" th:object="${userForm}">
<h2 class="form-signin-heading">Create your account</h2>
<br> <form action="#" method="POST" th:action="@{/registration}" class="form-signin" th:object="${userForm}">
<h2 class="form-signin-heading text-center">Create your account</h2><br>
<div class="form-group" th:classappend="${#fields.hasErrors('*')} ? 'has-error' : ''">
<input name="username" type="text" class="form-control" placeholder="Username" autofocus="true"/>
<input name="username" type="text" class="form-control" placeholder="Username" autofocus="true"/><br>
<p class="alert alert-danger" th:if="${#fields.hasErrors('username')}" th:errors="*{username}"></p>
</div>
<div class="form-group" th:classappend="${#fields.hasErrors('*')} ? 'has-error' : ''">
<input name="password" type="text" class="form-control" placeholder="Password" autofocus="true"/>
<input name="password" type="text" class="form-control" placeholder="Password" autofocus="true"/><br>
<p class="alert alert-danger" th:if="${#fields.hasErrors('password')}" th:errors="*{password}"></p>
</div>
<div class="form-group" th:classappend="${#fields.hasErrors('*')} ? 'has-error' : ''">
<input name="passwordConfirm" type="text" class="form-control" placeholder="Confirm your password" autofocus="true"/>
<input name="passwordConfirm" type="text" class="form-control" placeholder="Confirm your password" autofocus="true"/><br>
<p class="alert alert-danger" th:if="${#fields.hasErrors('passwordConfirm')}" th:errors="*{passwordConfirm}"></p>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Submit</button>
<button class="btn btn-lg btn-primary btn-block" type="submit">Register</button><br>
<h6 class="text-center">Already have an account? <a href="/login">Log in now</a></h6>
</form>
......
......@@ -11,7 +11,8 @@
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
<h2>Welcome | <a onclick="document.forms['logoutForm'].submit()">Logout</a></h2>
<h2> Welcome, <span th:text="${#request.userPrincipal.name}"></span> | <a onclick="document.forms['logoutForm'].submit()">Logout</a></h2>
<p >
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="@{/resources/js/bootstrap.min.js}"></script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment