Wire mail change to LDAP backend
This commit is contained in:
parent
ead51b3082
commit
061a748c2a
|
@ -139,7 +139,8 @@ defmodule RecycledCloud.Accounts do
|
||||||
|
|
||||||
with {:ok, query} <- UserToken.verify_change_email_token_query(token, context),
|
with {:ok, query} <- UserToken.verify_change_email_token_query(token, context),
|
||||||
%UserToken{sent_to: email} <- Repo.one(query),
|
%UserToken{sent_to: email} <- Repo.one(query),
|
||||||
{:ok, _} <- Repo.transaction(user_email_multi(user, email, context)) do
|
{:ok, _} <- Repo.transaction(user_email_multi(user, email, context)),
|
||||||
|
{:ok, _} <- User.set_email(user, email) do
|
||||||
:ok
|
:ok
|
||||||
else
|
else
|
||||||
_ -> :error
|
_ -> :error
|
||||||
|
@ -147,11 +148,13 @@ defmodule RecycledCloud.Accounts do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp user_email_multi(user, email, context) do
|
defp user_email_multi(user, email, context) do
|
||||||
changeset = user |> User.email_changeset(%{email: email}) |> User.confirm_changeset()
|
changeset = user
|
||||||
|
|> User.email_changeset(%{email: email})
|
||||||
# TODO: change email in LDAP here.
|
|> User.confirm_changeset()
|
||||||
|
|
||||||
|
# Delete existing tokens.
|
||||||
Ecto.Multi.new()
|
Ecto.Multi.new()
|
||||||
|
|> Ecto.Multi.update(:user, changeset)
|
||||||
|> Ecto.Multi.delete_all(:tokens, UserToken.user_and_contexts_query(user, [context]))
|
|> Ecto.Multi.delete_all(:tokens, UserToken.user_and_contexts_query(user, [context]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -207,7 +210,7 @@ defmodule RecycledCloud.Accounts do
|
||||||
case User.set_password(user, new_password) do
|
case User.set_password(user, new_password) do
|
||||||
{:ok, _} -> {:ok, user}
|
{:ok, _} -> {:ok, user}
|
||||||
{:error, err} ->
|
{:error, err} ->
|
||||||
changeset_errors = [current_password: {"Unknown error.", []}]
|
changeset_errors = [current_password: {"Unknown error: #{err}", [err: inspect(err)]}]
|
||||||
updated_changeset = changeset
|
updated_changeset = changeset
|
||||||
|> Map.put(:action, :update)
|
|> Map.put(:action, :update)
|
||||||
|> Map.put(:errors, changeset_errors)
|
|> Map.put(:errors, changeset_errors)
|
||||||
|
|
|
@ -191,4 +191,14 @@ defmodule RecycledCloud.Accounts.User do
|
||||||
|
|
||||||
query |> LDAP.execute_single
|
query |> LDAP.execute_single
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_email(user, email) do
|
||||||
|
ldif = :eldap.mod_replace('mail', [email |> String.to_charlist])
|
||||||
|
|
||||||
|
query = fn ldap_conn ->
|
||||||
|
:eldap.modify(ldap_conn, String.to_charlist(user.dn), [ldif])
|
||||||
|
end
|
||||||
|
|
||||||
|
query |> LDAP.execute_single
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue