aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pleroma/web')
-rw-r--r--lib/pleroma/web/channels/user_socket.ex4
-rw-r--r--lib/pleroma/web/chat_channel.ex1
-rw-r--r--lib/pleroma/web/endpoint.ex6
-rw-r--r--lib/pleroma/web/oauth/fallback_controller.ex12
-rw-r--r--lib/pleroma/web/oauth/oauth_controller.ex5
-rw-r--r--lib/pleroma/web/router.ex1
-rw-r--r--lib/pleroma/web/templates/o_auth/o_auth/show.html.eex2
-rw-r--r--lib/pleroma/web/templates/twitter_api/util/subscribe.html.eex10
-rw-r--r--lib/pleroma/web/twitter_api/controllers/util_controller.ex23
-rw-r--r--lib/pleroma/web/twitter_api/views/user_view.ex1
-rw-r--r--lib/pleroma/web/web_finger/web_finger.ex4
11 files changed, 63 insertions, 6 deletions
diff --git a/lib/pleroma/web/channels/user_socket.ex b/lib/pleroma/web/channels/user_socket.ex
index 4a9bb8e22..f18b3cb80 100644
--- a/lib/pleroma/web/channels/user_socket.ex
+++ b/lib/pleroma/web/channels/user_socket.ex
@@ -5,7 +5,9 @@ defmodule Pleroma.Web.UserSocket do
## Channels
# channel "room:*", Pleroma.Web.RoomChannel
- channel "chat:*", Pleroma.Web.ChatChannel
+ if Application.get_env(:pleroma, :chat) |> Keyword.get(:enabled) do
+ channel "chat:*", Pleroma.Web.ChatChannel
+ end
## Transports
transport :websocket, Phoenix.Transports.WebSocket
diff --git a/lib/pleroma/web/chat_channel.ex b/lib/pleroma/web/chat_channel.ex
index 268bef17d..48a3553bf 100644
--- a/lib/pleroma/web/chat_channel.ex
+++ b/lib/pleroma/web/chat_channel.ex
@@ -24,7 +24,6 @@ defmodule Pleroma.Web.ChatChannel do
end
defmodule Pleroma.Web.ChatChannel.ChatChannelState do
- use Agent
@max_messages 20
def start_link do
diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex
index 725d2ee64..93b37dc74 100644
--- a/lib/pleroma/web/endpoint.ex
+++ b/lib/pleroma/web/endpoint.ex
@@ -1,7 +1,9 @@
defmodule Pleroma.Web.Endpoint do
use Phoenix.Endpoint, otp_app: :pleroma
- socket "/socket", Pleroma.Web.UserSocket
+ if Application.get_env(:pleroma, :chat) |> Keyword.get(:enabled) do
+ socket "/socket", Pleroma.Web.UserSocket
+ end
socket "/api/v1", Pleroma.Web.MastodonAPI.MastodonSocket
# Serve at "/" the static files from "priv/static" directory.
@@ -12,7 +14,7 @@ defmodule Pleroma.Web.Endpoint do
at: "/media", from: "uploads", gzip: false
plug Plug.Static,
at: "/", from: :pleroma,
- only: ~w(index.html static finmoji emoji packs sounds instance sw.js)
+ only: ~w(index.html static finmoji emoji packs sounds images instance sw.js)
# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
diff --git a/lib/pleroma/web/oauth/fallback_controller.ex b/lib/pleroma/web/oauth/fallback_controller.ex
new file mode 100644
index 000000000..daa110532
--- /dev/null
+++ b/lib/pleroma/web/oauth/fallback_controller.ex
@@ -0,0 +1,12 @@
+defmodule Pleroma.Web.OAuth.FallbackController do
+ use Pleroma.Web, :controller
+ alias Pleroma.Web.OAuth.OAuthController
+
+ # No user/password
+ def call(conn, _) do
+ conn
+ |> put_flash(:error, "Invalid Username/Password")
+ |> OAuthController.authorize(conn.params)
+ end
+
+end \ No newline at end of file
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex
index e8483dec0..94318bfa9 100644
--- a/lib/pleroma/web/oauth/oauth_controller.ex
+++ b/lib/pleroma/web/oauth/oauth_controller.ex
@@ -5,6 +5,11 @@ defmodule Pleroma.Web.OAuth.OAuthController do
alias Pleroma.{Repo, User}
alias Comeonin.Pbkdf2
+ plug :fetch_session
+ plug :fetch_flash
+
+ action_fallback Pleroma.Web.OAuth.FallbackController
+
def authorize(conn, params) do
render conn, "show.html", %{
response_type: params["response_type"],
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 63dbd6245..6e9f40955 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -62,6 +62,7 @@ defmodule Pleroma.Web.Router do
pipe_through :pleroma_html
get "/ostatus_subscribe", UtilController, :remote_follow
post "/ostatus_subscribe", UtilController, :do_remote_follow
+ post "/main/ostatus", UtilController, :remote_subscribe
end
scope "/api/pleroma", Pleroma.Web.TwitterAPI do
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 3c6903a16..a7fa7523b 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
@@ -1,3 +1,5 @@
+<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
+<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
<h2>OAuth Authorization</h2>
<%= form_for @conn, o_auth_path(@conn, :authorize), [as: "authorization"], fn f -> %>
<%= label f, :name, "Name" %>
diff --git a/lib/pleroma/web/templates/twitter_api/util/subscribe.html.eex b/lib/pleroma/web/templates/twitter_api/util/subscribe.html.eex
new file mode 100644
index 000000000..f60accebf
--- /dev/null
+++ b/lib/pleroma/web/templates/twitter_api/util/subscribe.html.eex
@@ -0,0 +1,10 @@
+<%= if @error do %>
+ <h2>Error: <%= @error %></h2>
+<% else %>
+ <h2>Remotely follow <%= @nickname %></h2>
+ <%= form_for @conn, util_path(@conn, :remote_subscribe), [as: "user"], fn f -> %>
+ <%= hidden_input f, :nickname, value: @nickname %>
+ <%= text_input f, :profile, placeholder: "Your account ID, e.g. lain@quitter.se" %>
+ <%= submit "Follow" %>
+ <% end %>
+<% end %>
diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
index a1d56e3ab..503719dbf 100644
--- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex
+++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
@@ -3,6 +3,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
require Logger
alias Pleroma.Web
alias Pleroma.Web.OStatus
+ alias Pleroma.Web.WebFinger
alias Comeonin.Pbkdf2
alias Pleroma.Formatter
alias Pleroma.Web.ActivityPub.ActivityPub
@@ -32,6 +33,26 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
json(conn, "ok")
end
+ def remote_subscribe(conn, %{"nickname" => nick, "profile" => _}) do
+ with %User{} = user <- User.get_cached_by_nickname(nick),
+ avatar = User.avatar_url(user) do
+ conn
+ |> render("subscribe.html", %{nickname: nick, avatar: avatar, error: false})
+ else
+ _e -> render(conn, "subscribe.html", %{nickname: nick, avatar: nil, error: "Could not find user"})
+ end
+ end
+ def remote_subscribe(conn, %{"user" => %{"nickname" => nick, "profile" => profile}}) do
+ with {:ok, %{"subscribe_address" => template}} <- WebFinger.finger(profile),
+ %User{ap_id: ap_id} <- User.get_cached_by_nickname(nick) do
+ conn
+ |> Phoenix.Controller.redirect(external: String.replace(template, "{uri}", ap_id))
+ else
+ _e ->
+ render(conn, "subscribe.html", %{nickname: nick, avatar: nil, error: "Something went wrong."})
+ end
+ end
+
def remote_follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do
{err, followee} = OStatus.find_or_make_user(acct)
avatar = User.avatar_url(followee)
@@ -100,7 +121,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
site: %{
name: Keyword.get(@instance, :name),
server: Web.base_url,
- textlimit: Keyword.get(@instance, :limit),
+ textlimit: to_string(Keyword.get(@instance, :limit)),
closed: if(Keyword.get(@instance, :registrations_open), do: "0", else: "1")
}
})
diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex
index 1b995f42f..f49bcc0fb 100644
--- a/lib/pleroma/web/twitter_api/views/user_view.ex
+++ b/lib/pleroma/web/twitter_api/views/user_view.ex
@@ -47,6 +47,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
"statusnet_profile_url" => user.ap_id,
"cover_photo" => User.banner_url(user) |> MediaProxy.url(),
"background_image" => image_url(user.info["background"]) |> MediaProxy.url(),
+ "is_local" => user.local
}
if assigns[:token] do
diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex
index 4ae3eab59..95e717b17 100644
--- a/lib/pleroma/web/web_finger/web_finger.ex
+++ b/lib/pleroma/web/web_finger/web_finger.ex
@@ -69,11 +69,13 @@ defmodule Pleroma.Web.WebFinger do
topic = XML.string_from_xpath(~s{//Link[@rel="http://schemas.google.com/g/2010#updates-from"]/@href}, doc)
subject = XML.string_from_xpath("//Subject", doc)
salmon = XML.string_from_xpath(~s{//Link[@rel="salmon"]/@href}, doc)
+ subscribe_address = XML.string_from_xpath(~s{//Link[@rel="http://ostatus.org/schema/1.0/subscribe"]/@template}, doc)
data = %{
"magic_key" => magic_key,
"topic" => topic,
"subject" => subject,
- "salmon" => salmon
+ "salmon" => salmon,
+ "subscribe_address" => subscribe_address
}
{:ok, data}
end