Commit 30c8df78 authored by Mikko Ahlroth's avatar Mikko Ahlroth

Check that user email is not nil when sending password reset to avoid crash

Also remove username from frontpage channel push
parent 4ee7b39e
Pipeline #24902921 passed with stage
in 1 minute and 25 seconds
......@@ -57,7 +57,7 @@ defmodule CodeStats.User.PasswordReset do
true ->
username = get_change(cset, :username)
q = from(u in User, where: u.username == ^username)
q = from(u in User, where: u.username == ^username and not is_nil(u.email))
case Repo.one(q) do
# Invalidate changeset, error message is not shown so it is not needed
......
......@@ -6,7 +6,6 @@ defmodule CodeStatsWeb.FrontpageChannel do
XP numbers on the front page.
"""
alias CodeStats.User
alias CodeStats.User.Pulse
def join("frontpage", _params, socket) do
......@@ -26,7 +25,8 @@ defmodule CodeStatsWeb.FrontpageChannel do
The given pulse must have xps preloaded, xps must have language preloaded.
"""
def send_pulse(%User{private_profile: false} = user, coords, %Pulse{xps: xps})
@spec send_pulse(map, %Pulse{}) :: :ok
def send_pulse(coords, %Pulse{xps: xps})
when not is_nil(xps) do
formatted_xps =
for xp <- xps do
......@@ -38,7 +38,6 @@ defmodule CodeStatsWeb.FrontpageChannel do
CodeStatsWeb.Endpoint.broadcast("frontpage", "new_pulse", %{
xps: formatted_xps,
username: user.username,
coords: coords
})
end
......
......@@ -52,7 +52,7 @@ defmodule CodeStatsWeb.PulseController do
# Broadcast XP data to possible viewers on profile page and frontpage
coords = GeoIPPlug.get_coords(conn)
ProfileChannel.send_pulse(user, %{pulse | xps: inserted_xps})
FrontpageChannel.send_pulse(user, coords, %{pulse | xps: inserted_xps})
FrontpageChannel.send_pulse(coords, %{pulse | xps: inserted_xps})
conn |> put_status(201) |> json(%{ok: "Great success!"})
else
......
......@@ -114,6 +114,13 @@
<div class="stripe">
<h2>Changelog</h2>
<h3>2.0.1 – 2018-07-01 – Email fix</h3>
<ul>
<li>Fixed crash when trying to send password reset for a user with no email.</li>
<li>Removed unnecessary data from front page channel push.</li>
</ul>
<h3>2.0.0 – 2018-07-01 – Brand spanking new</h3>
<ul>
......
......@@ -4,7 +4,7 @@ defmodule CodeStats.Mixfile do
def project do
[
app: :code_stats,
version: "2.0.0",
version: "2.0.1",
elixir: "~> 1.6",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment