aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/plugs/ensure_user_key_plug.ex10
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/auth_controller.ex2
-rw-r--r--lib/pleroma/web/oauth/oauth_controller.ex21
-rw-r--r--lib/pleroma/web/router.ex4
-rw-r--r--lib/pleroma/web/templates/layout/app.html.eex219
-rw-r--r--lib/pleroma/web/templates/o_auth/o_auth/show.html.eex60
6 files changed, 67 insertions, 249 deletions
diff --git a/lib/pleroma/plugs/ensure_user_key_plug.ex b/lib/pleroma/plugs/ensure_user_key_plug.ex
index 9795cdbde..470fe0d95 100644
--- a/lib/pleroma/plugs/ensure_user_key_plug.ex
+++ b/lib/pleroma/plugs/ensure_user_key_plug.ex
@@ -3,6 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Plugs.EnsureUserKeyPlug do
+ alias Pleroma.User
import Plug.Conn
def init(opts) do
@@ -12,7 +13,12 @@ defmodule Pleroma.Plugs.EnsureUserKeyPlug do
def call(%{assigns: %{user: _}} = conn, _), do: conn
def call(conn, _) do
- conn
- |> assign(:user, nil)
+ with user_id <- get_session(conn, :user_id),
+ true <- is_binary(user_id),
+ %User{} = user <- User.get_by_id(user_id) do
+ assign(conn, :user, user)
+ else
+ _ -> assign(conn, :user, nil)
+ end
end
end
diff --git a/lib/pleroma/web/mastodon_api/controllers/auth_controller.ex b/lib/pleroma/web/mastodon_api/controllers/auth_controller.ex
index 753b3db3e..f856019c8 100644
--- a/lib/pleroma/web/mastodon_api/controllers/auth_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/auth_controller.ex
@@ -18,7 +18,7 @@ defmodule Pleroma.Web.MastodonAPI.AuthController do
@local_mastodon_name "Mastodon-Local"
@doc "GET /web/login"
- def login(%{assigns: %{user: %User{}}} = conn, _params) do
+ def login(%{assigns: %{user: %User{}, token: _}} = conn, _params) do
redirect(conn, to: local_mastodon_root_path(conn))
end
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex
index 7683589cf..5c93f96f1 100644
--- a/lib/pleroma/web/oauth/oauth_controller.ex
+++ b/lib/pleroma/web/oauth/oauth_controller.ex
@@ -76,8 +76,17 @@ defmodule Pleroma.Web.OAuth.OAuthController do
available_scopes = (app && app.scopes) || []
scopes = Scopes.fetch_scopes(params, available_scopes)
+ user =
+ with %{assigns: %{user: %User{} = user}} <- conn do
+ user
+ else
+ _ -> nil
+ end
+
# Note: `params` might differ from `conn.params`; use `@params` not `@conn.params` in template
render(conn, Authenticator.auth_template(), %{
+ app: app && Map.delete(app, :client_secret),
+ user: user,
response_type: params["response_type"],
client_id: params["client_id"],
available_scopes: available_scopes,
@@ -121,11 +130,13 @@ defmodule Pleroma.Web.OAuth.OAuthController do
end
end
- def create_authorization(
- %Plug.Conn{} = conn,
- %{"authorization" => _} = params,
- opts \\ []
- ) do
+ def create_authorization(_, _, opts \\ [])
+
+ def create_authorization(%Plug.Conn{assigns: %{user: %User{} = user}} = conn, params, []) do
+ create_authorization(conn, params, user: user)
+ end
+
+ def create_authorization(%Plug.Conn{} = conn, %{"authorization" => _} = params, opts) do
with {:ok, auth, user} <- do_create_authorization(conn, params, opts[:user]),
{:mfa_required, _, _, false} <- {:mfa_required, user, auth, MFA.require?(user)} do
after_create_authorization(conn, auth, params)
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 386308362..bb74affa3 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -276,11 +276,11 @@ defmodule Pleroma.Web.Router do
scope "/oauth", Pleroma.Web.OAuth do
scope [] do
- pipe_through(:oauth)
+ pipe_through([:oauth, :after_auth])
get("/authorize", OAuthController, :authorize)
+ post("/authorize", OAuthController, :create_authorization)
end
- post("/authorize", OAuthController, :create_authorization)
post("/token", OAuthController, :token_exchange)
post("/revoke", OAuthController, :token_revoke)
get("/registration_details", OAuthController, :registration_details)
diff --git a/lib/pleroma/web/templates/layout/app.html.eex b/lib/pleroma/web/templates/layout/app.html.eex
index 5836ec1e0..7bc81ddaa 100644
--- a/lib/pleroma/web/templates/layout/app.html.eex
+++ b/lib/pleroma/web/templates/layout/app.html.eex
@@ -6,224 +6,7 @@
<title>
<%= Pleroma.Config.get([:instance, :name]) %>
</title>
- <style>
- body {
- background-color: #121a24;
- font-family: sans-serif;
- color: #b9b9ba;
- text-align: center;
- }
-
- .container {
- max-width: 420px;
- padding: 20px;
- background-color: #182230;
- border-radius: 4px;
- margin: auto;
- margin-top: 10vh;
- box-shadow: 0 1px 4px 0px rgba(0, 0, 0, 0.5);
- }
-
- h1 {
- margin: 0;
- font-size: 24px;
- }
-
- h2 {
- color: #b9b9ba;
- font-weight: normal;
- font-size: 18px;
- margin-bottom: 20px;
- }
-
- a {
- color: color: #d8a070;
- text-decoration: none;
- }
-
- form {
- width: 100%;
- }
-
- .input {
- text-align: left;
- color: #89898a;
- display: flex;
- flex-direction: column;
- }
-
- input {
- box-sizing: content-box;
- padding: 10px;
- margin-top: 5px;
- margin-bottom: 10px;
- background-color: #121a24;
- color: #b9b9ba;
- border: 0;
- transition-property: border-bottom;
- transition-duration: 0.35s;
- border-bottom: 2px solid #2a384a;
- font-size: 14px;
- }
-
- .scopes-input {
- display: flex;
- flex-direction: column;
- margin-top: 1em;
- text-align: left;
- color: #89898a;
- }
-
- .scopes-input label:first-child {
- height: 2em;
- }
-
- .scopes {
- display: flex;
- flex-wrap: wrap;
- text-align: left;
- color: #b9b9ba;
- }
-
- .scope {
- display: flex;
- flex-basis: 100%;
- height: 2em;
- align-items: center;
- }
-
- .scope:before {
- color: #b9b9ba;
- content: "✔\fe0e";
- margin-left: 1em;
- margin-right: 1em;
- }
-
- [type="checkbox"] + label {
- display: none;
- cursor: pointer;
- margin: 0.5em;
- }
-
- [type="checkbox"] {
- display: none;
- }
-
- [type="checkbox"] + label:before {
- cursor: pointer;
- display: inline-block;
- color: white;
- background-color: #121a24;
- border: 4px solid #121a24;
- box-shadow: 0px 0px 1px 0 #d8a070;
- box-sizing: border-box;
- width: 1.2em;
- height: 1.2em;
- margin-right: 1.0em;
- content: "";
- transition-property: background-color;
- transition-duration: 0.35s;
- color: #121a24;
- margin-bottom: -0.2em;
- border-radius: 2px;
- }
-
- [type="checkbox"]:checked + label:before {
- background-color: #d8a070;
- }
-
- input:focus {
- outline: none;
- border-bottom: 2px solid #d8a070;
- }
-
- button {
- box-sizing: border-box;
- width: 100%;
- background-color: #1c2a3a;
- color: #b9b9ba;
- border-radius: 4px;
- border: none;
- padding: 10px;
- margin-top: 20px;
- margin-bottom: 20px;
- text-transform: uppercase;
- font-size: 16px;
- box-shadow: 0px 0px 2px 0px black,
- 0px 1px 0px 0px rgba(255, 255, 255, 0.2) inset,
- 0px -1px 0px 0px rgba(0, 0, 0, 0.2) inset;
- }
-
- button:hover {
- cursor: pointer;
- box-shadow: 0px 0px 0px 1px #d8a070,
- 0px 1px 0px 0px rgba(255, 255, 255, 0.2) inset,
- 0px -1px 0px 0px rgba(0, 0, 0, 0.2) inset;
- }
-
- .alert-danger {
- box-sizing: border-box;
- width: 100%;
- background-color: #931014;
- border: 1px solid #a06060;
- border-radius: 4px;
- padding: 10px;
- margin-top: 20px;
- font-weight: 500;
- font-size: 16px;
- }
-
- .alert-info {
- box-sizing: border-box;
- width: 100%;
- border-radius: 4px;
- border: 1px solid #7d796a;
- padding: 10px;
- margin-top: 20px;
- font-weight: 500;
- font-size: 16px;
- }
-
- @media all and (max-width: 440px) {
- .container {
- margin-top: 0
- }
-
- .scope {
- flex-basis: 0%;
- }
-
- .scope:before {
- content: "";
- margin-left: 0em;
- margin-right: 1em;
- }
-
- .scope:first-child:before {
- margin-left: 1em;
- content: "✔\fe0e";
- }
-
- .scope:after {
- content: ",";
- }
-
- .scope:last-child:after {
- content: "";
- }
- }
- .form-row {
- display: flex;
- }
- .form-row > label {
- text-align: left;
- line-height: 47px;
- flex: 1;
- }
- .form-row > input {
- flex: 2;
- }
- </style>
+ <link rel="stylesheet" href="/instance/static.css">
</head>
<body>
<div class="container">
diff --git a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex
index b17142ff8..d7efbf184 100644
--- a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex
+++ b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex
@@ -5,32 +5,51 @@
<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
<% end %>
-<h2>OAuth Authorization</h2>
<%= form_for @conn, o_auth_path(@conn, :authorize), [as: "authorization"], fn f -> %>
-<%= if @params["registration"] in ["true", true] do %>
- <h3>This is the first time you visit! Please enter your Pleroma handle.</h3>
- <p>Choose carefully! You won't be able to change this later. You will be able to change your display name, though.</p>
- <div class="input">
- <%= label f, :nickname, "Pleroma Handle" %>
- <%= text_input f, :nickname, placeholder: "lain" %>
+<%= if @user do %>
+ <div class="account-header">
+ <div class="avatar">
+ <img src="<%= Pleroma.User.avatar_url(@user) %>">
+ </div>
+ <div class="name">
+ Signed in as:
+ <div class="username">@<%= @user.nickname %></div>
+ </div>
</div>
- <%= hidden_input f, :name, value: @params["name"] %>
- <%= hidden_input f, :password, value: @params["password"] %>
- <br>
-<% else %>
- <div class="input">
- <%= label f, :name, "Username" %>
- <%= text_input f, :name %>
- </div>
- <div class="input">
- <%= label f, :password, "Password" %>
- <%= password_input f, :password %>
- </div>
- <%= submit "Log In" %>
+<% end %>
+
+<%= if @app do %>
+ <p>Application <strong><%= @app.client_name %></strong> is requesting access to your account.</p>
<%= render @view_module, "_scopes.html", Map.merge(assigns, %{form: f}) %>
<% end %>
+<%= if @user do %>
+ <%= submit "Authorize" %>
+<% else %>
+ <%= if @params["registration"] in ["true", true] do %>
+ <h3>This is the first time you visit! Please enter your Pleroma handle.</h3>
+ <p>Choose carefully! You won't be able to change this later. You will be able to change your display name, though.</p>
+ <div class="input">
+ <%= label f, :nickname, "Pleroma Handle" %>
+ <%= text_input f, :nickname, placeholder: "lain" %>
+ </div>
+ <%= hidden_input f, :name, value: @params["name"] %>
+ <%= hidden_input f, :password, value: @params["password"] %>
+ <br>
+ <% else %>
+ <div class="input">
+ <%= label f, :name, "Username" %>
+ <%= text_input f, :name %>
+ </div>
+ <div class="input">
+ <%= label f, :password, "Password" %>
+ <%= password_input f, :password %>
+ </div>
+ <%= submit "Log In" %>
+ <% end %>
+<% end %>
+
<%= hidden_input f, :client_id, value: @client_id %>
<%= hidden_input f, :response_type, value: @response_type %>
<%= hidden_input f, :redirect_uri, value: @redirect_uri %>
@@ -40,4 +59,3 @@
<%= if Pleroma.Config.oauth_consumer_enabled?() do %>
<%= render @view_module, Pleroma.Web.Auth.Authenticator.oauth_consumer_template(), assigns %>
<% end %>
-