Giter Site home page Giter Site logo

addict's Introduction

Build Status Hex.pm Hex.pm Inline docs

Addict

Addict allows you to manage users registration and authentication on your Phoenix Framework app easily.

What does it do?

For now, it enables your users to register, login, logout and recover/reset their passwords.

Requirements

Addict is dependent on an ecto User Model and a Database connection interface.

The user model must have at least the following schema:

  field :email, :string
  field :encrypted_password, :string

Plug and go

1 - Add Addict to your dependencies:

 {:addict, "~> 0.2"}

2 - Generate Addict configs via:

mix addict.generate.configs

3 - Generate (opinionated) boilerplate:

mix addict.generate.boilerplate

4 - Add Addict routes to your router.ex:

defmodule YourApp.Router do
  (...)
  use Addict.RoutesHelper
  (...)
  scope "/" do
    addict :routes
  end
end

5 - Visit any of these paths on your app

/login
/register
/recover_password
/reset_password

On what does it depend?

Addict depends on:

Optionally you can make Addict send e-mails for you too. At the moment only Mailgun is supported. Feel free to contribute with another service!

Addict Configs

See all available configurations here.

How can I use it?

Routes

Add the following to your router.ex:

defmodule ExampleApp.Router do
  use Phoenix.Router
  use Addict.RoutesHelper

  ...

  scope "/" do
    addict :routes
  end
end

This will generate the following routes:

        register_path  POST  /register          Addict.Controller.register/2
           login_path  POST  /login             Addict.Controller.login/2
          logout_path  POST  /logout            Addict.Controller.logout/2
recover_password_path  POST  /recover_password  Addict.Controller.recover_password/2
  reset_password_path  POST  /reset_password    Addict.Controller.reset_password/2

You can also override the path or controller/action for a given route:

addict :routes,
  logout: [path: "/sign-out", controller: ExampleApp.UserController, action: :sign_out],
  recover_password: "/password/recover",
  reset_password: "/password/reset"

These overrides will generate the following routes:

        register_path  POST  /register          Addict.Controller.register/2
           login_path  POST  /login             Addict.Controller.login/2
          logout_path  POST  /sign-out          ExampleApp.UserController.sign_out/2
recover_password_path  POST  /password/recover  Addict.Controller.recover_password/2
  reset_password_path  POST  /password/reset    Addict.Controller.reset_password/2

Interacting with Addict

After you've added the router and generated the configs, please take look at the optional boilerplate and the Example App. Here are the interesting bits:

Checking for authentication

Use Addict.Plugs.Authenticated plug to validate requests on your controllers:

defmodule MyAwesomeApp.PageController do
  use Phoenix.Controller

  plug Addict.Plugs.Authenticated when action in [:foobar]
  plug :action

  def foobar(conn, _params) do
    render conn, "index.html"
  end

end

If the user is not logged in and requests for the above action, he will be redirected to not_logged_in_url.

Adding Custom Mailer

For adding a custom Mailer just follow the conventions:

  • Module must be Addict.Mailers.TheEmailProvider
  • Add the Mailer file in /lib/addict/mailers
  • Make sure the mailer implements the behaviour defined here

Once that is done, just set mail_service configuration to :the_email_provider.

TODO

Check the issues on this repository to check or track the ongoing improvements and new features.

Contributing

Feel free to send your PR with improvements or corrections!

Special thanks to the folks at #elixir-lang on freenet for being so helpful every damn time!

addict's People

Contributors

trenpixster avatar avaelkross avatar jxs avatar trestrantham avatar joe-noh avatar phikes avatar jontonsoup avatar c-rack avatar barisbalic avatar beatrichartz avatar chrismccord avatar diogovk avatar cloudbring avatar montague avatar mtanzi avatar mimani-s avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.