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
| <%= form_tag @callback_url, method: "post", class: "login", novalidate: true do %> | |
| <div class="control-group"> | |
| <label class="control-label" for="email-input">Email</label> | |
| <input class="form-control" type="email" name="email" value="<%= @conn.params["email"] %>" required /> | |
| </div> | |
| <div class="control-group"> | |
| <label class="control-label" for="password-input">Password</label> | |
| <input class="form-control" type="password" name="password" required /> | |
| </div> |
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 User do | |
| use PhoenixUeberauthComeonin.Web, :model | |
| import Comeonin.Bcrypt | |
| alias Ueberauth.Auth | |
| alias PhoenixUeberauthComeonin.Repo | |
| schema "users" do | |
| field :name, :string |
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
| alias PhoenixUeberauthComeonin.Repo | |
| Repo.insert! %User{ | |
| name: "Administrator", | |
| email: "admin@admin.com", | |
| password: Comeonin.Bcrypt.hashpwsalt("admin") | |
| } |
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
| defp deps do | |
| [ | |
| ... | |
| {:guardian, "~> 0.13.0"} | |
| ] | |
| 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
| def application do | |
| [mod: {PhoenixUeberauthComeonin, []}, | |
| applications: [ | |
| ... | |
| :guardian, | |
| :ueberauth, | |
| :ueberauth_identity, | |
| ] | |
| ] | |
| 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
| config :guardian, Guardian, | |
| allowed_algos: ["HS512"], | |
| verify_module: Guardian.JWT, | |
| issuer: "Metamorfo", | |
| ttl: { 30, :days }, | |
| verify_issuer: true, | |
| secret_key: <<188, 78, 156, 202, 219, 17, 166, 68, 84, 206, 109, 204, 103, 136, 108, | |
| 222>>, | |
| serializer: GuardianSerializer |
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 GuardianSerializer do | |
| @behaviour Guardian.Serializer | |
| alias PhoenixUeberauthComeonin.Repo | |
| 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, id) } | |
| def from_token(_), do: { :error, "Unknown resource type" } |
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 PhoenixUeberauthComeonin.SessionsController do | |
| use PhoenixUeberauthComeonin.Web, :controller | |
| alias Ueberauth.Strategy.Helpers | |
| plug Ueberauth | |
| def new(conn, _params) do | |
| render conn, "new.html", callback_url: Helpers.callback_url(conn), current_user: nil | |
| 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 PhoenixUeberauthComeonin.PageController do | |
| use PhoenixUeberauthComeonin.Web, :controller | |
| plug Guardian.Plug.EnsureAuthenticated, handler: __MODULE__ | |
| def index(conn, _params) do | |
| render conn, "index.html" | |
| end | |
| def unauthenticated(conn, _params) do |
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
| def index(conn, _params) do | |
| user = Guardian.Plug.current_resource(conn) | |
| render conn, "index.html", current_user: user | |
| end |