简体   繁体   中英

How can I checked if the visitor is logged in from a plush template? Using the go Buffalo framework

How can I check if a visitor is logged in from within a template using the Go Buffalo web framework? Specifically, I am working on a project that utilizes the Buffalo framework and I need to be able to determine if a user is currently logged in or not, and I would like to do this within one of my templates. Are there any built-in methods or functions provided by Buffalo that can be used to accomplish this task?

I found out that I can use current_user , like this

<div class="auth-center">
  <%= if (current_user) { %>
    <h1><%= current_user.email %></h1>
    <a href="/signout" data-method="delete">sign out</a>
  <% } else { %>
    <a href="/signin" class="btn btn-primary">sign in</a>
    <a href="/users/new" class="btn btn-success">register</a>
  <% } %>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM