Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request - Authorised users #4

Closed
kieranwild opened this issue Feb 22, 2018 · 2 comments
Closed

Feature request - Authorised users #4

kieranwild opened this issue Feb 22, 2018 · 2 comments

Comments

@kieranwild
Copy link

kieranwild commented Feb 22, 2018

It would be really helpful if you could document how to pull a list of Authorised Users from a .env file like {:system, "AUTH_USERS"}
export AUTH_USERS= ("[email protected]", "[email protected]")
So only those users can login.

@zanderxyz
Copy link
Owner

zanderxyz commented Feb 24, 2018

Hi Kieran, sorry for the slow reply. This is a good idea, let me have a quick think and I’ll get back to you.

@zanderxyz
Copy link
Owner

I think the best way to handle this would be:

  1. Seed the database with your users in priv/repo/seeds.exs, and run mix run priv/repo/seeds.exs to insert them:
{:ok, _} = YourApp.Veil.create_user("[email protected]")
{:ok, _} = YourApp.Veil.create_user("[email protected]")
  1. Update the create function in user_controller.ex so that only existing users can log in:
def create(conn, %{"user" => %{"email" => email}}) when not is_nil(email) do
    if user = Veil.get_user_by_email(email) do
      sign_and_email(conn, user)
    else
      render(conn, "new.html", changeset: User.changeset(%User{}))
    end
  end

Let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants