Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
suazi committed Jun 5, 2019
1 parent 5ed8efb commit 72ed792
Show file tree
Hide file tree
Showing 62 changed files with 2,009 additions and 927 deletions.
78 changes: 66 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,74 @@
# Barcamp

To start your Phoenix server:
Requirements:

* Install dependencies with `mix deps.get`
* Create and migrate your database with `mix ecto.setup`
* Install Node.js dependencies with `cd assets && npm install`
* Start Phoenix endpoint with `mix phx.server`
* `elixir`
* `nodejs`
* `yarn` (install `node` first, then install `yarn` with `npm i -g yarn`, do NOT install it with `brew` or `apt`)
* `postgresql`

Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.

Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html).
### Building Releases

## Learn more
Add a `config/prod.secret.exs` file and put your very secret configs in there:
```
use Mix.Config
* Official website: http://www.phoenixframework.org/
* Guides: https://hexdocs.pm/phoenix/overview.html
* Docs: https://hexdocs.pm/phoenix
* Mailing list: http://groups.google.com/group/phoenix-talk
* Source: https://github.com/phoenixframework/phoenix
config :barcamp, BarcampWeb.Endpoint,
secret_key_base: "__SECRET_KEY__"
config :barcamp, Barcamp.Repo,
username: "__DB_USER__",
password: "__DB_PASSWORD__",
database: "barcamp_prod",
hostname: "localhost",
pool_size: 10
```

You may use `mix phx.gen.secret` to generate a secret key.

Replace the CA in `priv/cert/barcamp_key.pem` and `priv/cert/barcamp.pem` with your public CA.

Build everything:
```
mix deps.get --only prod
MIX_ENV=prod mix compile
yarn --cwd assets install && yarn --cwd assets deploy
mix phx.digest
MIX_ENV=prod mix do ecto.create, release
```

See it in action:
```
mkdir deploy_here
cp _build/prod/rel/barcamp/releases/0.1.0/barcamp.tar.gz deploy_here/
cd deploy_here
tar xvf barcamp.tar.gz
PORT=4001 ./bin/barcamp start
./bin/barcamp migrate
./bin/barcamp create_user login password0!
```

Then navigate to `localhost:4001`.

_Note:_ You do not need to have erlang or elixir where you are deploying a release.

### Updates / Hot-Code-Swap

Bump the version:
```
def project do
[
...
version: "0.1.1", # Bump the version here
...
]
end
```

Then:
```
MIX_ENV=prod mix release --upgrade
cp _build/prod/rel/barcamp/releases/0.1.1/barcamp.tar.gz deploy_here/releases/0.1.1/
./deploy_here/bin/barcamp upgrade 0.1.1
14 changes: 7 additions & 7 deletions assets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,30 @@ $(document).ready(function () {
$("#livestream").carousel("pause")

$("#_big_hall").click(function () {
$("#livestream").carousel(1);
$("#livestream").carousel(0);
})

$("#_308E").click(function () {
$("#livestream").carousel(2);
$("#livestream").carousel(1);
})

$("#_208E").click(function () {
$("#livestream").carousel(3);
$("#livestream").carousel(2);
})

$("#_213W").click(function () {
$("#livestream").carousel(4);
$("#livestream").carousel(3);
})

$("#_214W").click(function () {
$("#livestream").carousel(5);
$("#livestream").carousel(4);
})

$("#_114W").click(function () {
$("#livestream").carousel(6);
$("#livestream").carousel(5);
})

$("#_113W").click(function () {
$("#livestream").carousel(7);
$("#livestream").carousel(6);
})
})
21 changes: 12 additions & 9 deletions assets/src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,13 @@ section:first-of-type.index {
section:first-of-type.about-faq {
.center {
position: absolute;
top: 15%;
left: 50%;
top: 40px;
right: 120px;
bottom: 40px;
left: 120px;

width: 500px;
max-height: 390px;

margin-left: -230px;
padding: 5px;
overflow: scroll;

Expand All @@ -303,8 +303,6 @@ section:first-of-type.about-faq {
left: 80px;

width: 270px;

margin-left: initial;
}
}
}
Expand All @@ -331,6 +329,10 @@ section.sponsors {

.logo-group {
margin-bottom: 24px;

@include breakpoint(mobile) {
margin-right: 20px;
}
}

.logo {
Expand Down Expand Up @@ -653,15 +655,16 @@ section.timetable .calendar {
}

.time, .slot {
height: 125px;
// height: 125px;

@include breakpoint(mobile) {
height: initial;
}
}

.time {
display: flex;
display: none;
// display: flex;
align-items: center;
justify-content: center;

Expand All @@ -673,7 +676,7 @@ section.timetable .calendar {
.slot {
padding: 4px;

border-bottom: 1px solid $light-gray;
// border-bottom: 1px solid $light-gray;

@include breakpoint(mobile) {
padding-right: 0;
Expand Down
16 changes: 13 additions & 3 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@ use Mix.Config
# which you should run after static files are built and
# before starting your production server.
config :barcamp, BarcampWeb.Endpoint,
http: [:inet6, port: System.get_env("PORT") || 4000],
url: [host: "example.com", port: 80],
cache_static_manifest: "priv/static/cache_manifest.json"
https: [
:inet6,
port: {:system, "PORT"},
cipher_suite: :strong,
keyfile: "priv/cert/barcamp_key.pem",
certfile: "priv/cert/barcamp.pem"
],
url: [host: "localhost", port: {:system, "PORT"}],
force_ssl: [host: nil],
cache_static_manifest: "priv/static/cache_manifest.json",
server: true,
root: ".",
version: Application.spec(:phoenix_distillery, :vsn)

# Do not print debug messages in production
config :logger, level: :info
Expand Down
24 changes: 24 additions & 0 deletions lib/barcamp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,28 @@ defmodule Barcamp do
Contexts are also responsible for managing your data, regardless
if it comes from the database, an external API or others.
"""

require Logger

def migrate do
case Application.ensure_all_started(:barcamp) do
{:ok, _} ->
path = Application.app_dir(:barcamp, "priv/repo/migrations")
Ecto.Migrator.run(Barcamp.Repo, path, :up, all: true)
Logger.info("Success!")

{:error, data} ->
Logger.info("Migration unsuccessful, got: #{inspect(data)}")
end
end

def seed do
case :barcamp |> Application.app_dir("priv/repo/seeds.exs") |> Code.eval_file() do
{{:ok, _}, _} ->
Logger.info("Success!")

{{:error, changeset}, _} ->
Logger.info("Seed unsuccessful, got: #{inspect(changeset)}")
end
end
end
126 changes: 126 additions & 0 deletions lib/barcamp/auth.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
defmodule Barcamp.Auth do
@moduledoc """
The Auth context.
"""

import Ecto.Query, warn: false
alias Barcamp.Repo

alias Barcamp.Auth.User

@doc """
Returns the list of users.
## Examples
iex> list_users()
[%User{}, ...]
"""
def list_users do
Repo.all(User)
end

@doc """
Gets a single user.
Raises `Ecto.NoResultsError` if the User does not exist.
## Examples
iex> get_user!(123)
%User{}
iex> get_user!(456)
** (Ecto.NoResultsError)
"""
def get_user!(id), do: Repo.get!(User, id)

@doc """
Creates a user.
## Examples
iex> create_user(%{field: value})
{:ok, %User{}}
iex> create_user(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_user(attrs \\ %{}) do
result =
%User{}
|> User.registration_changeset(attrs)
|> Repo.insert()

case result do
{:ok, user} -> {:ok, %User{user | password: nil}}
_ -> result
end
end

@doc """
Updates a user.
## Examples
iex> update_user(user, %{field: new_value})
{:ok, %User{}}
iex> update_user(user, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_user(%User{} = user, attrs) do
user
|> User.changeset(attrs)
|> Repo.update()
end

@doc """
Deletes a User.
## Examples
iex> delete_user(user)
{:ok, %User{}}
iex> delete_user(user)
{:error, %Ecto.Changeset{}}
"""
def delete_user(%User{} = user) do
Repo.delete(user)
end

@doc """
Returns an `%Ecto.Changeset{}` for tracking user changes.
## Examples
iex> change_user(user)
%Ecto.Changeset{source: %User{}}
"""
def change_user(%User{} = user) do
User.changeset(user, %{})
end

def authenticate(login, password) do
user = Repo.get_by(User, login: login)

case check_password(user, password) do
true -> {:ok, user}
_ -> :error
end
end

defp check_password(user, password) do
case user do
nil -> Comeonin.Argon2.dummy_checkpw()
_ -> Comeonin.Argon2.checkpw(password, user.password_hash)
end
end
end
Loading

0 comments on commit 72ed792

Please sign in to comment.