logged_in? util and format nginx conf
This commit is contained in:
parent
2d3d4bcd58
commit
f5a8a7affc
|
@ -25,15 +25,22 @@ defmodule Forum.Util do
|
|||
@doc """
|
||||
Can current user sudo?
|
||||
"""
|
||||
def is_sudoer?(conn) do
|
||||
def sudoer?(conn) do
|
||||
get_session(conn, :sudoer)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
||||
"""
|
||||
def logged_in?(conn) do
|
||||
get_session(conn, :loggedin)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns true if the current user matches the user -- or the current user can sudo
|
||||
"""
|
||||
def can_edit?(conn, user) do
|
||||
user.name == current_username(conn) or is_sudoer?(conn)
|
||||
user.name == current_username(conn) or sudoer?(conn)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
</div>
|
||||
<div id="navbar" class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<%= if @conn |> Plug.Conn.get_session(:loggedin) do %>
|
||||
<%= if Util.logged_in?(@conn) do %>
|
||||
<li><%= link "home", to: thread_path(@conn, :index) %></li>
|
||||
<li><%= link "new thread", to: thread_path(@conn, :new) %></li>
|
||||
<li><%= link "profile", to: user_path(@conn, :show, Util.current_username(@conn)) %></li>
|
||||
|
@ -58,6 +58,15 @@
|
|||
|
||||
</div> <!-- /container -->
|
||||
|
||||
<footer class="navbar-default navbar-fixed-bottom">
|
||||
<div class="container-fluid">
|
||||
<div class="text-center">
|
||||
<span><a href="https://tilde.team/">tilde.team</a> ~ <a href="https://github.com/tilde-team/forum">source on github</a></span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="<%= static_path(@conn, "/js/app.js") %>"></script>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -11,14 +11,22 @@
|
|||
</div>
|
||||
|
||||
<div class="panel-footer">
|
||||
<div class="pull-right">
|
||||
<a href="#<%= @i %>">permalink</a>
|
||||
<%= if Util.can_edit?(@conn, @post.user) do %>
|
||||
<%= link "edit post", to: post_path(@conn, :edit, @post), class: "btn btn-info btn-xs" %>
|
||||
<%= link "delet this", to: post_path(@conn, :delete, @post), method: :delete, data: [confirm: "are you sure?"], class: "btn btn-danger btn-xs" %>
|
||||
<% end %>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-md-8">
|
||||
<em><a href="<%= user_path(@conn, :show, @post.user.name) %>">~<%= @post.user.name %></a></em> //
|
||||
<small><%= @post.inserted_at |> Util.pp_time %></small>
|
||||
<%= if @post.updated_at > @post.inserted_at do %>
|
||||
<small>(edited <%= @post.updated_at |> Util.pp_time %>)</small>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-md-4 text-right">
|
||||
<a href="#<%= @i %>">permalink</a>
|
||||
<%= if Util.current_username(@conn) == @post.user.name do %>
|
||||
<%= link "edit post", to: post_path(@conn, :edit, @post), class: "btn btn-info btn-xs" %>
|
||||
<%= link "delet this", to: post_path(@conn, :delete, @post), method: :delete, data: [confirm: "are you sure?"], class: "btn btn-danger btn-xs" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<em><a href="<%= user_path(@conn, :show, @post.user.name) %>">~<%= @post.user.name %></a></em> //
|
||||
<small><%= @post.inserted_at |> Util.pp_time %></small>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<%= error_tag f, :name %>
|
||||
</div>
|
||||
|
||||
<%= if Util.is_sudoer?(@conn) do %>
|
||||
<%= if Util.sudoer?(@conn) do %>
|
||||
<div class="form-group">
|
||||
<%= label f, :sticky, "sticky thread?" %>
|
||||
<%= checkbox f, :sticky %>
|
||||
|
|
|
@ -3,13 +3,17 @@
|
|||
<h4><a href="<%= thread_path(@conn, :show, @thread) %>"><%= @thread.name %></a></h4>
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
<%= if Util.can_edit?(@conn, @thread.user) do %>
|
||||
<div class="pull-right">
|
||||
<%= link "edit", to: thread_path(@conn, :edit, @thread), class: "btn btn-info btn-xs" %>
|
||||
<%= link "delete", to: thread_path(@conn, :delete, @thread), method: :delete, data: [confirm: "are you sure?"], class: "btn btn-danger btn-xs" %>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-md-8">
|
||||
by: <a href="<%= user_path(@conn, :show, @thread.user.name) %>"><em>~<%= @thread.user.name %></em></a> // <small>created <%= @thread.inserted_at |> Util.pp_time %></small>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
by: <a href="<%= user_path(@conn, :show, @thread.user.name) %>"><em>~<%= @thread.user.name %></em></a> // <small>created <%= @thread.inserted_at |> Util.pp_time %></small>
|
||||
<div class="col-xs-12 col-md-4 text-right">
|
||||
<%= if Util.can_edit?(@conn, @thread.user) do %>
|
||||
<%= link "edit", to: thread_path(@conn, :edit, @thread), class: "btn btn-info btn-xs" %>
|
||||
<%= link "delete", to: thread_path(@conn, :delete, @thread), method: :delete, data: [confirm: "are you sure?"], class: "btn btn-danger btn-xs" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
34
nginx.conf
34
nginx.conf
|
@ -1,13 +1,14 @@
|
|||
server {
|
||||
listen 80;
|
||||
server_name forum.tilde.team;
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
|
||||
# root /var/www/html/forum.tilde.team;
|
||||
server {
|
||||
listen 443 ssl; # managed by Certbot
|
||||
server_name forum.tilde.team;
|
||||
|
||||
# index index.php;
|
||||
|
||||
server_name forum.tilde.team;
|
||||
|
||||
location / {
|
||||
# try_files $uri $uri/ =404;
|
||||
location / {
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
|
@ -15,7 +16,7 @@ server {
|
|||
proxy_pass http://localhost:4001;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
}
|
||||
}
|
||||
|
||||
location ~* ^.+\.(css|cur|gif|gz|ico|jpg|jpeg|js|png|svg|woff|woff2)$ {
|
||||
root /home/ben/workspace/forum/priv/static;
|
||||
|
@ -24,25 +25,8 @@ server {
|
|||
add_header Cache-Control public;
|
||||
}
|
||||
|
||||
listen 443 ssl; # managed by Certbot
|
||||
ssl_certificate /etc/letsencrypt/live/forum.tilde.team/fullchain.pem; # managed by Certbot
|
||||
ssl_certificate_key /etc/letsencrypt/live/forum.tilde.team/privkey.pem; # managed by Certbot
|
||||
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
|
||||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
|
||||
|
||||
}
|
||||
|
||||
|
||||
server {
|
||||
if ($host = forum.tilde.team) {
|
||||
return 301 https://$host$request_uri;
|
||||
} # managed by Certbot
|
||||
|
||||
|
||||
listen 80;
|
||||
|
||||
server_name forum.tilde.team;
|
||||
return 404; # managed by Certbot
|
||||
|
||||
|
||||
}
|
||||
|
|
Reference in New Issue