Login por matricula

This commit is contained in:
santiago.sferco 2024-07-01 12:19:08 -03:00
parent 10b1f8c855
commit b11499ff2d
6 changed files with 32 additions and 34 deletions

View File

@ -58,10 +58,12 @@ body{
align-items: center;
padding: 15px;
height: max-content;
width: 250px;
width: 300px;
text-align: center;
}
div > .reg_form{}
.auth_form img{
margin-top: 10px;
margin-bottom: 20px;
@ -83,6 +85,10 @@ body{
background-color: #5bc0de;
color: white;
padding-top: 10px;
.imput_text{
margin-top: 5px;
border-radius: 5px;
}
padding-bottom: 10px;
width: 205px;
border-radius: 5px;

View File

@ -44,6 +44,12 @@ defmodule Derivantes.Accounts do
if User.valid_password?(user, password), do: user
end
def get_user_by_matricula_and_password(matricula, password)
when is_binary(matricula) and is_binary(password) do
user = Repo.get_by(User, matricula: matricula)
if User.valid_password?(user, password), do: user
end
@doc """
Gets a single user.

View File

@ -22,19 +22,13 @@ defmodule Derivantes.Accounts.UserNotifier do
Deliver instructions to confirm account.
"""
def deliver_confirmation_instructions(user, url) do
deliver(user.email, "Confirmation instructions", """
deliver(user.email, "Confirme su correo electrónico", """
==============================
Hi #{user.email},
You can confirm your account by visiting the URL below:
Hola #{user.email},
Active su cuenta haciendo click en el siguiente enlace:
#{url}
If you didn't create an account with us, please ignore this.
==============================
""")
end

View File

@ -13,43 +13,35 @@
<script src="https://kit.fontawesome.com/8afa33c96d.js" crossorigin="anonymous"></script>
</head>
<body class="gray antialiased">
<ul class="relative z-10 flex items-center gap-4 px-4 sm:px-6 lg:px-8 justify-end root_header">
<ul class="relative z-10 flex items-center gap-4 px-4 sm:px-6 lg:px-8 justify-end root_header p-3">
<%= if @current_user do %>
<li class="text-[0.8125rem] leading-6 text-zinc-900">
<li class="text-m leading-6 text-white">
<%= @current_user.email %>
</li>
<li>
<.link
href={~p"/derivantes/settings"}
class="text-[0.8125rem] leading-6 text-zinc-900 font-semibold hover:text-zinc-700"
>
Settings
</.link>
</li>
<li>
<.link
href={~p"/derivantes/log_out"}
method="delete"
class="text-[0.8125rem] leading-6 text-zinc-900 font-semibold hover:text-zinc-700"
class="text-m leading-6 text-white hover:text-gray font-semibold"
>
Log out
Salir
</.link>
</li>
<% else %>
<li>
<.link
href={~p"/derivantes/register"}
class="text-[0.8125rem] leading-6 text-zinc-900 font-semibold hover:text-zinc-700"
class="text-m leading-6 text-white hover:text-gray"
>
Register
Registro
</.link>
</li>
<li>
<.link
href={~p"/derivantes/log_in"}
class="text-[0.8125rem] leading-6 text-zinc-900 font-semibold hover:text-zinc-700"
class="text-m leading-6 text-white hover:text-gray"
>
Log in
Ingresar
</.link>
</li>
<% end %>

View File

@ -19,9 +19,9 @@ defmodule DerivantesWeb.UserSessionController do
end
defp create(conn, %{"user" => user_params}, info) do
%{"email" => email, "password" => password} = user_params
%{"matricula" => matricula, "password" => password} = user_params
if user = Accounts.get_user_by_email_and_password(email, password) do
if user = Accounts.get_user_by_matricula_and_password(matricula, password) do
conn
|> put_flash(:info, info)
|> UserAuth.log_in_user(user, user_params)
@ -29,7 +29,7 @@ defmodule DerivantesWeb.UserSessionController do
# In order to prevent user enumeration attacks, don't disclose whether the email is registered.
conn
|> put_flash(:error, "Invalid email or password")
|> put_flash(:email, String.slice(email, 0, 160))
|> put_flash(:matricula, String.slice(matricula, 0, 160))
|> redirect(to: ~p"/derivantes/log_in")
end
end

View File

@ -14,11 +14,11 @@ defmodule DerivantesWeb.UserLoginLive do
>
<img src={~p"/images/sana_americano_logo.png"} alt="Sanatorio Americano Logo"/>
<.input
field={@form[:email]}
type="email"
field={@form[:matricula]}
type="number"
label=""
class="imput_text"
placeholder="Email"
placeholder="Matrícula"
required
/>
<.input
@ -66,8 +66,8 @@ defmodule DerivantesWeb.UserLoginLive do
end
def mount(_params, _session, socket) do
email = Phoenix.Flash.get(socket.assigns.flash, :email)
form = to_form(%{"email" => email}, as: "user")
matricula = Phoenix.Flash.get(socket.assigns.flash, :matricula)
form = to_form(%{"matricula" => matricula}, as: "user")
{:ok, assign(socket, form: form), temporary_assigns: [form: form]}
end
end