This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use Mix.Config | |
| config :sling, Sling.Repo, | |
| username: "your_postgres_user", | |
| password: "your_postgres_password" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # contents above | |
| import_config "dev.secret.exs" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Sling.Repo.Migrations.CreateUser do | |
| use Ecto.Migration | |
| def change do | |
| create table(:users) do | |
| add :username, :string, null: false | |
| add :email, :string, null: false | |
| add :password_hash, :string, null: false | |
| timestamps() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Sling.User do | |
| use Sling.Web, :model | |
| schema "users" do | |
| field :username, :string | |
| field :email, :string | |
| field :password_hash, :string | |
| timestamps() | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # content above | |
| def application do | |
| [mod: {Sling, []}, | |
| applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext, | |
| :phoenix_ecto, :postgrex, :comeonin]] # :comeonin added here | |
| end | |
| # ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Sling.User do | |
| use Sling.Web, :model | |
| schema "users" do | |
| field :username, :string | |
| field :email, :string | |
| field :password_hash, :string | |
| field :password, :string, virtual: true | |
| timestamps() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # content above | |
| config :guardian, Guardian, | |
| issuer: "Sling", | |
| ttl: {30, :days}, | |
| verify_issuer: true, | |
| serializer: Sling.GuardianSerializer | |
| import_config "#{Mix.env}.exs" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| config :guardian, Guardian, | |
| secret_key: "LG17BzmhBeq81Yyyn6vH7GVdrCkQpLktol2vdXlBzkRRHpYsZwluKMG9r6fnu90m" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| config :guardian, Guardian, | |
| secret_key: System.get_env("GUARDIAN_SECRET_KEY") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Sling.GuardianSerializer do | |
| @behaviour Guardian.Serializer | |
| alias Sling.Repo | |
| alias Sling.User | |
| def for_token(user = %User{}), do: {:ok, "User:#{user.id}"} | |
| def for_token(_), do: {:error, "Unknown resource type"} | |
| def from_token("User:" <> id), do: {:ok, Repo.get(User, String.to_integer(id))} |