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
brew update | |
brew install elixir | |
mix local.hex | |
mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez | |
//install node.js版本(建議8.0之後) | |
//install postgres版本(建議至少9.4之後) | |
取得dev.secret.exs | |
設定資料庫 mix ecto.setup |
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
... | |
pipeline :api do | |
plug :accepts, ["json"] | |
plug Guardian.Plug.Pipeline, module: GuardianSimpleAuth.Guardian, error_handler: GuardianSimpleAuth.ErrorHandler | |
plug Guardian.Plug.VerifySession, claims: %{"typ" => "access"} | |
plug Guardian.Plug.VerifyHeader, claims: %{"typ" => "access"} | |
plug Guardian.Plug.LoadResource, allow_blank: true | |
end | |
pipeline :auth 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
defmodule BidhouseWeb.Router do | |
use BidhouseWeb, :router | |
use Coherence.Router # Add this | |
use ExAdmin.Router | |
pipeline :browser do | |
plug :accepts, ["html"] | |
plug :fetch_session | |
plug :fetch_flash | |
plug :protect_from_forgery |
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 password_match(conn, _) do | |
owner = Coherence.current_user(conn) | |
house = conn.assigns[:house] | |
password = conn.params["house_bid"]["password"] | |
result = Config.user_schema.checkpw(password, Map.get(owner, Config.password_hash)) | |
if result do | |
conn | |
else |
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
#... | |
@spec init(Keyword.t) :: [tuple] | |
def init(opts) do | |
login = | |
case opts[:login] do | |
true -> true | |
fun when is_function(fun) -> | |
fun | |
other -> | |
case opts[:protected] 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
defmodule BidhouseWeb.HouseBidController do | |
use BidhouseWeb, :controller | |
alias Bidhouse.Origins | |
alias Bidhouse.Origins.HouseBid | |
alias Bidhouse.Coherence.User | |
alias BidhouseWeb.HouseEmail | |
alias BidhouseWeb.Coherence.Mailer |
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
result = from(u in User, where: u.id == 1) |> Repo.one |> Repo.preload(:user_info) | |
result = from(u in User, where: u.id == 1, preload: [:user_info]) |> Repo.one |
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
import Ecto.Query | |
alias YourApp.Repo | |
alias YourApp.User | |
#(這也許是一個改名字的流程) | |
#你要query user.id = 1的人 | |
#抓到這個人之後 | |
#改他的名字 | |
#更新 |
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 changeset(struct, params \\ %{}) do | |
struct | |
|> cast(params, [:house_id]) | |
|> cast_attachments(params, [:image], allow_paths: true) | |
|> validate_required([:image, :house_id]) | |
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
目標:盡可能讓使用者使用上覺得迅速。 | |
改進點:資料下載量少,下載速度快、反應速度快。 | |
Single Page Application: | |
優點 | |
1.更好的用户体验,让用户在web app感受native app的速度和流畅, | |
2.於第一次載入時將html,css,js等預先載入, | |
其後只需透過ajax(非同步載入)方式做資料的傳輸,資料傳輸量較少,只需取得資料即可展現畫面 |