Fix credo

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2018-07-04 17:16:02 +02:00
parent 615e91a05b
commit b60e8b7647
6 changed files with 18 additions and 7 deletions

View File

@ -312,7 +312,7 @@ defmodule Eventos.Actors do
Get an user by email
"""
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 ->
{:error, nil}
user ->

View File

@ -12,7 +12,7 @@ defmodule Eventos.Actors.Service.ResetPassword do
@spec check_reset_password_token(String.t, String.t) :: tuple
def check_reset_password_token(password, 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
_err ->
{:error, :invalid_token}
@ -25,7 +25,7 @@ defmodule Eventos.Actors.Service.ResetPassword do
@spec send_password_reset_email(User.t, String.t) :: tuple
def send_password_reset_email(%User{} = user, locale \\ "en") do
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
|> UserEmail.reset_password_email(locale)
|> Mailer.deliver_later()
@ -37,7 +37,9 @@ defmodule Eventos.Actors.Service.ResetPassword do
@spec random_string(integer) :: String.t
defp random_string(length) do
:crypto.strong_rand_bytes(length) |> Base.url_encode64
length
|> :crypto.strong_rand_bytes()
|> Base.url_encode64
end
@spec we_can_send_email(User.t) :: boolean

View File

@ -66,7 +66,9 @@ defmodule Eventos.Actors.User do
end
defp random_string(length) do
:crypto.strong_rand_bytes(length) |> Base.url_encode64
length
|> :crypto.strong_rand_bytes()
|> Base.url_encode64
end
@doc """

View File

@ -1,5 +1,7 @@
defmodule Eventos.Email.User do
@moduledoc """
Handles emails sent to users
"""
alias Eventos.Actors.User
import Bamboo.Email

View File

@ -1,3 +1,6 @@
defmodule Eventos.Mailer do
@moduledoc """
Mailer
"""
use Bamboo.Mailer, otp_app: :eventos
end

View File

@ -90,7 +90,9 @@ defmodule EventosWeb.UserController do
end
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)
end