Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
s7_spruge_k
calendar
Commits
785d6f6d
Commit
785d6f6d
authored
Jun 13, 2019
by
s7_spruge_k
Browse files
Fixed login issue, removed welcome screen
parent
71d71d65
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
40 deletions
+27
-40
src/main/java/com/example/calendar/controller/UserController.java
.../java/com/example/calendar/controller/UserController.java
+27
-16
src/main/resources/templates/welcome.html
src/main/resources/templates/welcome.html
+0
-24
No files found.
src/main/java/com/example/calendar/controller/UserController.java
View file @
785d6f6d
...
...
@@ -25,8 +25,20 @@ public class UserController {
@GetMapping
(
"/registration"
)
public
String
registration
(
Model
model
)
{
Object
principal
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
String
username
=
""
;
if
(
principal
instanceof
UserDetails
)
{
username
=
((
UserDetails
)
principal
).
getUsername
();
}
else
{
username
=
principal
.
toString
();
}
if
(
username
!=
"anonymousUser"
)
return
"redirect:/calendar"
;
model
.
addAttribute
(
"userForm"
,
new
User
());
return
"registration"
;
}
...
...
@@ -41,11 +53,24 @@ public class UserController {
userService
.
save
(
userForm
);
securityService
.
autoLogin
(
userForm
.
getUsername
(),
userForm
.
getPasswordConfirm
());
return
"redirect:/
welcome
"
;
return
"redirect:/
calendar
"
;
}
@GetMapping
(
"/login"
)
public
String
login
(
Model
model
,
String
error
,
String
logout
)
{
Object
principal
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
String
username
=
""
;
if
(
principal
instanceof
UserDetails
)
{
username
=
((
UserDetails
)
principal
).
getUsername
();
}
else
{
username
=
principal
.
toString
();
}
if
(
username
!=
"anonymousUser"
)
return
"redirect:/calendar"
;
if
(
error
!=
null
)
model
.
addAttribute
(
"error"
,
"Your username and password is invalid."
);
...
...
@@ -55,18 +80,4 @@ public class UserController {
return
"login"
;
}
///login POST controller is provided by Spring Security
@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
src/main/resources/templates/welcome.html
deleted
100644 → 0
View file @
71d71d65
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"utf-8"
>
<title>
Create an account
</title>
<link
rel=
"stylesheet"
href=
"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity=
"sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin=
"anonymous"
>
</head>
<body>
<div
class=
"container"
>
<form
id=
"logoutForm"
action=
"#"
method=
"POST"
th:action=
"@{/logout}"
>
<input
type=
"hidden"
name=
"${_csrf.parameterName}"
value=
"${_csrf.token}"
/>
</form>
<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>
<script
src=
"https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity=
"sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin=
"anonymous"
></script>
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity=
"sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin=
"anonymous"
></script>
<script
src=
"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity=
"sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin=
"anonymous"
></script>
</body>
</html>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment