Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zuraguerra/elegua
User authentication library with mail verification that doesn't require Phoenix
https://github.com/zuraguerra/elegua
Last synced: 3 months ago
JSON representation
User authentication library with mail verification that doesn't require Phoenix
- Host: GitHub
- URL: https://github.com/zuraguerra/elegua
- Owner: ZuraGuerra
- Created: 2016-02-03T02:47:32.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-07-27T20:15:37.000Z (over 8 years ago)
- Last Synced: 2024-09-19T04:07:21.656Z (3 months ago)
- Language: Elixir
- Homepage:
- Size: 31.3 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Elegua
**TODO: Add description**
## Setup
Add your model specifications to config.
```elixir
config :elegua, # These are the default values, but imagine a model like:
user_model: YourApp.User, # MyApp.Player
app_repo: YourApp.Repo, # MyApp.Repo
password_field: :password, # :passphrase
username_field: :username, # :user
email_field: :email, # :mail
# these two are only needed if you'd like to verify users' email
# and thi is the only field that must have this name
verification_token_field: :verification_token,
is_verified_field: :is_verified # :active
```## Use
### Registration
#### Simple DB creation
```elixir
defmodule MyApp.Registration do
alias MyApp.MyUserdef create(params) do
changeset =
Elegua.changeset(%MyUser{}, params)
|> MyUser.another_changeset(params)
# And so on ad infinitumif changeset.valid? do
{:ok, user} = Elegua.register(changeset)
# Other happy things
else
# Handle error
endend
end
```
#### Email verification
```elixir
defmodule MyApp.Registration do
alias MyApp.MyUser@from "[email protected]"
@subject "Welcome to MyAwesomeApp!"def create(params) do
changeset =
Elegua.changeset(%MyUser{}, params)
|> MyUser.another_changeset(params)if changeset.valid? do
# Passing `verify` as an option
{:ok, user} = Elegua.register(changeset, :verify)
verification_token = changeset.params["verification_token"]
# You must add the token to the content
content = "Your verification token: #{verification_token}"
Elegua.send_verification_email(user_email, @from, @subject, {:text, content})
# OR you can send HTML
# content = "Welcome to Phoenix!
"
# Elegua.send_verification_email(user_email, @from, @subject, {:html, content})# IF you're using Phoenix, you can get your templates
# rendered to string with `Phoenix.View.render_to_string`
# https://hexdocs.pm/phoenix/Phoenix.View.html#render_to_string/3
else
# Handle error
end
enddef verify(token) do
Elegua.verify(token)
end
end
```## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed as:
1. Add elegua to your list of dependencies in `mix.exs`:
def deps do
[{:elegua, "~> 0.0.1"}]
end2. Ensure elegua is started before your application:
def application do
[applications: [:elegua]]
end