-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
defmodule Swipex.User do | ||
def register(name, password) do | ||
conn = Bolt.Sips.conn() | ||
id = UUID.uuid4() | ||
|
||
Bolt.Sips.query(conn, "CREATE (u:User {id: $id, name: $name, password: $password})", %{ | ||
id: id, | ||
name: name, | ||
password: password | ||
}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule SwipexWeb.PageController do | ||
use SwipexWeb, :controller | ||
|
||
def index(conn, _params) do | ||
render(conn, :index) | ||
end | ||
|
||
def register(conn, _params) do | ||
render(conn, :register) | ||
end | ||
|
||
def do_register(conn, %{ | ||
"name" => name, | ||
"password" => password | ||
}) do | ||
with true <- String.length(name) > 0, | ||
true <- String.length(password) > 0, | ||
{:ok, _} <- Swipex.User.register(name, password) do | ||
conn | ||
|> put_flash(:info, "Registered successfully!") | ||
|> redirect(to: "/login") | ||
else | ||
_ -> do_register(conn, %{}) | ||
end | ||
end | ||
|
||
def do_register(conn, _params) do | ||
conn | ||
|> put_flash(:error, "Invalid name or password.") | ||
|> redirect(to: "/register") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule SwipexWeb.PageHTML do | ||
use SwipexWeb, :html | ||
import Phoenix.HTML.Tag | ||
|
||
def index(assigns) do | ||
~H""" | ||
<p>Welcome to Swipex!</p> | ||
<p>If you have a profile, you can <a class="text-blue-400" href="/login">login here</a>.</p> | ||
<p> | ||
If you don't have a profile, you can <a class="text-blue-400" href="/register">register here</a>. | ||
</p> | ||
""" | ||
end | ||
|
||
def register(assigns) do | ||
~H""" | ||
<div class="max-w-md mx-auto"> | ||
<p>Register for Swipex</p> | ||
<form action="/register" method="post" class="flex flex-col gap-4"> | ||
<input type="text" name="name" placeholder="Name" /> | ||
<input type="password" name="password" placeholder="Password" /> | ||
<%= csrf_input_tag("/login") %> | ||
<input type="submit" value="Register" /> | ||
</form> | ||
</div> | ||
""" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters