Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #################
- navbar.ftl
- #################
- <#include "security.ftl">
- <#import "login.ftl" as l>
- <nav class="navbar navbar-expand-lg navbar-light bg-light">
- .....
- <div class="navbar-text mr-3"><#if user??>${name}${name}<#else>Please, login</#if></div> <!-- OK -->
- <@l.logout /> <!-- Not OK -->
- <div class="navbar-text mr-3">
- <form action="/logout" method="post">
- <input type="hidden" name="_csrf" value="${_csrf.token}"/>
- <button class="btn btn-primary" type="submit" ><#if user??>Sign Out<#else>Login</#if></button>
- </form>
- </div>
- </nav>
- #################
- security.ftl
- ################
- <#assign
- known = Session.SPRING_SECURITY_CONTEXT??
- >
- <#if known>
- <#assign
- user = Session.SPRING_SECURITY_CONTEXT.authentication.principal
- name = user.getUsername()
- isAdmin = user.isAdmin()
- currentUserId = user.getId()
- >
- <#else>
- <#assign
- name = "unknown"
- isAdmin = false
- currentUserId = -1
- >
- </#if>
- ################
- login.ftl
- ################
- <#macro login path isRegisterForm>
- ....
- </#macro>
- <#macro logout>
- <form action="/logout" method="post">
- <input type="hidden" name="_csrf" value="${_csrf.token}"/>
- <button class="btn btn-primary" type="submit" ><#if user??>Sign Out<#else>Login</#if></button>
- </form>
- </#macro>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement