Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2018-01-09 17:52:26 +01:00
parent 8ac705d8c2
commit 92d2045735
97 changed files with 18243 additions and 1544 deletions

View File

@@ -0,0 +1,9 @@
defmodule EventosWeb.AppController do
use EventosWeb, :controller
plug :put_layout, false
def app(conn, _params) do
render conn, "index.html"
end
end

View File

@@ -1,11 +1,8 @@
defmodule EventosWeb.PageController do
use EventosWeb, :controller
import Logger
def index(conn, _params) do
render conn, "index.html"
end
def app(conn, _params) do
render conn, "index.html"
end
end

View File

@@ -8,9 +8,12 @@ defmodule EventosWeb.SessionController do
# Attempt to authenticate the user
with {:ok, token, _claims} <- Accounts.authenticate(%{user: user, password: password}) do
# Render the token
render conn, "token.json", token: token
user = Eventos.Repo.preload user, :account
render conn, "token.json", %{token: token, user: user}
end
send_resp(conn, 400, "Bad login")
end
send_resp(conn, 400, "No such user")
end
def sign_out(conn, _params) do

View File

@@ -1,5 +1,6 @@
defmodule EventosWeb.UserController do
use EventosWeb, :controller
import Logger
alias Eventos.Accounts
alias Eventos.Accounts.User
@@ -57,4 +58,34 @@ defmodule EventosWeb.UserController do
|> put_flash(:info, "User deleted successfully.")
|> redirect(to: user_path(conn, :index))
end
def register(conn, %{"email" => email, "password" => password, "username" => username}) do
{:ok, {privkey, pubkey}} = RsaEx.generate_keypair("4096")
account_change = Ecto.Changeset.change(%Eventos.Accounts.Account{}, %{
username: username,
description: "tata",
display_name: "toto",
domain: nil,
private_key: privkey,
public_key: pubkey,
uri: "",
url: ""
})
user_change = Eventos.Accounts.User.registration_changeset(%Eventos.Accounts.User{}, %{
email: email,
password: password,
password_confirmation: password
})
account_with_user = Ecto.Changeset.put_assoc(account_change, :user, user_change)
Eventos.Repo.insert!(account_with_user)
user = Eventos.Accounts.find(email)
user = Eventos.Repo.preload user, :account
render conn, "user.json", %{user: user}
end
end