Hiding login link when user is logged in - spring-boot

I'm almost finished with a project of mine (bare with me I'm a beginner). I want to hide the login link when a role (admin or user) is logged into database. I also want to display a link called "add grade" only when Admin(Manager) is logged in. I am working with spring boot, thymeleaf, spring security5 and h2 & jdbc.
To summarize I want to hide or show HTML based on user's role
UPDATE: it works when I use the <div sec:authorize... for "add grade" link. Now just trying to figure how to hide login link when any role is logged in.

This is my typical code for either including or not including in a navbar:
<li th:ref="navbar-item" sec:authorize="!isAuthenticated()">
<a th:text="'Login'" th:href="#{/login}"/>
</li>
If you mean don't include by "hide", wrap your link in a th:block.
<th:block sec:authorize="!isAuthenticated()">
<a th:text="'Login'" th:href="#{/login}"/>
</th:block>

Related

how to count a calling route from server in laravel

Is there any ways to count a special route from another folder in server when it is calling in Laravel project?
For more information, I have below link in my laravel project:
The application.apk in in Android folder in server.
<li>
<i class="fab fa-android" aria-hidden="true" style="font-size: 20px;"></i><span>get android app</span>
</li>
how can I count number clicks on this link?
I think you could add a special class that on click, it sums the click calling via Ajax a function inside a controller of laravel. Then it will sum that click wherever you want.

How do I hide login link and show logout link in homepage navbar once user logs in and gets re-directed to homepage?

I'm working on a Spring boot based web application and the homepage contains a boostrap navbar with Login and Register link.
Once user logs in (by clicking login link from homepage), they will be re-directed to home page again (unless they visit any other link before spring security kicks in for A&A). On re-direct, I want to hide login and register links from the navbar and show logout link in their place. Becuase I want to insert the navbar in all the pages of application.
I want to know what is the best/standard way of doing this when the requirement is re-direction to same page.
One solution that I can think of is to check and obtain a user-principal object from spring security, pass it to thymeleaf template and check that if userprincipal object is present in the request attribute to the thymeleaf template, that means a user has logged in and I can then hide(not-render) login & register links and show(render) logout link. If not, show login & register links and hide logout link. I'm wondering, is this a correct way to do so? This feels like a hack to me and hence want to know if there is any standard way of doing this.
There is a Thymeleaf Spring Security extension that you can use:
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
Add the namespace
<html xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
And then you can use it:
<li sec:authorize="!isAuthenticated()" class="nav-item">
<a class="btn btn-outline-light" th:href="#{/login}">Login</a>
</li>
<li sec:authorize="isAuthenticated()" class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false" sec:authentication="name">
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="pl-3" th:href="#{/password}">Passwort ändern</a>
<div class="dropdown-divider"></div>
<a class="pl-3" th:href="#{/logout}">Logout</a>
</div>
</li>
Please find the whole documentation here:
https://github.com/thymeleaf/thymeleaf-extras-springsecurity

Spring MVC 4 Site Navigation

I am starting to develop a website using Spring MVC 4. I'd like my website to have a top-navigation. When a user hovers over the top-navigation I want them to see a list of the pages that they have access to.
How do I achieve this in a Spring MVC 4 best-practice way?
To illustrate my example, imagine the following:
<ul id='menu-nav'>
<li><a href='homeURL'>Home</a></li>
<li><a href='page1URL'>Page 1</a></li>
<li><a href='page2URL'>Page 2</a></li>
</ul>
Above is a list of all the pages in my very limited website. Once each user logs in, I want them to only be able to see the links to the pages that they have access to.
So, as an example, a user logging in with ADMIN rights would see ALL the links. But a user who DOES NOT have ADMIN rights would only see links to the Home Page and Page 1.
Can anyone suggest a way to implement this?
I think this should work :
<ul id='menu-nav'>
<li><a href='homeURL'>Home</a></li>
<li><a href='page1URL'>Page 1</a></li>
<!-- For many roles -->
<!-- <security:authorize access="hasAnyRole('ADMIN', 'USER')"> -->
<!-- For one role -->
<security:authorize access="hasRole('ADMIN')">
<li><a href='page2URL'>Page 2</a></li>
</security:authorize>
</ul>
Check this answer : https://stackoverflow.com/a/11469342/8800147

CKEditor : Code Snippet in Ckeditor not working with Laravel 5.3

Need to show saved Code Snippet on CKEditor for editing purpose.
I am using
Code Snippet along with Ckeditor at Laravel 5.3
Everything is OK. I can add Code and upload code in Database. Code also shown in the Target Page.
When I need to edit post, I get the previously uploaded data from the Database to the textarea. Inside the textarea Code Snippet does not show. Here's an Example...
I uploaded this code
<div class="col-md-5 flex-center mainheadright2">
<nav class="nav nav-inline">
<a class="nav-link" href="#">Get Full Access</a>
<a class="nav-link" href="#">Hire Me</a>
</nav>
</div>
While uploading this Code shows properly in the textarea. Also shows properly in Target Page. But while I get this Code again in the textarea to edit, it shows the following.
Get Full Access Hire Me
I want to get code as snippet every time I want to edit post.
What should I do?

Dropdown login form without extensions

First of all, I'm starting with Joomla 3. I have a main menu with a login item and I want to dropdown the login form when this item is clicked, something like login on dropbox site.
I try hot login extension but not working well for me.
UPDATE
I create a new postion in my XML file called 'login'
<positions>
<position>login</position>
And add this to the index.php
<div class="span7">
<jdoc:include type="modules" name="menu" style="none" />
<jdoc:include type="modules" name="login" style="none" />
</div>
Finally, in the panel, I set to the Login Form module the login postion.
Now, my DOM is look like this:
<div class="span7">
<ul class="nav menu">Menu itens...</ul>
<form id="login-form">...</form>
</div>
How can I set the login form to open when the user click in one of the menu items?
Depending on the template, there are different methods. For example with Yootheme templates, you need to open the Login module in the Module Manager and set the position to "menu". With Rockettheme, you can set a module or a module position to a specific menu item via the Menu Manager.
Have a look at he demo site for the template you download and read any documentation as it will help.

Resources