Commit 295fb1c6 authored by Mayel's avatar Mayel

new routes & controller for simple HTML register

parent 544da951
Pipeline #28834189 failed with stages
in 3 minutes and 7 seconds
......@@ -8,6 +8,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OAuth.{Authorization, Token, App}
alias Comeonin.Pbkdf2
alias Pleroma.Web.TwitterAPI.{TwitterAPI}
import Ecto.Query
require Logger
......@@ -1129,3 +1130,24 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
end
end
def register(conn, _) do
conn
|> render(MastodonView, "register.html", %{error: false})
end
def register_post(conn, params) do
with {:ok, user} <- TwitterAPI.register_user(params) do
{:ok, app} <- get_or_make_app(),
{:ok, auth} <- Authorization.create_authorization(app, user),
{:ok, token} <- Token.exchange_token(app, auth) do
conn
|> put_session(:oauth_token, token.token)
|> redirect(to: "/web/getting-started")
else
_e ->
conn
|> render(MastodonView, "register.html", %{error: "Wrong details"})
end
end
......@@ -342,6 +342,8 @@ defmodule Pleroma.Web.Router do
get("/web/login", MastodonAPIController, :login)
post("/web/login", MastodonAPIController, :login_post)
get("/web/register", MastodonAPIController, :register)
post("/web/register", MastodonAPIController, :register_post)
get("/web/*path", MastodonAPIController, :index)
delete("/auth/sign_out", MastodonAPIController, :logout)
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment