Packages
pow
0.1.0-alpha.7
1.0.39
1.0.38
1.0.37
1.0.36
1.0.35
1.0.34
1.0.33
1.0.32
1.0.31
1.0.30
1.0.29
1.0.28
1.0.27
1.0.26
1.0.25
1.0.24
1.0.23
1.0.22
1.0.21
1.0.20
1.0.19
1.0.18
1.0.17
1.0.16
1.0.15
1.0.14
1.0.13
1.0.12
1.0.11
1.0.10
1.0.9
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
1.0.0-rc.4
1.0.0-rc.3
1.0.0-rc.2
1.0.0-rc.1
1.0.0-rc.0
0.1.0-rc.1
0.1.0-alpha.8
0.1.0-alpha.7
retired
0.1.0-alpha.6
0.1.0-alpha.5
0.1.0-alpha.4
0.1.0-alpha.3
0.1.0-alpha.2
0.1.0-alpha.1
0.1.0-alpha
Robust user authentication solution
Retired package: Release invalid
Security advisory:
This version has known vulnerabilities.
View advisories
Current section
Files
Jump to
Current section
Files
lib/pow/operations.ex
defmodule Pow.Operations do
@moduledoc """
Operation methods that glues operation calls to context module.
A custom context module can be used instead of the default `Pow.Ecto.Context`
if a `:users_context` key is passed in the configuration.
"""
alias Pow.{Config, Ecto.Context}
@doc """
Build a changeset from a blank user struct.
It'll use the schema module fetched from the config through
`Pow.Ecto.Context.user_schema_mod/1`.
"""
@spec changeset(Config.t(), map()) :: map() | nil | no_return
def changeset(config, params) do
user_mod = Context.user_schema_mod(config)
user = user_mod.__struct__()
changeset(config, user, params)
end
@doc """
Build a changeset from existing user struct.
It'll call the `changeset/2` method on the user struct.
"""
@spec changeset(Config.t(), map(), map()) :: map()
def changeset(_config, user, params) do
user.__struct__.changeset(user, params)
end
@doc """
Authenticate a user.
This calls `Pow.Ecto.Context.authenticate/2` or `authenticate/1` on a custom
context module.
"""
@spec authenticate(Config.t(), map()) :: map() | nil | no_return
def authenticate(config, params) do
case context_module(config) do
Context -> Context.authenticate(config, params)
module -> module.authenticate(params)
end
end
@doc """
Create a new user.
This calls `Pow.Ecto.Context.create/2` or `create/1` on a custom context
module.
"""
@spec create(Config.t(), map()) :: {:ok, map()} | {:error, map()} | no_return
def create(config, params) do
case context_module(config) do
Context -> Context.create(config, params)
module -> module.create(params)
end
end
@doc """
Update an existing user.
This calls `Pow.Ecto.Context.update/3` or `update/2` on a custom context
module.
"""
@spec update(Config.t(), map(), map()) :: {:ok, map()} | {:error, map()} | no_return
def update(config, user, params) do
case context_module(config) do
Context -> Context.update(config, user, params)
module -> module.update(user, params)
end
end
@doc """
Delete an existing user.
This calls `Pow.Ecto.Context.delete/2` or `delete/1` on a custom context
module.
"""
@spec delete(Config.t(), map()) :: {:ok, map()} | {:error, map()} | no_return
def delete(config, user) do
case context_module(config) do
Context -> Context.delete(config, user)
module -> module.delete(user)
end
end
@doc """
Retrieve a user with the provided clauses.
This calls `Pow.Ecto.Context.get_by/2` or `get_by/1` on a custom context
module.
"""
@spec get_by(Config.t(), Keyword.t() | map()) :: map() | nil | no_return
def get_by(config, clauses) do
case context_module(config) do
Context -> Context.get_by(config, clauses)
module -> module.get_by(clauses)
end
end
defp context_module(config) do
Config.get(config, :users_context, Context)
end
end