Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
begedin committed Oct 4, 2017
1 parent e5d7b0e commit 78ea008
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/code_corps/accounts/changesets.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ defmodule CodeCorps.Accounts.Changesets do
struct
|> Changeset.change(params |> Adapters.User.from_github_user())
|> Changeset.put_change(:sign_up_context, "github")
|> Changeset.unique_constraint(:email)
|> Changeset.validate_inclusion(:type, ["bot", "user"])
|> Changeset.unique_constraint(:email)
|> Changeset.unique_constraint(:github_id)
end

@doc ~S"""
Expand All @@ -26,8 +27,9 @@ defmodule CodeCorps.Accounts.Changesets do
struct
|> Changeset.cast(params, [:github_auth_token, :github_avatar_url, :github_id, :github_username, :type])
|> ensure_email_without_overwriting(params)
|> Changeset.unique_constraint(:email)
|> Changeset.validate_required([:github_auth_token, :github_avatar_url, :github_id, :github_username, :type])
|> Changeset.unique_constraint(:email)
|> Changeset.unique_constraint(:github_id)
end

@spec ensure_email_without_overwriting(Changeset.t, map) :: Changeset.t
Expand Down
1 change: 1 addition & 0 deletions lib/code_corps/github/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ defmodule CodeCorps.GitHub.User do
@spec do_connect(User.t, map, String.t) :: {:ok, User.t} | {:error, Changeset.t}
defp do_connect(%User{} = user, %{} = user_payload, access_token)
when is_binary(access_token) do

Accounts.update_from_github_oauth(user, user_payload, access_token)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule CodeCorps.Repo.Migrations.AddUniqueConstraintToUsersGithubId do
use Ecto.Migration

def change do
create index(:users, [:github_id], unique: true)
end
end
13 changes: 10 additions & 3 deletions priv/repo/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-- PostgreSQL database dump
--

-- Dumped from database version 9.5.4
-- Dumped by pg_dump version 9.5.4
-- Dumped from database version 9.5.1
-- Dumped by pg_dump version 9.5.1

SET statement_timeout = 0;
SET lock_timeout = 0;
Expand Down Expand Up @@ -2566,6 +2566,13 @@ CREATE UNIQUE INDEX user_tasks_user_id_task_id_index ON user_tasks USING btree (
CREATE UNIQUE INDEX users_email_index ON users USING btree (email);


--
-- Name: users_github_id_index; Type: INDEX; Schema: public; Owner: -
--

CREATE UNIQUE INDEX users_github_id_index ON users USING btree (github_id);


--
-- Name: users_lower_username_index; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -3040,5 +3047,5 @@ ALTER TABLE ONLY user_tasks
-- PostgreSQL database dump complete
--

INSERT INTO "schema_migrations" (version) VALUES (20160723215749), (20160804000000), (20160804001111), (20160805132301), (20160805203929), (20160808143454), (20160809214736), (20160810124357), (20160815125009), (20160815143002), (20160816020347), (20160816034021), (20160817220118), (20160818000944), (20160818132546), (20160820113856), (20160820164905), (20160822002438), (20160822004056), (20160822011624), (20160822020401), (20160822044612), (20160830081224), (20160830224802), (20160911233738), (20160912002705), (20160912145957), (20160918003206), (20160928232404), (20161003185918), (20161019090945), (20161019110737), (20161020144622), (20161021131026), (20161031001615), (20161121005339), (20161121014050), (20161121043941), (20161121045709), (20161122015942), (20161123081114), (20161123150943), (20161124085742), (20161125200620), (20161126045705), (20161127054559), (20161205024856), (20161207112519), (20161209192504), (20161212005641), (20161214005935), (20161215052051), (20161216051447), (20161218005913), (20161219160401), (20161219163909), (20161220141753), (20161221085759), (20161226213600), (20161231063614), (20170102130055), (20170102181053), (20170104113708), (20170104212623), (20170104235423), (20170106013143), (20170115035159), (20170115230549), (20170121014100), (20170131234029), (20170201014901), (20170201025454), (20170201035458), (20170201183258), (20170220032224), (20170224233516), (20170226050552), (20170228085250), (20170308214128), (20170308220713), (20170308222552), (20170313130611), (20170318032449), (20170318082740), (20170324194827), (20170424215355), (20170501225441), (20170505224222), (20170526095401), (20170602000208), (20170622205732), (20170626231059), (20170628092119), (20170628213609), (20170629183404), (20170630140136), (20170706132431), (20170707213648), (20170711122252), (20170717092127), (20170725060612), (20170727052644), (20170731130121), (20170814131722), (20170913114958), (20170921014405), (20170925214512), (20170925230419), (20170926134646), (20170927100300), (20170928234412);
INSERT INTO "schema_migrations" (version) VALUES (20160723215749), (20160804000000), (20160804001111), (20160805132301), (20160805203929), (20160808143454), (20160809214736), (20160810124357), (20160815125009), (20160815143002), (20160816020347), (20160816034021), (20160817220118), (20160818000944), (20160818132546), (20160820113856), (20160820164905), (20160822002438), (20160822004056), (20160822011624), (20160822020401), (20160822044612), (20160830081224), (20160830224802), (20160911233738), (20160912002705), (20160912145957), (20160918003206), (20160928232404), (20161003185918), (20161019090945), (20161019110737), (20161020144622), (20161021131026), (20161031001615), (20161121005339), (20161121014050), (20161121043941), (20161121045709), (20161122015942), (20161123081114), (20161123150943), (20161124085742), (20161125200620), (20161126045705), (20161127054559), (20161205024856), (20161207112519), (20161209192504), (20161212005641), (20161214005935), (20161215052051), (20161216051447), (20161218005913), (20161219160401), (20161219163909), (20161220141753), (20161221085759), (20161226213600), (20161231063614), (20170102130055), (20170102181053), (20170104113708), (20170104212623), (20170104235423), (20170106013143), (20170115035159), (20170115230549), (20170121014100), (20170131234029), (20170201014901), (20170201025454), (20170201035458), (20170201183258), (20170220032224), (20170224233516), (20170226050552), (20170228085250), (20170308214128), (20170308220713), (20170308222552), (20170313130611), (20170318032449), (20170318082740), (20170324194827), (20170424215355), (20170501225441), (20170505224222), (20170526095401), (20170602000208), (20170622205732), (20170626231059), (20170628092119), (20170628213609), (20170629183404), (20170630140136), (20170706132431), (20170707213648), (20170711122252), (20170717092127), (20170725060612), (20170727052644), (20170731130121), (20170814131722), (20170913114958), (20170921014405), (20170925214512), (20170925230419), (20170926134646), (20170927100300), (20170928234412), (20171003134956);

0 comments on commit 78ea008

Please sign in to comment.