Fix credo
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
615e91a05b
commit
b60e8b7647
|
@ -312,7 +312,7 @@ defmodule Eventos.Actors do
|
||||||
Get an user by email
|
Get an user by email
|
||||||
"""
|
"""
|
||||||
def find_by_email(email) do
|
def find_by_email(email) do
|
||||||
case Repo.get_by(User, email: email) |> Repo.preload(:actor) do
|
case Repo.preload(Repo.get_by(User, email: email), :actor) do
|
||||||
nil ->
|
nil ->
|
||||||
{:error, nil}
|
{:error, nil}
|
||||||
user ->
|
user ->
|
||||||
|
|
|
@ -12,7 +12,7 @@ defmodule Eventos.Actors.Service.ResetPassword do
|
||||||
@spec check_reset_password_token(String.t, String.t) :: tuple
|
@spec check_reset_password_token(String.t, String.t) :: tuple
|
||||||
def check_reset_password_token(password, token) do
|
def check_reset_password_token(password, token) do
|
||||||
with %User{} = user <- Repo.get_by(User, reset_password_token: token) do
|
with %User{} = user <- Repo.get_by(User, reset_password_token: token) do
|
||||||
User.password_reset_changeset(user, %{"password" => password, "reset_password_sent_at" => nil, "reset_password_token" => nil}) |> Repo.update()
|
Repo.update(User.password_reset_changeset(user, %{"password" => password, "reset_password_sent_at" => nil, "reset_password_token" => nil}))
|
||||||
else
|
else
|
||||||
_err ->
|
_err ->
|
||||||
{:error, :invalid_token}
|
{:error, :invalid_token}
|
||||||
|
@ -25,7 +25,7 @@ defmodule Eventos.Actors.Service.ResetPassword do
|
||||||
@spec send_password_reset_email(User.t, String.t) :: tuple
|
@spec send_password_reset_email(User.t, String.t) :: tuple
|
||||||
def send_password_reset_email(%User{} = user, locale \\ "en") do
|
def send_password_reset_email(%User{} = user, locale \\ "en") do
|
||||||
with :ok <- we_can_send_email(user),
|
with :ok <- we_can_send_email(user),
|
||||||
{:ok, %User{} = user_updated} <- User.send_password_reset_changeset(user, %{"reset_password_token" => random_string(30), "reset_password_sent_at" => DateTime.utc_now()}) |> Repo.update() do
|
{:ok, %User{} = user_updated} <- Repo.update(User.send_password_reset_changeset(user, %{"reset_password_token" => random_string(30), "reset_password_sent_at" => DateTime.utc_now()})) do
|
||||||
mail = user_updated
|
mail = user_updated
|
||||||
|> UserEmail.reset_password_email(locale)
|
|> UserEmail.reset_password_email(locale)
|
||||||
|> Mailer.deliver_later()
|
|> Mailer.deliver_later()
|
||||||
|
@ -37,7 +37,9 @@ defmodule Eventos.Actors.Service.ResetPassword do
|
||||||
|
|
||||||
@spec random_string(integer) :: String.t
|
@spec random_string(integer) :: String.t
|
||||||
defp random_string(length) do
|
defp random_string(length) do
|
||||||
:crypto.strong_rand_bytes(length) |> Base.url_encode64
|
length
|
||||||
|
|> :crypto.strong_rand_bytes()
|
||||||
|
|> Base.url_encode64
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec we_can_send_email(User.t) :: boolean
|
@spec we_can_send_email(User.t) :: boolean
|
||||||
|
|
|
@ -66,7 +66,9 @@ defmodule Eventos.Actors.User do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp random_string(length) do
|
defp random_string(length) do
|
||||||
:crypto.strong_rand_bytes(length) |> Base.url_encode64
|
length
|
||||||
|
|> :crypto.strong_rand_bytes()
|
||||||
|
|> Base.url_encode64
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
defmodule Eventos.Email.User do
|
defmodule Eventos.Email.User do
|
||||||
|
@moduledoc """
|
||||||
|
Handles emails sent to users
|
||||||
|
"""
|
||||||
alias Eventos.Actors.User
|
alias Eventos.Actors.User
|
||||||
|
|
||||||
import Bamboo.Email
|
import Bamboo.Email
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
defmodule Eventos.Mailer do
|
defmodule Eventos.Mailer do
|
||||||
|
@moduledoc """
|
||||||
|
Mailer
|
||||||
|
"""
|
||||||
use Bamboo.Mailer, otp_app: :eventos
|
use Bamboo.Mailer, otp_app: :eventos
|
||||||
end
|
end
|
||||||
|
|
|
@ -90,7 +90,9 @@ defmodule EventosWeb.UserController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_current_actor(conn, _params) do
|
def show_current_actor(conn, _params) do
|
||||||
user = Guardian.Plug.current_resource(conn) |> Repo.preload(:actor)
|
user = conn
|
||||||
|
|> Guardian.Plug.current_resource()
|
||||||
|
|> Repo.preload(:actor)
|
||||||
render(conn, "show_simple.json", user: user)
|
render(conn, "show_simple.json", user: user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue