projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'fix/config-gen-releases' into 'develop'
[akkoma]
/
lib
/
pleroma
/
PasswordResetToken.ex
diff --git
a/lib/pleroma/PasswordResetToken.ex
b/lib/pleroma/PasswordResetToken.ex
index 52b1fcd503d465afa761d0c3a73d804b92fe3aa3..f31ea5bc57d6fb7df3c2e3caba579f1a7c796f1c 100644
(file)
--- a/
lib/pleroma/PasswordResetToken.ex
+++ b/
lib/pleroma/PasswordResetToken.ex
@@
-1,20
+1,26
@@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.PasswordResetToken do
use Ecto.Schema
import Ecto.Changeset
defmodule Pleroma.PasswordResetToken do
use Ecto.Schema
import Ecto.Changeset
- alias Pleroma.{User, PasswordResetToken, Repo}
+ alias Pleroma.PasswordResetToken
+ alias Pleroma.Repo
+ alias Pleroma.User
schema "password_reset_tokens" do
schema "password_reset_tokens" do
- belongs_to
:user, User
- field
:token, :string
- field
:used, :boolean, default: false
+ belongs_to
(:user, User, type: Pleroma.FlakeId)
+ field
(:token, :string)
+ field
(:used, :boolean, default: false)
timestamps()
end
def create_token(%User{} = user) do
timestamps()
end
def create_token(%User{} = user) do
- token = :crypto.strong_rand_bytes(32) |> Base.url_encode64
+ token = :crypto.strong_rand_bytes(32) |> Base.url_encode64
()
token = %PasswordResetToken{
user_id: user.id,
token = %PasswordResetToken{
user_id: user.id,
@@
-33,7
+39,7
@@
defmodule Pleroma.PasswordResetToken do
def reset_password(token, data) do
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
def reset_password(token, data) do
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
- %User{} = user <-
Repo.get(User,
token.user_id),
+ %User{} = user <-
User.get_cached_by_id(
token.user_id),
{:ok, _user} <- User.reset_password(user, data),
{:ok, token} <- Repo.update(used_changeset(token)) do
{:ok, token}
{:ok, _user} <- User.reset_password(user, data),
{:ok, token} <- Repo.update(used_changeset(token)) do
{:ok, token}