Introduce avatar and banner and fetch Gravatar to fill avatar during registration
Signed-off-by: Thomas Citharel <tcit@tcit.fr> typo Signed-off-by: Thomas Citharel <tcit@tcit.fr> Rename avatar to avatar_url, same with header. Add a comment to explain why the tweak with HTTPoison and TLS1.2 Signed-off-by: Thomas Citharel <tcit@tcit.fr> Rename avatar to avatar_url Signed-off-by: Thomas Citharel <tcit@tcit.fr> rename old avatar properties in front-end to avatar_url Signed-off-by: Thomas Citharel <tcit@tcit.fr> fix change gravatar from ?d= to ?default= Signed-off-by: Thomas Citharel <tcit@tcit.fr> reorganize aliases and imports Signed-off-by: Thomas Citharel <tcit@tcit.fr> set avatar url only when gravatar exists, add a test for that case Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -4,8 +4,9 @@ defmodule Eventos.Accounts do
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias Eventos.Repo
|
||||
import Exgravatar
|
||||
|
||||
alias Eventos.Repo
|
||||
alias Eventos.Accounts.Account
|
||||
|
||||
@doc """
|
||||
@@ -173,6 +174,19 @@ defmodule Eventos.Accounts do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Fetch gravatar url for email and set it as avatar if it exists
|
||||
"""
|
||||
defp gravatar(email) do
|
||||
url = gravatar_url(email, default: "404")
|
||||
case HTTPoison.get(url, [], [ssl: [{:versions, [:'tlsv1.2']}]]) do # See https://github.com/edgurgel/httpoison#note-about-broken-ssl-in-erlang-19
|
||||
{:ok, %HTTPoison.Response{status_code: 200}} ->
|
||||
url
|
||||
_ -> # User doesn't have a gravatar email, or other issues
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Register user
|
||||
"""
|
||||
@@ -180,13 +194,15 @@ defmodule Eventos.Accounts do
|
||||
{:ok, {privkey, pubkey}} = RsaEx.generate_keypair("4096")
|
||||
|
||||
|
||||
avatar = gravatar(email)
|
||||
account = Eventos.Accounts.Account.registration_changeset(%Eventos.Accounts.Account{}, %{
|
||||
username: username,
|
||||
domain: nil,
|
||||
private_key: privkey,
|
||||
public_key: pubkey,
|
||||
uri: "h",
|
||||
url: "h"
|
||||
url: "h",
|
||||
avatar_url: avatar,
|
||||
})
|
||||
|
||||
user = Eventos.Accounts.User.registration_changeset(%Eventos.Accounts.User{}, %{
|
||||
@@ -207,7 +223,6 @@ defmodule Eventos.Accounts do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@doc """
|
||||
Creates a user.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user