Created
October 20, 2016 21:24
-
-
Save bnhansn/fc1c989c3427ee2c346fe4cb5083f63c to your computer and use it in GitHub Desktop.
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.UserController do | |
| use Sling.Web, :controller | |
| alias Sling.User | |
| def create(conn, params) do | |
| changeset = User.registration_changeset(%User{}, params) | |
| case Repo.insert(changeset) do | |
| {:ok, user} -> | |
| new_conn = Guardian.Plug.api_sign_in(conn, user, :access) | |
| jwt = Guardian.Plug.current_token(new_conn) | |
| new_conn | |
| |> put_status(:created) | |
| |> render(Sling.SessionView, "show.json", user: user, jwt: jwt) | |
| {:error, changeset} -> | |
| conn | |
| |> put_status(:unprocessable_entity) | |
| |> render(Sling.ChangesetView, "error.json", changeset: changeset) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment