diff --git a/lib/recycledcloud/LDAP.ex b/lib/recycledcloud/LDAP.ex index 955cbfe..1f2435f 100644 --- a/lib/recycledcloud/LDAP.ex +++ b/lib/recycledcloud/LDAP.ex @@ -96,7 +96,8 @@ defmodule RecycledCloud.LDAP do :eldap.simple_bind(ldap_conn, dn, pw) end - defp connect do + # The method is used by the RC.LDAPTestEnvironment module. + def connect do conf = Application.get_env(:recycledcloud, :ldap, []) host = Keyword.get(conf, :server, "localhost") |> String.to_charlist @@ -110,18 +111,19 @@ defmodule RecycledCloud.LDAP do Logger.info "Successfuly connected to LDAP server." case bind(ldap_conn) do {:error, err} -> - Logger.warning("Could not bind to LDAP server: #{err}") + Logger.warning("Could not bind to LDAP server: #{inspect(err)}") _ -> :noop end %{status: :ok, conn: ldap_conn} {:error, err} -> - Logger.warning "Failed to connect to LDAP server: #{err}. Authentication will not be possible." + Logger.warning "Failed to connect to LDAP server: #{inspect(err)}. Authentication will not be possible." %{status: :error, conn: nil} end end - defp close(ldap_conn) do + # The method is used by the RC.LDAPTestEnvironment module. + def close(ldap_conn) do ldap_conn |> :eldap.close Logger.debug("An LDAP connection was closed.") end diff --git a/lib/recycledcloud/accounts.ex b/lib/recycledcloud/accounts.ex index 0464271..9e68c55 100644 --- a/lib/recycledcloud/accounts.ex +++ b/lib/recycledcloud/accounts.ex @@ -6,7 +6,6 @@ defmodule RecycledCloud.Accounts do import Ecto.Query, warn: false alias RecycledCloud.Repo alias RecycledCloud.Accounts.{User, Key, UserToken, UserNotifier} - alias RecycledCloud.LDAP ## Database getters @@ -164,7 +163,7 @@ defmodule RecycledCloud.Accounts do :ok <- User.set_email(user, email) do :ok else - err -> :error + _ -> :error end end diff --git a/lib/recycledcloud/accounts/key.ex b/lib/recycledcloud/accounts/key.ex index 7fd2a37..6410969 100644 --- a/lib/recycledcloud/accounts/key.ex +++ b/lib/recycledcloud/accounts/key.ex @@ -40,7 +40,7 @@ defmodule RecycledCloud.Accounts.Key do @doc false def changeset(key, attrs) do - out = key + key |> cast(attrs, [:comment, :value]) |> validate_required([:value]) |> process_ssh_key(:value, :fingerprint, :comment) diff --git a/lib/recycledcloud/accounts/user.ex b/lib/recycledcloud/accounts/user.ex index 0558be1..0a51a93 100644 --- a/lib/recycledcloud/accounts/user.ex +++ b/lib/recycledcloud/accounts/user.ex @@ -30,7 +30,7 @@ defmodule RecycledCloud.Accounts.User do case query |> LDAP.execute do {:ok, []} -> {:error, "could not find matching object"} {:ok, [entry]} -> {:ok, entry} - {:ok, [entry|_]} -> {:error, "found more than one object with uid #{uid}"} + {:ok, [_entry|_]} -> {:error, "found more than one object with uid #{uid}"} {:error, err} -> {:error, inspect(err)} end end @@ -85,7 +85,7 @@ defmodule RecycledCloud.Accounts.User do err -> err end end - o = query |> LDAP.execute + query |> LDAP.execute end def register(%User{} = user) do diff --git a/lib/recycledcloud_web/controllers/user_confirmation_controller.ex b/lib/recycledcloud_web/controllers/user_confirmation_controller.ex index aff5d85..66b6021 100644 --- a/lib/recycledcloud_web/controllers/user_confirmation_controller.ex +++ b/lib/recycledcloud_web/controllers/user_confirmation_controller.ex @@ -7,8 +7,8 @@ defmodule RecycledCloudWeb.UserConfirmationController do render(conn, "new.html") end - def create(conn, %{"user" => %{"email" => email}}) do - if user = Accounts.get_user_by_email(email) do + def create(conn, %{"user" => %{"username" => username}}) do + if user = Accounts.get_user_by_username(username) do Accounts.deliver_user_confirmation_instructions( user, &Routes.user_confirmation_url(conn, :confirm, &1) diff --git a/test/recycledcloud_web/controllers/user_settings_controller_test.exs b/test/recycledcloud_web/controllers/user_settings_controller_test.exs index 5f108e7..5b91fa6 100644 --- a/test/recycledcloud_web/controllers/user_settings_controller_test.exs +++ b/test/recycledcloud_web/controllers/user_settings_controller_test.exs @@ -35,7 +35,7 @@ defmodule RecycledCloudWeb.UserSettingsControllerTest do assert redirected_to(new_password_conn) == Routes.user_settings_path(conn, :edit) assert get_session(new_password_conn, :user_token) != get_session(conn, :user_token) assert get_flash(new_password_conn, :info) =~ "Password updated successfully" - assert Accounts.get_user_by_email_and_password(user.email, "new valid password") + assert Accounts.get_user_by_username_and_password(user.username, "new valid password") end test "does not update password on invalid data", %{conn: conn} do @@ -44,14 +44,13 @@ defmodule RecycledCloudWeb.UserSettingsControllerTest do "action" => "update_password", "current_password" => "invalid", "user" => %{ - "password" => "too short", + "password" => "short", "password_confirmation" => "does not match" } }) response = html_response(old_password_conn, 200) - assert response =~ "