Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117799057
D333.1775265587.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D333.1775265587.diff
View Options
diff --git a/web/controllers/auth_controller.ex b/web/controllers/auth_controller.ex
new file mode 100644
--- /dev/null
+++ b/web/controllers/auth_controller.ex
@@ -0,0 +1,31 @@
+defmodule KolabChat.AuthController do
+ use KolabChat.Web, :controller
+
+ @doc """
+ Handler for the default logon form
+ """
+ def default_callback(conn, params) do
+ %{"logon" => %{"password" => _pass, "username" => user}} = params
+
+ cond do
+ is_nil(user) or user == "" ->
+ conn
+ |> put_flash(:error, gettext("Invalid username"))
+ |> redirect(to: "/")
+ true ->
+ conn
+ |> put_flash(:info, gettext("Successfully authenticated"))
+ |> put_session(:user, user)
+ |> redirect(to: "/")
+ end
+ end
+
+ @doc """
+ Handler for logout action
+ """
+ def logout(conn, _params) do
+ conn
+ |> configure_session(drop: true)
+ |> redirect(to: "/")
+ end
+end
diff --git a/web/controllers/plugs/set_user.ex b/web/controllers/plugs/set_user.ex
new file mode 100644
--- /dev/null
+++ b/web/controllers/plugs/set_user.ex
@@ -0,0 +1,14 @@
+defmodule KolabChat.Plugs.SetUser do
+ import Plug.Conn
+
+ def init(params), do: params
+
+ def call(conn, _params) do
+ cond do
+ user = get_session(conn, :user) ->
+ assign(conn, :user, user)
+ true ->
+ assign(conn, :user, nil)
+ end
+ end
+end
diff --git a/web/router.ex b/web/router.ex
--- a/web/router.ex
+++ b/web/router.ex
@@ -7,6 +7,7 @@
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
+ plug KolabChat.Plugs.SetUser
end
pipeline :api do
@@ -19,6 +20,13 @@
get "/", PageController, :index
end
+ scope "/auth", KolabChat do
+ pipe_through :browser
+
+ post "/default/callback", AuthController, :default_callback
+ get "/logout", AuthController, :logout
+ end
+
# Other scopes may use custom stacks.
# scope "/api", KolabChat do
# pipe_through :api
diff --git a/web/static/css/app.css b/web/static/css/app.css
--- a/web/static/css/app.css
+++ b/web/static/css/app.css
@@ -1 +1,13 @@
-/* This file is for your main application css. */
\ No newline at end of file
+/* This file is for your main application css. */
+
+header form {
+ float: right;
+ text-align: right;
+ margin-top: 15px;
+ margin-right: 55px;
+}
+
+header form input {
+ display: block;
+ margin-bottom: 3px;
+}
diff --git a/web/templates/layout/app.html.eex b/web/templates/layout/app.html.eex
--- a/web/templates/layout/app.html.eex
+++ b/web/templates/layout/app.html.eex
@@ -14,11 +14,19 @@
<body>
<div class="container">
<header class="header">
- <nav role="navigation">
- <ul class="nav nav-pills pull-right">
- <li><a href="/login">Login</a></li>
- </ul>
- </nav>
+ <%= if @conn.assigns[:user] do %>
+ <nav role="navigation">
+ <ul class="nav nav-pills pull-right">
+ <li><%= link gettext("Logout"), to: "/auth/logout" %></li>
+ </ul>
+ </nav>
+ <% else %>
+ <%= form_for @conn, "/auth/default/callback", [as: :logon], fn f -> %>
+ <%= text_input f, :username, placeholder: gettext("Username") %>
+ <%= password_input f, :password, placeholder: gettext("Password") %>
+ <%= submit gettext("Log in"), class: "btn btn-primary" %>
+ <% end %>
+ <% end %>
<span class="logo"></span>
</header>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 4, 1:19 AM (10 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18776838
Default Alt Text
D333.1775265587.diff (3 KB)
Attached To
Mode
D333: T2018: Dummy authentication module
Attached
Detach File
Event Timeline