Created
July 1, 2016 06:25
-
-
Save nguyenvinhlinh/7b642b962905baed7a2746427f671b66 to your computer and use it in GitHub Desktop.
This file contains 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 XXX do | |
import Plug.Conn | |
import Phoenix.Controller | |
def __using__(params) do | |
params | |
end | |
defmacro is_edit_path(conn) do | |
conn.request_path == Iea.Router.Helpers.teacher_user_path(conn, :edit_profile) | |
end | |
end | |
defmodule Plug.TeacherProfileControl do | |
import Plug.Conn | |
import Phoenix.Controller | |
alias Iea.User | |
import XXX | |
def init(opt) do | |
opt | |
end | |
def call(conn, _params) when is_edit_path(conn) do | |
conn | |
end | |
def call(conn, _params) do | |
user = conn.assigns.current_user | |
changeset = case user.contract_type do | |
"full time" -> | |
User.fulltime_teacher_update_changeset(user, %{}) | |
"part time" -> | |
User.parttime_teacher_update_changeset(user, %{}) | |
end | |
case changeset.errors do | |
[] -> conn | |
_ -> | |
conn | |
|> redirect(to: Iea.Router.Helpers.teacher_user_path(conn, :edit_profile)) | |
|> halt | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment