Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Openmaize with a new phoenix project

David Whitlock edited this page Apr 2, 2017 · 13 revisions

Create new phoenix project

Run the following commands (replace alibaba with the name of your project):

mix phoenix.new alibaba
cd alibaba

Run the Openmaize installer

Download and install the openmaize_phx installer.

mix archive.install https://github.com/riverrun/openmaize/raw/master/installer/archives/openmaize_phx.ez

For a basic setup, run the following command:

mix openmaize.phx

If you want to add email confirmation and password resetting, add the --confirm option:

mix openmaize.phx --confirm

If you want to create authentication files for an api, use the --api option:

mix openmaize.phx --api

Add openmaize to deps

Make sure you are using Elixir 1.4 or above.

  1. Add openmaize to your mix.exs dependencies

    defp deps do
      [{:openmaize, "~> 3.0"}]
    end
  2. Run mix deps.get

Change the user-identifier, if necessary

The user-identifier, which is used to identify (and index) the user in the database, is :email. If you want to change it, to :username or something else, you will need to edit the following files (:username is used as an example):

  • web/models/user.ex
    • change the unique_constraint value
  • priv/repo/migrations/*_create_user.exs
    • change the user_index value
  • web/controllers/session_controller.ex
    • change plug Openmaize.Login when action in [:create] to plug Openmaize.Login, [unique_id: :username] when action in [:create]
  • test/controllers/session_controller.exs
    • edit the valid_attrs and invalid_attrs
  • web/templates/session/new.html.eex
    • change the email form-group to a username form-group

Create the database and run the migration

mix ecto.setup

Customize the Phoenix app

If you ran the mix openmaize.phx command with the --confirm option, you will need to edit the lib/name_of_your_project/mailer.ex file, using an email library of your choice. See this page for more information.

To see which routes are available, you can run mix phoenix.routes, and to start the server, run mix phoenix.server. For tests, run mix test.