aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/oauth/authorization.ex
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2018-03-30 15:01:53 +0200
committerlain <lain@soykaf.club>2018-03-30 15:01:53 +0200
commit4afbef39f49948ddd3b1cd1bbda58ff7e3ac2785 (patch)
tree6959e12d9058c981f3b69c77b8b0290049651cd6 /lib/pleroma/web/oauth/authorization.ex
parent480932c8e524e1a80c9c8ef1a1aa23379f633afe (diff)
downloadpleroma-4afbef39f49948ddd3b1cd1bbda58ff7e3ac2785.tar.gz
Format the code.
Diffstat (limited to 'lib/pleroma/web/oauth/authorization.ex')
-rw-r--r--lib/pleroma/web/oauth/authorization.ex17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/pleroma/web/oauth/authorization.ex b/lib/pleroma/web/oauth/authorization.ex
index 1ba5be602..94f44c9f2 100644
--- a/lib/pleroma/web/oauth/authorization.ex
+++ b/lib/pleroma/web/oauth/authorization.ex
@@ -7,24 +7,24 @@ defmodule Pleroma.Web.OAuth.Authorization do
import Ecto.{Changeset}
schema "oauth_authorizations" do
- field :token, :string
- field :valid_until, :naive_datetime
- field :used, :boolean, default: false
- belongs_to :user, Pleroma.User
- belongs_to :app, Pleroma.App
+ field(:token, :string)
+ field(:valid_until, :naive_datetime)
+ field(:used, :boolean, default: false)
+ belongs_to(:user, Pleroma.User)
+ belongs_to(:app, Pleroma.App)
timestamps()
end
def create_authorization(%App{} = app, %User{} = user) do
- token = :crypto.strong_rand_bytes(32) |> Base.url_encode64
+ token = :crypto.strong_rand_bytes(32) |> Base.url_encode64()
authorization = %Authorization{
token: token,
used: false,
user_id: user.id,
app_id: app.id,
- valid_until: NaiveDateTime.add(NaiveDateTime.utc_now, 60 * 10)
+ valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), 60 * 10)
}
Repo.insert(authorization)
@@ -37,11 +37,12 @@ defmodule Pleroma.Web.OAuth.Authorization do
end
def use_token(%Authorization{used: false, valid_until: valid_until} = auth) do
- if NaiveDateTime.diff(NaiveDateTime.utc_now, valid_until) < 0 do
+ if NaiveDateTime.diff(NaiveDateTime.utc_now(), valid_until) < 0 do
Repo.update(use_changeset(auth, %{used: true}))
else
{:error, "token expired"}
end
end
+
def use_token(%Authorization{used: true}), do: {:error, "already used"}
end