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 register(conn, %{"user" => user_params}) do | |
case ElixirStream.RegisterAction.sign_up(user_params) do | |
{:ok, user} -> | |
conn | |
|> put_flash(:info, "You have signed up and logged in!") | |
|> put_session(:user_id, user.id) | |
|> redirect(to: entry_path(conn, :index)) | |
{:error, changeset} -> | |
conn | |
|> render("register_form.html", changeset: changeset) |
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 ElixirStream.RegisterAction do | |
alias ElixirStream.User | |
def sign_up(params) do | |
changeset = User.changeset(%User{}, params) | |
if changeset.valid? do | |
user = ElixirStream.Repo.insert(changeset) | |
{:ok, user} | |
else | |
{:error, changeset} | |
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 set_password_digest(changeset) do | |
password = Ecto.Changeset.get_field(changeset, :password) | |
change(changeset, %{password_digest: crypt_password(password)}) | |
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
model | |
|> cast(params, @required_fields, @optional_fields) |
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
changeset = Entry.changeset(%Entry{}, params) | |
if changeset.valid? do | |
Repo.insert(changeset) | |
## Oh the happy path | |
else | |
## The sad path :( | |
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
Repo.all from e in Entry, order_by: [desc: e.id], preload: [:user] |
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 ElixirStream.Entry do | |
use ElixirStream.Web, :model | |
use Ecto.Model.Callbacks | |
alias ElixirStream.User | |
before_insert :set_slug | |
schema "entries" do | |
field :email, :string | |
field :author_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
{:ok, users_json} = File.read("users.json") | |
{:ok, users_parsed} = JSX.decode(users_json, [{:labels, :atom}]) | |
Enum.map(users_parsed, fn(e)-> %User{username: e.username, password_digest: e.password_digest, email: e.email} end) |> | |
Enum.each(fn(e)-> Repo.insert!(e, false) 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
# In emacs I have this: | |
play_by_play_api_class.play_by_play( | |
game.scheduled_time.year, | |
game.week.season, | |
game.week.nr, | |
game.home_team.abbreviation, | |
game.away_team.abbreviation | |
) | |
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
{ | |
"id": 1, | |
"email": null, | |
"password_digest": null, | |
"token": "446608df-1f80-409d-9815-39146b8876df", | |
"created_at": "2015-05-08T07:26:43.202Z", | |
"updated_at": "2015-05-08T07:26:43.202Z", | |
"full_name": "Janis Miezitis", | |
"phone_number": null, | |
"reset_password_token": null, |