{"id":13507441,"url":"https://github.com/khusnetdinov/sesamex","last_synced_at":"2025-10-19T15:15:48.126Z","repository":{"id":57547150,"uuid":"71572997","full_name":"khusnetdinov/sesamex","owner":"khusnetdinov","description":"[WIP] Another authentication hex for Phoenix.","archived":false,"fork":false,"pushed_at":"2017-08-16T19:57:47.000Z","size":43,"stargazers_count":12,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-09T13:07:48.824Z","etag":null,"topics":["elixir-library","elxir","hex","phoenix","predefined-templates","sign"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/khusnetdinov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-21T14:35:54.000Z","updated_at":"2023-09-01T10:50:19.000Z","dependencies_parsed_at":"2022-09-26T18:40:44.195Z","dependency_job_id":null,"html_url":"https://github.com/khusnetdinov/sesamex","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khusnetdinov%2Fsesamex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khusnetdinov%2Fsesamex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khusnetdinov%2Fsesamex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khusnetdinov%2Fsesamex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khusnetdinov","download_url":"https://codeload.github.com/khusnetdinov/sesamex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250483467,"owners_count":21438063,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir-library","elxir","hex","phoenix","predefined-templates","sign"],"created_at":"2024-08-01T02:00:33.673Z","updated_at":"2025-10-19T15:15:48.061Z","avatar_url":"https://github.com/khusnetdinov.png","language":"Elixir","funding_links":[],"categories":["Authentication"],"sub_categories":[],"readme":"# [WIP] Sesamex [![Code Triagers Badge](https://www.codetriage.com/khusnetdinov/sesamex/badges/users.svg)](https://www.codetriage.com/khusnetdinov/sesamex) [![Build Status](https://travis-ci.org/khusnetdinov/sesamex.svg?branch=master)](https://travis-ci.org/khusnetdinov/sesamex) [![Ebert](https://ebertapp.io/github/khusnetdinov/sesamex.svg)](https://ebertapp.io/github/khusnetdinov/sesamex) [![Hex.pm](https://img.shields.io/hexpm/v/plug.svg)](https://hex.pm/packages/sesamex)\n![img](http://res.cloudinary.com/dtoqqxqjv/image/upload/v1489144587/github/147705061811651_leoa8a.jpg)\n\n# NOTE: This repo in active development!\n\n\n## Getting started\n\nSesamex is a simple and flexible authentication solution for Elixir / Phoenix.\n\n#### Implemented functionality:\n\n- `:registration`\n- `:session`\n\n#### Todo functionality:\n\n- `:remember`\n- `:track`\n- email adapter\n- email in browser\n- `:confirm`\n- `:recover`\n- `:invite`\n- `:lock, :unlock`\n- token auth\n- `:oauth`\n- change layout\n\n## Installation\n\nAdd `sesamex` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:sesamex, \"~\u003e 0.2.1\"}]\nend\n```\n\n## Authentication in 5 minutes!\n\nWe are going to create authentication for `User` model in 5 minutes with `phoenix.new` bootstrapped application.\n\n1) Create model and migration for `User`.\n\n```elixir\n$ mix sesamex.gen.model User users\n```\n\n2) Migrate database.\n\n```elixir\n$ mix ecto.migrate\n```\n\n3) Create predefined controllers for using them in authentication.\n\n```elixir\n$ mix sesamex.gen.controllers User\n```\n\n4) Create predefined views modules.\n\n```elixir\n$ mix sesamex.gen.views User\n```\n\n5) Create predefined templates for sign_up and sign_in pages.\n\n```elixir\n$ mix sesamex.gen.templates User\n```\n\n6) Add routes modules `Sesamex.Routes`, `Sesamex.Pipeline` and functions `authenticate`, `session`.\n\n```elixir\n$ mix sesamex.gen.routes User\n```\n\n7) Add routes functions to `layout.html.eex`, remove lines with `Get Started` link and paste code below.\n\n```elixir\n\u003c%= if @current_user do %\u003e\n  \u003cli\u003e\u003c%= @current_user.email %\u003e\u003c/li\u003e\n  \u003cli\u003e\u003c%= link \"sign_out\", to: session_path(@conn, :delete), method: \"delete\" %\u003e\n\u003c% else %\u003e\n  \u003cli\u003e\u003c%= link \"sign_up\", to: registration_path(@conn, :new) %\u003e\u003c/li\u003e\n  \u003cli\u003e\u003c%= link \"sign_in\", to: session_path(@conn, :new) %\u003e\u003c/li\u003e\n\u003c% end %\u003e\n```\n\n8) Run server `mix phoenix.server`.\n\n## Usage\n\nSesamex goes with helper modules which keep required logic for authentification.\n\n#### Generate model and migration for authentication process:\n\n```elixir\n$ mix sesamex.gen.model Model models\n```\n\nThe tasks accepts the same argements as phoenix model generation task - singular and plural forms of model.\nTask will generate 2 files:\n\n- `web/models/model.ex`\n- `priv/repo/migrations/#{timestamp}_create_model.ex`\n\nModel file keeps schema and changesets functions which were taken from `Sesamex.Model` by default. If you want customize, just write you own logic.\n\nBy default Sesamex use `email`, `password` fields for authentication. If you want to change them or add additional fields you need to change migration and schema in this files.\n\n#### Generate predefined controllers modules for model scope:\n\n```elixir\n$ mix sesamex.gen.controllers Model\n```\n\nTask get `Model` in singular form for defining controllers modules scope and generate files. In example:\n```\n├── controllers/\n│   ├── model/\n│   │   ...\n│   │   └── registration_controller.ex\n│   └── page_controller.ex\n```\n\nBy defualt sesamex generate controllers with scope `Project.Model.ExampleController`. If you want to use custom controllers you need change settings in routes. See below.\n\n#### Generation predefined views modules for model scope:\n\n```elixir\n$ mix sesamex.gen.views Model\n```\n\nTask do the job like controllers task for views.\n\n#### Generation predefined templates for `sign_up`, `sign_in` pages:\n\n```elixir\n$ mix sesames.gen.templates Model\n```\n\nTask get `Model` scope name and create templates for pages:\n\n- `web/templates/model/registration/new.html.eex`\n- `web/templates/model/session/new.html.eex`\n\nTemplates file keep predefined eex markup for using pages instantly.\n\n#### Generation routes and define default controllers:\n\n```elixir\n$ mix sesamex.gen.routes Model\n```\n\nAdds to `web/routex.ex` Sesamex modules and helpers:\n\n```elixir\ndefmodule Project.Routes do\n  # ...\n  use Sesamex.Routes\n  use Sesamex.Pipeline\n\n  alias Project.Repo\n  alias Project.User\n\n  pipeline :browser do\n    # ...\n    plug :session, [:user, User, Repo]\n  end\n\n  scope \"/\", Project do\n    # ...\n    authenticate :users\n\n    get \"/\", PageController, :index\n  end\n  # ...\nend\n```\n\nModule `Sesamex.Routes` macro `authenticate: 2` keep logic for generation route_paths for model. Note that you should atom in plural form `:models`. There are 2 opts `only`, `except`, see examples:\n\n- `only: [:module, :other_module]`\n- `except: [:module, :other_module]`\n\nBy default macros generate routes for controllers which shoud be scoped by model name, see example:\n\n```elixir\n\n  authenticate :users, only: [:registration]\n\n  # Generate routes\n  # registration_path  GET  /users/sign_up  Project.User.RegistrationController :new\n  # ...\n\n```\n\nIf you want to redifine controller name, use `controllers` Keywords list:\n\n- controllers: [module: OtherController] - Redefine controllers for module.\n\n```elixir\n\n  authenticate :users, controllers: [registration: OtherController]\n\n  # Generate routes\n  # registration_path  GET  /users/sign_up  Project.OtherController :new\n  # ...\n\n```\n\n#### Generation current model assigns in @conn:\n\nSesamex add to @conn `current_model` assigns for `Model`. You can use `@corrent_model` in views for checking persistance of authenticated model.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT\nLicense](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhusnetdinov%2Fsesamex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhusnetdinov%2Fsesamex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhusnetdinov%2Fsesamex/lists"}