diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a152b9f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: elixir +sudo: false +elixir: + - 1.6.6 +otp_release: + - 21.0 +addons: + postgresql: '9.4' +services: + - postgresql +env: + - MIX_ENV=test + +before_script: + - cp config/travis.exs config/test.exs + - mix do ecto.create, ecto.migrate + +script: mix coveralls.travis \ No newline at end of file diff --git a/RequestSample_accounts.http b/RequestSample_accounts.http index d553727..9b310ed 100644 --- a/RequestSample_accounts.http +++ b/RequestSample_accounts.http @@ -15,7 +15,7 @@ Content-Type: application/json "password": "hogehoge" } -@token = Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJNYXRlcmlhIiwiZW1haWwiOiJob2dlaG9nZUBleGFtcGxlLmNvbSIsImV4cCI6MTU0NDAwNDY2NSwiaWF0IjoxNTQ0MDA0MDY1LCJpc3MiOiJNYXRlcmlhIiwianRpIjoiYWYwOTRjNjItZWFjMi00YzcxLWJmYTgtYjgxYjY3NmE1ZWVlIiwibmJmIjoxNTQ0MDA0MDY0LCJzdWIiOiIxIiwidHlwIjoiYWNjZXNzIn0.j6HBnTSyRO1Rs_X4sKHQflRl7c2yTc1QqgRd1y2VLaM +@token = Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJNYXRlcmlhIiwiZW1haWwiOiJob2dlaG9nZUBleGFtcGxlLmNvbSIsImV4cCI6MTU0NTgxMTc4OSwiaWF0IjoxNTQ1ODExMTg5LCJpc3MiOiJNYXRlcmlhIiwianRpIjoiMWEzYmM0ZGMtZWJmYS00MWUyLWJiNjctNDYxMTJmMzU4Njc2IiwibmJmIjoxNTQ1ODExMTg4LCJzdWIiOiJ7XCJ1c2VyX2lkXCI6MX0iLCJ0eXAiOiJhY2Nlc3MifQ.taF2To9CACyPMyZcmDjCi82VKmhA-fq8QApVhfiA8DY ### ユーザー汎用検索 diff --git a/config/travis.exs b/config/travis.exs new file mode 100644 index 0000000..0d20003 --- /dev/null +++ b/config/travis.exs @@ -0,0 +1,32 @@ +use Mix.Config + +# We don't run a server during test. If one is required, +# you can enable the server option below. +config :materia, MateriaWeb.Test.Endpoint, + http: [port: 4001], + #server: false, + debug_errors: true, + code_reloader: false, + check_origin: false, + watchers: [] + +# Print only warnings and errors during test +config :logger, level: :info + +# Configure your database +config :materia, Materia.Test.Repo, + adapter: Ecto.Adapters.Postgres, + username: "postgres", + password: "", + database: "materia_test", + hostname: "localhost", + pool: Ecto.Adapters.SQL.Sandbox + +config :materia, repo: Materia.Test.Repo + +# Configures GuardianDB +config :guardian, Guardian.DB, + repo: Materia.Test.Repo, + schema_name: "guardian_tokens", # default +#token_types: ["refresh_token"], # store all token types if not set + sweep_interval: 60 # default: 60 minutes diff --git a/cover/excoveralls.html b/cover/excoveralls.html index 11728f1..ef526a7 100644 --- a/cover/excoveralls.html +++ b/cover/excoveralls.html @@ -393,7 +393,7 @@

Coverage

  • - 66.7 + 68.1 @@ -514,7 +514,7 @@

    Coverage

  • - 53.3 + 70.6 @@ -703,10 +703,10 @@

    Coverage

    -
    82.3
    -
    558
    -
    9205
    -
    99
    +
    82.8
    +
    564
    +
    9633
    +
    97
    @@ -10720,9 +10720,9 @@

    lib/materia/accounts/user.ex

    lib/materia/authenticator/authenticator.ex

    -
    66.7
    -
    90
    -
    1424
    +
    68.1
    +
    94
    +
    1688
    30
    @@ -10887,20 +10887,20 @@

    lib/materia/authenticator/au -

    + - - + + - + - + - - + + - + @@ -11159,8 +11159,16 @@

    lib/materia/authenticator/au -

    + + + + + + + + + @@ -11168,15 +11176,23 @@

    lib/materia/authenticator/au

    - + - + - + + + + + + + + + @@ -11184,7 +11200,7 @@

    lib/materia/authenticator/au

    - + @@ -11192,7 +11208,7 @@

    lib/materia/authenticator/au

    - + @@ -11200,7 +11216,7 @@

    lib/materia/authenticator/au

    - + @@ -11208,7 +11224,7 @@

    lib/materia/authenticator/au

    - + @@ -11216,7 +11232,7 @@

    lib/materia/authenticator/au

    - + @@ -11224,7 +11240,7 @@

    lib/materia/authenticator/au

    - + @@ -11232,7 +11248,7 @@

    lib/materia/authenticator/au

    - + @@ -11240,7 +11256,7 @@

    lib/materia/authenticator/au

    - + @@ -11248,7 +11264,7 @@

    lib/materia/authenticator/au

    - + @@ -11256,7 +11272,7 @@

    lib/materia/authenticator/au

    - + @@ -11264,7 +11280,7 @@

    lib/materia/authenticator/au

    - + @@ -11272,7 +11288,7 @@

    lib/materia/authenticator/au

    - + @@ -11280,7 +11296,7 @@

    lib/materia/authenticator/au

    - + @@ -11288,15 +11304,15 @@

    lib/materia/authenticator/au

    - + - + - + @@ -11304,7 +11320,7 @@

    lib/materia/authenticator/au

    - + @@ -11312,7 +11328,7 @@

    lib/materia/authenticator/au

    - + @@ -11320,7 +11336,7 @@

    lib/materia/authenticator/au

    - + @@ -11328,7 +11344,7 @@

    lib/materia/authenticator/au

    - + @@ -11336,7 +11352,7 @@

    lib/materia/authenticator/au

    - + @@ -11344,7 +11360,7 @@

    lib/materia/authenticator/au

    - + @@ -11352,7 +11368,7 @@

    lib/materia/authenticator/au

    - + @@ -11360,7 +11376,7 @@

    lib/materia/authenticator/au

    - + @@ -11368,7 +11384,7 @@

    lib/materia/authenticator/au

    - + @@ -11376,7 +11392,7 @@

    lib/materia/authenticator/au

    - + @@ -11384,7 +11400,7 @@

    lib/materia/authenticator/au

    - + @@ -11392,7 +11408,7 @@

    lib/materia/authenticator/au

    - + @@ -11400,7 +11416,7 @@

    lib/materia/authenticator/au

    - + @@ -11408,7 +11424,7 @@

    lib/materia/authenticator/au

    - + @@ -11416,7 +11432,7 @@

    lib/materia/authenticator/au

    - + @@ -11424,7 +11440,7 @@

    lib/materia/authenticator/au

    - + @@ -11432,7 +11448,7 @@

    lib/materia/authenticator/au

    - + @@ -11440,7 +11456,7 @@

    lib/materia/authenticator/au

    - + @@ -11448,7 +11464,7 @@

    lib/materia/authenticator/au

    - + @@ -11456,7 +11472,7 @@

    lib/materia/authenticator/au

    - + @@ -11464,7 +11480,7 @@

    lib/materia/authenticator/au

    - + @@ -11472,7 +11488,7 @@

    lib/materia/authenticator/au

    - + @@ -11480,7 +11496,7 @@

    lib/materia/authenticator/au

    - + @@ -11488,7 +11504,7 @@

    lib/materia/authenticator/au

    - + @@ -11496,7 +11512,7 @@

    lib/materia/authenticator/au

    - + @@ -11504,7 +11520,7 @@

    lib/materia/authenticator/au

    - + @@ -11512,7 +11528,7 @@

    lib/materia/authenticator/au

    - + @@ -11520,7 +11536,7 @@

    lib/materia/authenticator/au

    - + @@ -11528,7 +11544,7 @@

    lib/materia/authenticator/au

    - + @@ -11536,7 +11552,7 @@

    lib/materia/authenticator/au

    - + @@ -11544,7 +11560,7 @@

    lib/materia/authenticator/au

    - + @@ -11552,7 +11568,7 @@

    lib/materia/authenticator/au

    - + @@ -11560,7 +11576,7 @@

    lib/materia/authenticator/au

    - + @@ -11568,7 +11584,7 @@

    lib/materia/authenticator/au

    - + @@ -11576,7 +11592,7 @@

    lib/materia/authenticator/au

    - + @@ -11584,7 +11600,7 @@

    lib/materia/authenticator/au

    - + @@ -11592,7 +11608,7 @@

    lib/materia/authenticator/au

    - + @@ -11600,7 +11616,7 @@

    lib/materia/authenticator/au

    - + @@ -11608,7 +11624,7 @@

    lib/materia/authenticator/au

    - + @@ -11616,7 +11632,7 @@

    lib/materia/authenticator/au

    - + @@ -11624,7 +11640,7 @@

    lib/materia/authenticator/au

    - + @@ -11632,7 +11648,7 @@

    lib/materia/authenticator/au

    - + @@ -11640,7 +11656,7 @@

    lib/materia/authenticator/au

    - + @@ -11648,7 +11664,7 @@

    lib/materia/authenticator/au

    - + @@ -11656,7 +11672,7 @@

    lib/materia/authenticator/au

    - + @@ -11664,7 +11680,7 @@

    lib/materia/authenticator/au

    - + @@ -11672,7 +11688,7 @@

    lib/materia/authenticator/au

    - + @@ -11680,7 +11696,7 @@

    lib/materia/authenticator/au

    - + @@ -11688,7 +11704,7 @@

    lib/materia/authenticator/au

    - + @@ -11696,7 +11712,7 @@

    lib/materia/authenticator/au

    - + @@ -11704,7 +11720,7 @@

    lib/materia/authenticator/au

    - + @@ -11712,7 +11728,7 @@

    lib/materia/authenticator/au

    - + @@ -11720,7 +11736,7 @@

    lib/materia/authenticator/au

    - + @@ -11728,7 +11744,7 @@

    lib/materia/authenticator/au

    - + @@ -11736,7 +11752,7 @@

    lib/materia/authenticator/au

    - + @@ -11744,7 +11760,7 @@

    lib/materia/authenticator/au

    - + @@ -11752,7 +11768,7 @@

    lib/materia/authenticator/au

    - + @@ -11760,7 +11776,7 @@

    lib/materia/authenticator/au

    - + @@ -11768,7 +11784,7 @@

    lib/materia/authenticator/au

    - + @@ -11776,7 +11792,7 @@

    lib/materia/authenticator/au

    - + @@ -11784,7 +11800,7 @@

    lib/materia/authenticator/au

    - + @@ -11792,7 +11808,7 @@

    lib/materia/authenticator/au

    - + @@ -11800,7 +11816,7 @@

    lib/materia/authenticator/au

    - + @@ -11808,7 +11824,7 @@

    lib/materia/authenticator/au

    - + @@ -11816,7 +11832,7 @@

    lib/materia/authenticator/au

    - + @@ -11824,7 +11840,7 @@

    lib/materia/authenticator/au

    - + @@ -11832,7 +11848,7 @@

    lib/materia/authenticator/au

    - + @@ -11840,7 +11856,7 @@

    lib/materia/authenticator/au

    - + @@ -11848,7 +11864,7 @@

    lib/materia/authenticator/au

    - + @@ -11856,7 +11872,7 @@

    lib/materia/authenticator/au

    - + @@ -11864,7 +11880,7 @@

    lib/materia/authenticator/au

    - + @@ -11872,7 +11888,7 @@

    lib/materia/authenticator/au

    - + @@ -11880,7 +11896,7 @@

    lib/materia/authenticator/au

    - + @@ -11888,7 +11904,7 @@

    lib/materia/authenticator/au

    - + @@ -11896,7 +11912,7 @@

    lib/materia/authenticator/au

    - + @@ -11904,7 +11920,7 @@

    lib/materia/authenticator/au

    - + @@ -11912,7 +11928,7 @@

    lib/materia/authenticator/au

    - + @@ -11920,7 +11936,7 @@

    lib/materia/authenticator/au

    - + @@ -11928,7 +11944,7 @@

    lib/materia/authenticator/au

    - + @@ -11936,7 +11952,7 @@

    lib/materia/authenticator/au

    - + @@ -11944,7 +11960,7 @@

    lib/materia/authenticator/au

    - + @@ -11952,7 +11968,7 @@

    lib/materia/authenticator/au

    - + @@ -11960,7 +11976,7 @@

    lib/materia/authenticator/au

    - + @@ -11968,7 +11984,7 @@

    lib/materia/authenticator/au

    - + @@ -11976,7 +11992,7 @@

    lib/materia/authenticator/au

    - + @@ -11984,7 +12000,7 @@

    lib/materia/authenticator/au

    - + @@ -11992,7 +12008,7 @@

    lib/materia/authenticator/au

    - + @@ -12000,7 +12016,7 @@

    lib/materia/authenticator/au

    - + @@ -12008,7 +12024,7 @@

    lib/materia/authenticator/au

    - + @@ -12016,7 +12032,7 @@

    lib/materia/authenticator/au

    - + @@ -12024,7 +12040,7 @@

    lib/materia/authenticator/au

    - + @@ -12032,7 +12048,7 @@

    lib/materia/authenticator/au

    - + @@ -12040,7 +12056,7 @@

    lib/materia/authenticator/au

    - + @@ -12048,7 +12064,7 @@

    lib/materia/authenticator/au

    - + @@ -12056,7 +12072,7 @@

    lib/materia/authenticator/au

    - + @@ -12064,7 +12080,7 @@

    lib/materia/authenticator/au

    - + @@ -12072,7 +12088,7 @@

    lib/materia/authenticator/au

    - + @@ -12080,7 +12096,7 @@

    lib/materia/authenticator/au

    - + @@ -12088,7 +12104,7 @@

    lib/materia/authenticator/au

    - + @@ -12096,7 +12112,7 @@

    lib/materia/authenticator/au

    - + @@ -12104,7 +12120,7 @@

    lib/materia/authenticator/au

    - + @@ -12112,7 +12128,7 @@

    lib/materia/authenticator/au

    - + @@ -12120,7 +12136,7 @@

    lib/materia/authenticator/au

    - + @@ -12128,7 +12144,7 @@

    lib/materia/authenticator/au

    - + @@ -12136,7 +12152,7 @@

    lib/materia/authenticator/au

    - + @@ -12144,7 +12160,7 @@

    lib/materia/authenticator/au

    - + @@ -12152,7 +12168,7 @@

    lib/materia/authenticator/au

    - + @@ -12160,7 +12176,7 @@

    lib/materia/authenticator/au

    - + @@ -12168,7 +12184,7 @@

    lib/materia/authenticator/au

    - + @@ -12176,7 +12192,7 @@

    lib/materia/authenticator/au

    - + @@ -12184,7 +12200,7 @@

    lib/materia/authenticator/au

    - + @@ -12192,7 +12208,7 @@

    lib/materia/authenticator/au

    - + @@ -12200,7 +12216,7 @@

    lib/materia/authenticator/au

    - + @@ -12208,7 +12224,7 @@

    lib/materia/authenticator/au

    - + @@ -12216,7 +12232,7 @@

    lib/materia/authenticator/au

    - + @@ -12224,7 +12240,7 @@

    lib/materia/authenticator/au

    - + @@ -12232,7 +12248,7 @@

    lib/materia/authenticator/au

    - + @@ -12240,7 +12256,7 @@

    lib/materia/authenticator/au

    - + @@ -12248,7 +12264,7 @@

    lib/materia/authenticator/au

    - + @@ -12256,7 +12272,7 @@

    lib/materia/authenticator/au

    - + @@ -12264,7 +12280,7 @@

    lib/materia/authenticator/au

    - + @@ -12272,7 +12288,7 @@

    lib/materia/authenticator/au

    - + @@ -12280,7 +12296,7 @@

    lib/materia/authenticator/au

    - + @@ -12288,7 +12304,7 @@

    lib/materia/authenticator/au

    - + @@ -12296,7 +12312,7 @@

    lib/materia/authenticator/au

    - + @@ -12304,7 +12320,7 @@

    lib/materia/authenticator/au

    - + @@ -12312,7 +12328,7 @@

    lib/materia/authenticator/au

    - + @@ -12320,7 +12336,7 @@

    lib/materia/authenticator/au

    - + @@ -12328,7 +12344,7 @@

    lib/materia/authenticator/au

    - + @@ -12336,7 +12352,7 @@

    lib/materia/authenticator/au

    - + @@ -12344,7 +12360,7 @@

    lib/materia/authenticator/au

    - + @@ -12352,7 +12368,7 @@

    lib/materia/authenticator/au

    - + @@ -12360,7 +12376,7 @@

    lib/materia/authenticator/au

    - + @@ -12368,7 +12384,7 @@

    lib/materia/authenticator/au

    - + @@ -12376,7 +12392,7 @@

    lib/materia/authenticator/au

    - + @@ -12384,7 +12400,7 @@

    lib/materia/authenticator/au

    - + @@ -12392,7 +12408,7 @@

    lib/materia/authenticator/au

    - + @@ -12400,7 +12416,7 @@

    lib/materia/authenticator/au

    - + @@ -12408,7 +12424,7 @@

    lib/materia/authenticator/au

    - + @@ -12416,7 +12432,7 @@

    lib/materia/authenticator/au

    - + @@ -12424,7 +12440,7 @@

    lib/materia/authenticator/au

    - + @@ -12432,7 +12448,7 @@

    lib/materia/authenticator/au

    - + @@ -12440,7 +12456,7 @@

    lib/materia/authenticator/au

    - + @@ -12448,7 +12464,7 @@

    lib/materia/authenticator/au

    - + @@ -12456,7 +12472,7 @@

    lib/materia/authenticator/au

    - + @@ -12464,7 +12480,7 @@

    lib/materia/authenticator/au

    - + @@ -12472,7 +12488,7 @@

    lib/materia/authenticator/au

    - + @@ -12480,7 +12496,7 @@

    lib/materia/authenticator/au

    - + @@ -12488,7 +12504,7 @@

    lib/materia/authenticator/au

    - + @@ -12496,7 +12512,7 @@

    lib/materia/authenticator/au

    - + @@ -12504,7 +12520,7 @@

    lib/materia/authenticator/au

    - + @@ -12512,7 +12528,7 @@

    lib/materia/authenticator/au

    - + @@ -12520,7 +12536,7 @@

    lib/materia/authenticator/au

    - + @@ -12528,7 +12544,7 @@

    lib/materia/authenticator/au

    - + @@ -12536,7 +12552,7 @@

    lib/materia/authenticator/au

    - + @@ -12544,7 +12560,7 @@

    lib/materia/authenticator/au

    - + @@ -12552,7 +12568,7 @@

    lib/materia/authenticator/au

    - + @@ -12560,7 +12576,7 @@

    lib/materia/authenticator/au

    - + @@ -12568,7 +12584,7 @@

    lib/materia/authenticator/au

    - + @@ -12576,7 +12592,7 @@

    lib/materia/authenticator/au

    - + @@ -12584,7 +12600,47 @@

    lib/materia/authenticator/au

    - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -12592,7 +12648,7 @@

    lib/materia/authenticator/au

    - + @@ -12600,7 +12656,7 @@

    lib/materia/authenticator/au

    - + @@ -12608,7 +12664,7 @@

    lib/materia/authenticator/au

    - + @@ -12616,7 +12672,7 @@

    lib/materia/authenticator/au

    - + @@ -12624,7 +12680,7 @@

    lib/materia/authenticator/au

    - + @@ -12632,7 +12688,7 @@

    lib/materia/authenticator/au

    - + @@ -12640,7 +12696,7 @@

    lib/materia/authenticator/au

    - + @@ -12648,7 +12704,7 @@

    lib/materia/authenticator/au

    - + @@ -12656,7 +12712,7 @@

    lib/materia/authenticator/au

    - + @@ -12664,7 +12720,7 @@

    lib/materia/authenticator/au

    - + @@ -12672,7 +12728,7 @@

    lib/materia/authenticator/au

    - + @@ -12680,7 +12736,7 @@

    lib/materia/authenticator/au

    - + @@ -12688,7 +12744,7 @@

    lib/materia/authenticator/au

    - + @@ -12696,7 +12752,7 @@

    lib/materia/authenticator/au

    - + @@ -12704,7 +12760,7 @@

    lib/materia/authenticator/au

    - + @@ -12712,7 +12768,7 @@

    lib/materia/authenticator/au

    - + @@ -12720,7 +12776,7 @@

    lib/materia/authenticator/au

    - + @@ -12728,7 +12784,7 @@

    lib/materia/authenticator/au

    - + @@ -12736,7 +12792,7 @@

    lib/materia/authenticator/au

    - + @@ -12744,7 +12800,7 @@

    lib/materia/authenticator/au

    - + @@ -12752,7 +12808,7 @@

    lib/materia/authenticator/au

    - + @@ -12760,7 +12816,7 @@

    lib/materia/authenticator/au

    - + @@ -12768,7 +12824,7 @@

    lib/materia/authenticator/au

    - + @@ -12776,7 +12832,7 @@

    lib/materia/authenticator/au

    - + @@ -12784,7 +12840,7 @@

    lib/materia/authenticator/au

    - + @@ -12792,7 +12848,7 @@

    lib/materia/authenticator/au

    - + @@ -12800,7 +12856,7 @@

    lib/materia/authenticator/au

    - + @@ -12808,7 +12864,7 @@

    lib/materia/authenticator/au

    - + @@ -12816,7 +12872,7 @@

    lib/materia/authenticator/au

    - + @@ -12824,7 +12880,7 @@

    lib/materia/authenticator/au

    - + @@ -12832,7 +12888,7 @@

    lib/materia/authenticator/au

    - + @@ -12840,7 +12896,7 @@

    lib/materia/authenticator/au

    - + @@ -12848,7 +12904,7 @@

    lib/materia/authenticator/au

    - + @@ -12856,7 +12912,7 @@

    lib/materia/authenticator/au

    - + @@ -12864,7 +12920,7 @@

    lib/materia/authenticator/au

    - + @@ -12872,7 +12928,7 @@

    lib/materia/authenticator/au

    - + @@ -12880,7 +12936,7 @@

    lib/materia/authenticator/au

    - + @@ -12888,7 +12944,7 @@

    lib/materia/authenticator/au

    - + @@ -12896,7 +12952,7 @@

    lib/materia/authenticator/au

    - + @@ -12904,7 +12960,7 @@

    lib/materia/authenticator/au

    - + @@ -12912,7 +12968,7 @@

    lib/materia/authenticator/au

    - + @@ -12920,7 +12976,7 @@

    lib/materia/authenticator/au

    - + @@ -12928,7 +12984,7 @@

    lib/materia/authenticator/au

    - + @@ -12936,7 +12992,7 @@

    lib/materia/authenticator/au

    - + @@ -12944,7 +13000,7 @@

    lib/materia/authenticator/au

    - + @@ -12952,7 +13008,15 @@

    lib/materia/authenticator/au

    - + + + + + + + + + @@ -21455,7 +21519,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21463,13 +21527,21 @@

    lib/materia/plug/grant_checker.ex

    + + + + + + + + - + @@ -21477,7 +21549,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21485,7 +21557,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21493,7 +21565,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21501,7 +21573,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21509,15 +21581,15 @@

    lib/materia/plug/grant_checker.ex

    - + - + - + @@ -21525,7 +21597,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21533,7 +21605,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21541,7 +21613,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21549,7 +21621,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21557,7 +21629,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21565,7 +21637,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21573,7 +21645,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21581,7 +21653,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21589,7 +21661,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21597,7 +21669,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21605,7 +21677,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21613,7 +21685,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21621,7 +21693,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21629,7 +21701,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21637,7 +21709,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21645,7 +21717,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21653,7 +21725,7 @@

    lib/materia/plug/grant_checker.ex

    - + @@ -21815,10 +21887,10 @@

    lib/materia/test_helper/assert

    lib/materia_web/controller_base.ex

    -
    53.3
    -
    15
    -
    73
    -
    7
    +
    70.6
    +
    17
    +
    237
    +
    5

    1948 sub = to_string(resource.id) #sub = to_string(resource.id)
    20 {:ok, sub}48 {:ok, sub} = Poison.encode(%{user_id: resource.id})
    5366 IO.puts("debug000 inspect(user)")
    54
    5455 66 user = Materia.Accounts.get_user!(claims["sub"]) user = Materia.Accounts.get_user!(get_user_id_from_claims(claims))
    555666 IO.puts("debug001 inspect(user)")
    57 66 case claims["typ"] do
    5658 "access" ->
    5759 53 if user.status != User.status.activated do
    5860 0 raise BusinessError, message: @msg_err_invalid_token
    5961 end
    6062 "user_registration" ->
    6163 9 if user.status != User.status.unactivated do
    6264 4 raise BusinessError, message: @msg_err_invalid_token
    6365 end
    6466 "password_reset" ->
    6567 4 if user.status != User.status.activated do
    6668 2 raise BusinessError, message: @msg_err_invalid_token
    6769 end
    6870 _ ->
    6971 0 raise BusinessErrr, message: @msg_err_invalid_token raise BusinessError, message: @msg_err_invalid_token
    7072 end
    7173
    7274 60 with {:ok, _} <- Guardian.DB.on_verify(claims, token) do
    7375 {:ok, claims}
    7476 end
    7577 end
    7678
    7779 def on_refresh({old_token, old_claims}, {new_token, new_claims}, _options) do
    7880 0 Logger.debug("--- #{__MODULE__} on_refresh --------------")
    7981
    8082 #with {:ok, _, _} <- Guardian.DB.on_refresh({old_token, old_claims}, {new_token, new_claims}) do
    8183 0 with {:ok, _, _} <- on_refresh({old_token, old_claims}, {new_token, new_claims}) do
    8284
    8385 0 {:ok, {old_token, old_claims}, {new_token, new_claims}}
    8486 end
    8587 end
    8688
    8789 def on_revoke(claims, token, _options) do
    8890 5 Logger.debug("--- #{__MODULE__} on_revoke --------------")
    8991
    9092 5 with {:ok, _} <- Guardian.DB.on_revoke(claims, token) do
    9193 {:ok, claims}
    9294 end
    9395 end
    9496
    9597 def sign_in(email, password) do
    9698 19 config = get_config()
    9799 19 access_token_ttl = config[:access_token_ttl]
    98100 19 Logger.debug("#{__MODULE__} --- sign_in access_token_ttl:#{inspect(access_token_ttl)}")
    99101
    100102 19 if access_token_ttl == nil do
    101103 0 raise BusinessError, message: "materia.Authenticator access_token_ttl config not found."
    102104 end
    103105
    104106 19 claims = %{"email" => email}
    105107 19 Logger.debug("#{__MODULE__} --- sign_in claims:#{inspect(claims)}")
    106108
    107109 19 with {:ok, nil} <- resource_from_claims(claims) do
    108110 {:error, @msg_err_invalid_email_or_pass}
    109111 else
    110112 {:ok, resource} ->
    111113 19 if resource.status != Materia.Accounts.User.status().activated do
    112114 {:error, @msg_err_invalid_email_or_pass}
    113115 else
    114116 19 if Comeonin.Bcrypt.checkpw(password, resource.hashed_password) do
    115117 17 Logger.debug("#{__MODULE__} --- sign_in Comeonin.Bcrypt.checkpw == true")
    116118 17 with {:ok, access_token, _access_claims} <-
    117119 encode_and_sign(resource, claims, token_type: "access", ttl: access_token_ttl) do
    118120 17 Logger.debug("#{__MODULE__} --- sign_in Materia.Authenticator.encode_and_sign ok")
    119121 17 Logger.debug("#{__MODULE__} --- sign_in access_token:#{access_token}")
    120122 17 result = %{id: resource.id, access_token: access_token}
    121123 17 refresh_token_ttl = config[:refresh_token_ttl]
    122124
    123125 17 Logger.debug(
    124126 17 "#{__MODULE__} --- sign_in refresh_token_ttl:#{inspect(refresh_token_ttl)}"
    125127 )
    126128
    127129 17 if refresh_token_ttl != nil do
    128130 17 refresh_token_ttl = config[:refresh_token_ttl]
    129131
    130132 17 Logger.debug(
    131133 17 "#{__MODULE__} --- sign_in refresh_token_ttl:#{inspect(refresh_token_ttl)}"
    132134 )
    133135
    134136 17 with {:ok, refresh_token, _refresh_claims} <-
    135137 encode_and_sign(
    136138 resource,
    137139 claims,
    138140 token_type: "refresh",
    139141 ttl: refresh_token_ttl
    140142 ) do
    141143 17 result = Map.put(result, :refresh_token, refresh_token)
    142144 {:ok, result}
    143145 else
    144146 _ ->
    145147 {:error, @msg_err_invalid_email_or_pass}
    146148 end
    147149 else
    148150 {:ok, result}
    149151 end
    150152 else
    151153 _ ->
    152154 {:error, @msg_err_invalid_email_or_pass}
    153155 end
    154156 else
    155157 {:error, @msg_err_invalid_email_or_pass}
    156158 end
    157159 end
    158160
    159161 _ ->
    160162 {:error, @msg_err_invalid_email_or_pass}
    161163 end
    162164 end
    163165
    164166 def refresh_tokens(refresh_token) do
    165167 0 config = get_config()
    166168 0 access_token_ttl = config[:access_token_ttl]
    167169 0 Logger.debug("#{__MODULE__} --- refresh_tokens access_token_ttl:#{inspect(access_token_ttl)}")
    168170
    169171 0 if access_token_ttl == nil do
    170172 0 raise BusinessError, message: "materia.Authenticator access_token_ttl config not found."
    171173 end
    172174
    173175 0 with {:ok, _refresh, new_access} <-
    174176 exchange(refresh_token, "refresh", "access", ttl: access_token_ttl) do
    175177 0 {token, claims} = new_access
    176178 0 Logger.debug("#{__MODULE__} --- refresh_tokens new_access_token:#{inspect(token)}")
    177179
    178180 0 with {:ok, _} <- Guardian.DB.after_encode_and_sign(%{}, "access", claims, token) do
    179181 0 refresh_token_ttl = config[:refresh_token_ttl]
    180182
    181183 0 Logger.debug(
    182184 0 "#{__MODULE__} --- refresh_tokens refresh_token_ttl:#{inspect(refresh_token_ttl)}"
    183185 )
    184186
    185187 0 if refresh_token_ttl == nil do
    186188 0 raise BusinessError,
    187189 message: "materia.Authenticator refresh_token_ttl config not found."
    188190 end
    189191
    190192 0 with {:ok, _old_refresh, new_refresh} <- refresh(refresh_token, ttl: refresh_token_ttl) do
    191193 0 {:ok, new_access, new_refresh}
    192194 else
    193195 _ -> {:error, @msg_err_invalid_token}
    194196 end
    195197 else
    196198 _ -> {:error, @msg_err_invalid_token}
    197199 end
    198200 else
    199201 _ -> {:error, @msg_err_invalid_token}
    200202 end
    201203 end
    202204
    203205 def get_user_registration_token(email) do
    204206 9 config = get_config()
    205207 9 user_registration_token_ttl = config[:user_registration_token_ttl]
    206208
    207209 9 Logger.debug("#{__MODULE__} --- get_user_registration_token user_registration_token_ttl:#{inspect(user_registration_token_ttl)}")
    208210
    209211 9 if user_registration_token_ttl == nil do
    210212 0 raise BusinessError, message: "materia.Authenticator user_registration_token_ttl config not found."
    211213 end
    212214
    213215 9 get_custom_token(email, "user_registration", user_registration_token_ttl)
    214216
    215217 end
    216218
    217219 def get_password_reset_token(email) do
    218220 5 config = get_config()
    219221 5 password_reset_token_ttl = config[:password_reset_token_ttl]
    220222
    221223 5 Logger.debug("#{__MODULE__} --- get_password_reset_token password_reset_token_ttl:#{inspect(password_reset_token_ttl)}")
    222224
    223225 5 if password_reset_token_ttl == nil do
    224226 0 raise BusinessError, message: "materia.Authenticator password_reset_token_ttl config not found."
    225227 end
    226228
    227229 5 get_custom_token(email, "password_reset", password_reset_token_ttl)
    228230
    229231 end
    230232
    231233 def get_user_id_from_claims(claims) do
    23466 {:ok, sub} = Poison.decode(claims["sub"])
    23566 user_id = sub["user_id"]
    236 end
    237
    238 @doc false
    232239 defp get_custom_token(email, token_type, token_ttl) do
    233240 14 claims = %{"email" => email}
    234241 14 Logger.debug("#{__MODULE__} --- get_custom_token start. claims:#{inspect(claims)}")
    235242
    236243 14 with {:ok, nil} <- resource_from_claims(claims) do
    237244 {:error, "user not found by claims"}
    238245 else
    239246 {:ok, resource} ->
    240247 14 with {:ok, user_registration_token, _user_claims} <-
    241248 encode_and_sign(
    242249 resource,
    243250 claims,
    244251 token_type: token_type,
    245252 ttl: token_ttl
    246253 ) do
    247254 14 Logger.debug("#{__MODULE__} --- get_custom_token Materia.Authenticator.encode_and_sign ok")
    248255 14 Logger.debug("#{__MODULE__} --- get_custom_token user_registration_token:#{user_registration_token}")
    249256
    250257 {:ok, user_registration_token}
    251258 else
    252259 _ -> {:error, "get_custom_token failed."}
    253260 end
    254261
    255262 _ ->
    256263 {:error, "get_custom_token failed."}
    257264 end
    258265
    259266 end
    260267
    261268 defp get_config() do
    262269 33 config = Application.get_env(:materia, Materia.Authenticator)
    263270
    264271 33 if config == nil do
    265272 0 raise BusinessError, message: "materia.Authenticator config not found."
    266273 else
    267274 33 config
    268275 end
    269276 end
    270277
    271278 defp on_refresh({old_token, old_claims}, {new_token, new_claims}) do
    272279 0 Guardian.DB.on_revoke(old_claims, old_token)
    273280 0 Guardian.DB.after_encode_and_sign(%{}, new_claims["typ"], new_claims, new_token)
    274281
    275282 0 {:ok, {old_token, old_claims}, {new_token, new_claims}}
    276283 end
    277284
    285 end
    7 alias MateriaWeb.ControllerBase
    8
    9 def init(opts) do
    910 0 Logger.debug("#{__MODULE__}--- init---------------------")
    1011 end
    1112
    1213 def call(conn, opts) do
    1314 33 Logger.debug("#{__MODULE__}--- call ---------------------")
    1415 33 user = Accounts.get_user!(conn.private.guardian_default_claims["sub"]) user = Accounts.get_user!(ControllerBase.get_user_id(conn))
    1516 33 grants = Accounts.get_grant_by_role(user.role)
    1617 33 has_grant? = grants
    1718 75 |> Enum.any?(fn(grant) -> ( String.upcase(grant.method) == Grant.method.any or String.upcase(grant.method) == conn.method ) and Regex.match?(~r/#{grant.request_path}[0-9]*/,conn.request_path) end)
    1819
    1920 33 conn =
    2021 if has_grant? do
    2122 33 Logger.debug("#{__MODULE__}--- call has_grant?:#{has_grant?}---------------------")
    2223 33 conn
    2324 else
    2425 0 Logger.debug("#{__MODULE__}--- call has_grant?:#{has_grant?}---------------------")
    2526 conn
    2627 |> halt()
    2728 0 |> send_resp(401, Poison.encode!(%{message: "no grant"}))
    2829 end
    2930 33 conn
    3031 end
    3132
    3233 end
    @@ -21894,9 +21966,9 @@

    lib/materia_web/controller_base.ex +

    - + @@ -21910,16 +21982,40 @@

    lib/materia_web/controller_base.ex +

    - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -21927,7 +22023,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -21935,7 +22031,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -21943,7 +22039,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -21951,7 +22047,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -21959,7 +22055,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -21967,7 +22063,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -21975,7 +22071,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -21983,7 +22079,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -21991,7 +22087,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -21999,7 +22095,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22007,7 +22103,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22015,7 +22111,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22023,7 +22119,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22031,7 +22127,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22039,7 +22135,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22047,7 +22143,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22055,7 +22151,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22063,7 +22159,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22071,7 +22167,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22079,7 +22175,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22087,7 +22183,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22095,7 +22191,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22103,7 +22199,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22111,7 +22207,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22119,7 +22215,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22127,7 +22223,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22135,7 +22231,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22143,7 +22239,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22151,7 +22247,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22159,7 +22255,7 @@

    lib/materia_web/controller_base.ex -

    + @@ -22230,7 +22326,7 @@

    lib/materia_web/contr

    - + @@ -22238,7 +22334,7 @@

    lib/materia_web/contr

    - + @@ -22246,7 +22342,7 @@

    lib/materia_web/contr

    - + @@ -22254,13 +22350,21 @@

    lib/materia_web/contr

    + + + + + + + + - + @@ -22268,7 +22372,7 @@

    lib/materia_web/contr

    - + @@ -22276,7 +22380,7 @@

    lib/materia_web/contr

    - + @@ -22284,7 +22388,7 @@

    lib/materia_web/contr

    - + @@ -22292,7 +22396,7 @@

    lib/materia_web/contr

    - + @@ -22300,7 +22404,7 @@

    lib/materia_web/contr

    - + @@ -22308,7 +22412,7 @@

    lib/materia_web/contr

    - + @@ -22316,7 +22420,7 @@

    lib/materia_web/contr

    - + @@ -22324,7 +22428,7 @@

    lib/materia_web/contr

    - + @@ -22332,7 +22436,7 @@

    lib/materia_web/contr

    - + @@ -22340,7 +22444,7 @@

    lib/materia_web/contr

    - + @@ -22348,7 +22452,7 @@

    lib/materia_web/contr

    - + @@ -22356,7 +22460,7 @@

    lib/materia_web/contr

    - + @@ -22364,23 +22468,31 @@

    lib/materia_web/contr

    - + + + + + + + + + - + - + - + @@ -22388,7 +22500,7 @@

    lib/materia_web/contr

    - + @@ -22396,7 +22508,7 @@

    lib/materia_web/contr

    - + @@ -22404,7 +22516,7 @@

    lib/materia_web/contr

    - + @@ -22412,7 +22524,7 @@

    lib/materia_web/contr

    - + @@ -22420,7 +22532,7 @@

    lib/materia_web/contr

    - + @@ -22428,7 +22540,7 @@

    lib/materia_web/contr

    - + @@ -22436,7 +22548,7 @@

    lib/materia_web/contr

    - + @@ -22444,7 +22556,7 @@

    lib/materia_web/contr

    - + @@ -22452,7 +22564,7 @@

    lib/materia_web/contr

    - + @@ -22460,7 +22572,7 @@

    lib/materia_web/contr

    - + @@ -22468,7 +22580,7 @@

    lib/materia_web/contr

    - + @@ -22476,7 +22588,7 @@

    lib/materia_web/contr

    - + @@ -22484,7 +22596,7 @@

    lib/materia_web/contr

    - + @@ -22492,7 +22604,7 @@

    lib/materia_web/contr

    - + @@ -22500,7 +22612,7 @@

    lib/materia_web/contr

    - + @@ -22508,7 +22620,7 @@

    lib/materia_web/contr

    - + @@ -22516,7 +22628,7 @@

    lib/materia_web/contr

    - + @@ -22524,7 +22636,7 @@

    lib/materia_web/contr

    - + @@ -22532,7 +22644,7 @@

    lib/materia_web/contr

    - + @@ -22540,7 +22652,7 @@

    lib/materia_web/contr

    - + @@ -22548,7 +22660,7 @@

    lib/materia_web/contr

    - + @@ -22556,7 +22668,7 @@

    lib/materia_web/contr

    - + @@ -22564,7 +22676,7 @@

    lib/materia_web/contr

    - + @@ -22572,7 +22684,7 @@

    lib/materia_web/contr

    - + @@ -22580,7 +22692,7 @@

    lib/materia_web/contr

    - + @@ -22588,7 +22700,7 @@

    lib/materia_web/contr

    - + @@ -22596,7 +22708,7 @@

    lib/materia_web/contr

    - + @@ -22604,7 +22716,7 @@

    lib/materia_web/contr

    - + @@ -22612,7 +22724,7 @@

    lib/materia_web/contr

    - + @@ -25084,7 +25196,7 @@

    lib/materia_web/controll

    - + @@ -25092,7 +25204,7 @@

    lib/materia_web/controll

    - + @@ -25100,7 +25212,7 @@

    lib/materia_web/controll

    - + @@ -25108,7 +25220,7 @@

    lib/materia_web/controll

    - + @@ -25116,7 +25228,7 @@

    lib/materia_web/controll

    - + @@ -25124,13 +25236,21 @@

    lib/materia_web/controll

    + + + + + + + + - + @@ -25138,7 +25258,7 @@

    lib/materia_web/controll

    - + @@ -25146,7 +25266,7 @@

    lib/materia_web/controll

    - + @@ -25154,7 +25274,7 @@

    lib/materia_web/controll

    - + @@ -25162,7 +25282,7 @@

    lib/materia_web/controll

    - + @@ -25170,7 +25290,7 @@

    lib/materia_web/controll

    - + @@ -25178,7 +25298,7 @@

    lib/materia_web/controll

    - + @@ -25186,7 +25306,7 @@

    lib/materia_web/controll

    - + @@ -25194,7 +25314,7 @@

    lib/materia_web/controll

    - + @@ -25202,7 +25322,7 @@

    lib/materia_web/controll

    - + @@ -25210,7 +25330,7 @@

    lib/materia_web/controll

    - + @@ -25218,7 +25338,7 @@

    lib/materia_web/controll

    - + @@ -25226,7 +25346,7 @@

    lib/materia_web/controll

    - + @@ -25234,7 +25354,7 @@

    lib/materia_web/controll

    - + @@ -25242,7 +25362,7 @@

    lib/materia_web/controll

    - + @@ -25250,7 +25370,7 @@

    lib/materia_web/controll

    - + @@ -25258,7 +25378,7 @@

    lib/materia_web/controll

    - + @@ -25266,7 +25386,7 @@

    lib/materia_web/controll

    - + @@ -25274,7 +25394,7 @@

    lib/materia_web/controll

    - + @@ -25282,7 +25402,7 @@

    lib/materia_web/controll

    - + @@ -25290,7 +25410,7 @@

    lib/materia_web/controll

    - + @@ -25298,7 +25418,7 @@

    lib/materia_web/controll

    - + @@ -25306,7 +25426,7 @@

    lib/materia_web/controll

    - + @@ -25314,7 +25434,7 @@

    lib/materia_web/controll

    - + @@ -25322,7 +25442,7 @@

    lib/materia_web/controll

    - + @@ -25330,23 +25450,31 @@

    lib/materia_web/controll

    - + + + + + + + + + - + - + - + @@ -25354,7 +25482,7 @@

    lib/materia_web/controll

    - + @@ -25362,7 +25490,7 @@

    lib/materia_web/controll

    - + @@ -25370,7 +25498,7 @@

    lib/materia_web/controll

    - + @@ -25378,7 +25506,7 @@

    lib/materia_web/controll

    - + @@ -25386,7 +25514,7 @@

    lib/materia_web/controll

    - + @@ -25394,7 +25522,7 @@

    lib/materia_web/controll

    - + @@ -25402,7 +25530,7 @@

    lib/materia_web/controll

    - + @@ -25410,7 +25538,7 @@

    lib/materia_web/controll

    - + @@ -25418,7 +25546,7 @@

    lib/materia_web/controll

    - + @@ -25426,7 +25554,7 @@

    lib/materia_web/controll

    - + @@ -25434,7 +25562,7 @@

    lib/materia_web/controll

    - + @@ -25442,7 +25570,7 @@

    lib/materia_web/controll

    - + @@ -25450,7 +25578,7 @@

    lib/materia_web/controll

    - + @@ -25458,7 +25586,7 @@

    lib/materia_web/controll

    - + @@ -25466,7 +25594,7 @@

    lib/materia_web/controll

    - + @@ -25474,7 +25602,7 @@

    lib/materia_web/controll

    - + @@ -25482,7 +25610,7 @@

    lib/materia_web/controll

    - + @@ -25490,7 +25618,7 @@

    lib/materia_web/controll

    - + @@ -25498,7 +25626,7 @@

    lib/materia_web/controll

    - + @@ -25506,7 +25634,7 @@

    lib/materia_web/controll

    - + @@ -25514,7 +25642,7 @@

    lib/materia_web/controll

    - + @@ -25522,7 +25650,7 @@

    lib/materia_web/controll

    - + @@ -25530,7 +25658,7 @@

    lib/materia_web/controll

    - + @@ -25538,7 +25666,7 @@

    lib/materia_web/controll

    - + @@ -25546,7 +25674,7 @@

    lib/materia_web/controll

    - + @@ -25554,7 +25682,7 @@

    lib/materia_web/controll

    - + @@ -25562,7 +25690,7 @@

    lib/materia_web/controll

    - + @@ -25570,7 +25698,7 @@

    lib/materia_web/controll

    - + @@ -25578,7 +25706,7 @@

    lib/materia_web/controll

    - + @@ -25586,7 +25714,7 @@

    lib/materia_web/controll

    - + @@ -25594,7 +25722,7 @@

    lib/materia_web/controll

    - + @@ -25602,23 +25730,31 @@

    lib/materia_web/controll

    - + + + + + + + + + - + - + - + @@ -25626,7 +25762,7 @@

    lib/materia_web/controll

    - + @@ -25634,7 +25770,7 @@

    lib/materia_web/controll

    - + @@ -25642,7 +25778,7 @@

    lib/materia_web/controll

    - + @@ -25650,7 +25786,7 @@

    lib/materia_web/controll

    - + @@ -25658,7 +25794,7 @@

    lib/materia_web/controll

    - + @@ -25666,7 +25802,7 @@

    lib/materia_web/controll

    - + @@ -25674,7 +25810,7 @@

    lib/materia_web/controll

    - + @@ -25682,7 +25818,7 @@

    lib/materia_web/controll

    - + @@ -25690,23 +25826,31 @@

    lib/materia_web/controll

    - + + + + + + + + + - + - + - + @@ -25714,7 +25858,7 @@

    lib/materia_web/controll

    - + @@ -25722,7 +25866,7 @@

    lib/materia_web/controll

    - + @@ -25730,7 +25874,7 @@

    lib/materia_web/controll

    - + @@ -25738,7 +25882,7 @@

    lib/materia_web/controll

    - + @@ -25746,7 +25890,7 @@

    lib/materia_web/controll

    - + @@ -25754,7 +25898,7 @@

    lib/materia_web/controll

    - + @@ -25762,7 +25906,7 @@

    lib/materia_web/controll

    - + @@ -25770,7 +25914,7 @@

    lib/materia_web/controll

    - + @@ -25778,7 +25922,7 @@

    lib/materia_web/controll

    - + @@ -25786,7 +25930,7 @@

    lib/materia_web/controll

    - + @@ -25794,23 +25938,31 @@

    lib/materia_web/controll

    - + + + + + + + + + - + - + - + @@ -25818,7 +25970,7 @@

    lib/materia_web/controll

    - + @@ -25826,7 +25978,7 @@

    lib/materia_web/controll

    - + @@ -25834,7 +25986,7 @@

    lib/materia_web/controll

    - + @@ -25842,7 +25994,7 @@

    lib/materia_web/controll

    - + @@ -25850,7 +26002,7 @@

    lib/materia_web/controll

    - + @@ -25858,7 +26010,7 @@

    lib/materia_web/controll

    - + @@ -25866,7 +26018,7 @@

    lib/materia_web/controll

    - + diff --git a/lib/materia/authenticator/authenticator.ex b/lib/materia/authenticator/authenticator.ex index b45df6e..cae5d31 100644 --- a/lib/materia/authenticator/authenticator.ex +++ b/lib/materia/authenticator/authenticator.ex @@ -17,8 +17,8 @@ defmodule Materia.Authenticator do # A unique `id` is a good subject, a non-unique email address # is a poor subject. Logger.debug("--- #{__MODULE__} subject_for_token --------------") - sub = to_string(resource.id) - {:ok, sub} + #sub = to_string(resource.id) + {:ok, sub} = Poison.encode(%{user_id: resource.id}) end def subject_for_token(_, _) do @@ -52,7 +52,8 @@ defmodule Materia.Authenticator do def on_verify(claims, token, _options) do Logger.debug("--- #{__MODULE__} on_verify --------------") - user = Materia.Accounts.get_user!(claims["sub"]) + user = Materia.Accounts.get_user!(get_user_id_from_claims(claims)) + case claims["typ"] do "access" -> if user.status != User.status.activated do @@ -67,7 +68,7 @@ defmodule Materia.Authenticator do raise BusinessError, message: @msg_err_invalid_token end _ -> - raise BusinessErrr, message: @msg_err_invalid_token + raise BusinessError, message: @msg_err_invalid_token end with {:ok, _} <- Guardian.DB.on_verify(claims, token) do @@ -229,6 +230,11 @@ defmodule Materia.Authenticator do end + def get_user_id_from_claims(claims) do + {:ok, sub} = Poison.decode(claims["sub"]) + user_id = sub["user_id"] + end + @doc false defp get_custom_token(email, token_type, token_ttl) do claims = %{"email" => email} @@ -275,4 +281,5 @@ defmodule Materia.Authenticator do {:ok, {old_token, old_claims}, {new_token, new_claims}} end + end diff --git a/lib/materia/mails/mail_client_aws_ses.ex b/lib/materia/mails/mail_client_aws_ses.ex index e0a1a9b..db9cf66 100644 --- a/lib/materia/mails/mail_client_aws_ses.ex +++ b/lib/materia/mails/mail_client_aws_ses.ex @@ -1,5 +1,7 @@ defmodule Materia.Mails.MailClientAwsSes do + alias Materia.Errors.BusinessError + require Logger @behaviour Materia.Mails.MailClient diff --git a/lib/materia/plug/grant_checker.ex b/lib/materia/plug/grant_checker.ex index 2dfce6c..c19ed16 100644 --- a/lib/materia/plug/grant_checker.ex +++ b/lib/materia/plug/grant_checker.ex @@ -5,6 +5,7 @@ defmodule Materia.Plug.GrantChecker do alias Materia.Accounts alias Materia.Accounts.Grant + alias MateriaWeb.ControllerBase def init(opts) do Logger.debug("#{__MODULE__}--- init---------------------") @@ -12,7 +13,7 @@ defmodule Materia.Plug.GrantChecker do def call(conn, opts) do Logger.debug("#{__MODULE__}--- call ---------------------") - user = Accounts.get_user!(conn.private.guardian_default_claims["sub"]) + user = Accounts.get_user!(ControllerBase.get_user_id(conn)) grants = Accounts.get_grant_by_role(user.role) has_grant? = grants |> Enum.any?(fn(grant) -> ( String.upcase(grant.method) == Grant.method.any or String.upcase(grant.method) == conn.method ) and Regex.match?(~r/#{grant.request_path}[0-9]*/,conn.request_path) end) diff --git a/lib/materia_web/controller_base.ex b/lib/materia_web/controller_base.ex index 71c5cbf..8a33375 100644 --- a/lib/materia_web/controller_base.ex +++ b/lib/materia_web/controller_base.ex @@ -8,7 +8,9 @@ defmodule MateriaWeb.ControllerBase do def get_user_id(conn) do _user_id = try do - conn.private.guardian_default_claims["sub"] + sub = conn.private.guardian_default_claims["sub"] + {:ok, sub_map} = Poison.decode(sub) + sub_map["user_id"] rescue _e in KeyError -> Logger.debug("#{__MODULE__} conn.private.guardian_default_claims[\"sub\"] is not found. anonymus operation!") diff --git a/lib/materia_web/controllers/address_controller.ex b/lib/materia_web/controllers/address_controller.ex index b1212dc..25b6fab 100644 --- a/lib/materia_web/controllers/address_controller.ex +++ b/lib/materia_web/controllers/address_controller.ex @@ -3,6 +3,7 @@ defmodule MateriaWeb.AddressController do alias Materia.Locations alias Materia.Locations.Address + alias MateriaWeb.ControllerBase action_fallback MateriaWeb.FallbackController @@ -21,7 +22,8 @@ defmodule MateriaWeb.AddressController do end def create_my_address(conn, address_params) do - id = String.to_integer(conn.private.guardian_default_claims["sub"]) + #id = String.to_integer(conn.private.guardian_default_claims["sub"]) + id = ControllerBase.get_user_id(conn) address_params = address_params |> Map.put("user_id", id) with {:ok, %Address{} = address} <- Locations.create_address(address_params) do diff --git a/lib/materia_web/controllers/user_controller.ex b/lib/materia_web/controllers/user_controller.ex index dc23af1..7c60f15 100644 --- a/lib/materia_web/controllers/user_controller.ex +++ b/lib/materia_web/controllers/user_controller.ex @@ -3,6 +3,7 @@ defmodule MateriaWeb.UserController do alias Materia.Accounts alias Materia.Accounts.User + alias MateriaWeb.ControllerBase action_fallback MateriaWeb.FallbackController @@ -35,7 +36,8 @@ defmodule MateriaWeb.UserController do def show_me(conn, _params) do Logger.debug("show_me") - id = String.to_integer(conn.private.guardian_default_claims["sub"]) + #id = String.to_integer(conn.private.guardian_default_claims["sub"]) + id = ControllerBase.get_user_id(conn) user = Accounts.get_user!(id) render(conn, "show.json", user: user) end @@ -69,7 +71,8 @@ defmodule MateriaWeb.UserController do end def registration_user(conn, params) do - id = String.to_integer(conn.private.guardian_default_claims["sub"]) + #id = String.to_integer(conn.private.guardian_default_claims["sub"]) + id = ControllerBase.get_user_id(conn) user = Accounts.get_user!(id) conn = MateriaWeb.ControllerBase.transaction_flow(conn, :user, Materia.Accounts, :registration_user, [user, params]) if Map.has_key?(conn, :private) do @@ -80,7 +83,8 @@ defmodule MateriaWeb.UserController do end def registration_user_and_sign_in(conn, params) do - id = String.to_integer(conn.private.guardian_default_claims["sub"]) + #id = String.to_integer(conn.private.guardian_default_claims["sub"]) + id = ControllerBase.get_user_id(conn) user = Accounts.get_user!(id) conn = MateriaWeb.ControllerBase.transaction_flow(conn, :user_token, Materia.Accounts, :registration_user_and_sign_in, [user, params]) token = conn.private.guardian_default_token @@ -93,7 +97,8 @@ defmodule MateriaWeb.UserController do end def reset_my_password(conn, %{"password" => password}) do - id = String.to_integer(conn.private.guardian_default_claims["sub"]) + #id = String.to_integer(conn.private.guardian_default_claims["sub"]) + id = ControllerBase.get_user_id(conn) user = Accounts.get_user!(id) conn = MateriaWeb.ControllerBase.transaction_flow(conn, :user, Materia.Accounts, :reset_my_password, [user, password]) token = conn.private.guardian_default_token diff --git a/mix.exs b/mix.exs index df22fe2..de88c0c 100644 --- a/mix.exs +++ b/mix.exs @@ -50,8 +50,8 @@ defmodule Materia.Mixfile do defp deps do deps_list = [ {:phoenix, "~> 1.3.2"}, - {:phoenix_pubsub, "~> 1.0.2"}, - {:plug, "~> 1.5.1"}, + {:phoenix_pubsub, "~> 1.0"}, + {:plug, "~> 1.5"}, {:phoenix_ecto, "~> 3.2"}, {:postgrex, ">= 0.0.0"}, {:phoenix_html, "~> 2.10"},
    8041 _user_id =
    100 conn.private.guardian_default_claims["sub"]41 sub = conn.private.guardian_default_claims["sub"]
    1141 {:ok, sub_map} = Poison.decode(sub)
    12 #String.to_integer(sub_map["user_id"])
    1341 sub_map["user_id"]
    14 rescue
    1215 0 _e in KeyError ->
    1316 0 Logger.debug("#{__MODULE__} conn.private.guardian_default_claims[\"sub\"] is not found. anonymus operation!")
    1417 0 raise BusinessError, message: "conn.private.guardian_default_claims[\"sub\"] is not found. anonymus operation!\rthis endpoint need Materia.AuthenticatePipeline. check your app's router.ex"
    1518 end
    1619 end
    1720
    1821 def transaction_flow(conn, controler_atom, module, function_atom, attr \\ [%{}]) do
    1922 14 repo = Application.get_env(:materia, :repo)
    2023
    2124 14 try do
    2225 14 with {:ok, result} <- Multi.new
    2326 |> Multi.run(function_atom, module, function_atom, attr)
    2427 |> repo.transaction() do
    2528 11 result_map = Map.new([{controler_atom, result[function_atom]}])
    2629 conn
    2730 |> Plug.Conn.put_status(:created)
    2831 11 |> Phoenix.Controller.render("show.json", result_map)
    2932 else
    3033 {:error, reason} ->
    3134 0 Logger.debug("#{__MODULE__} transaction_flow. Ecto.Multi transaction was failed. #{inspect(reason)}")
    3235 0 raise BusinessError, message: "Ecto.Multi transaction was failed. module:#{inspect(module)} function:#{function_atom}"
    3336 end
    3437 rescue
    3538 3 e ->
    3639 3 Logger.debug("#{__MODULE__} transaction_flow. exception occured.")
    3740 3 e
    3841 end
    3942 end
    4043
    4144 end
    5 alias MateriaWeb.ControllerBase
    6 action_fallback MateriaWeb.FallbackController
    7 action_fallback MateriaWeb.FallbackController
    8
    9 def index(conn, _params) do
    910 5 addresses = Locations.list_addresses()
    1011 5 render(conn, "index.json", addresses: addresses)
    1112 end
    1213
    1314 def create(conn, address_params) do
    1415 1 with {:ok, %Address{} = address} <- Locations.create_address(address_params) do
    1516 conn
    1617 |> put_status(:created)
    1718 |> put_resp_header("location", address_path(conn, :show, address))
    1819 1 |> render("show.json", address: address)
    1920 end
    2021 end
    2122
    2223 def create_my_address(conn, address_params) do
    24 #id = String.to_integer(conn.private.guardian_default_claims["sub"])
    2325 1 id = String.to_integer(conn.private.guardian_default_claims["sub"]) id = ControllerBase.get_user_id(conn)
    2426 1 address_params =
    2527 address_params |> Map.put("user_id", id)
    2628 1 with {:ok, %Address{} = address} <- Locations.create_address(address_params) do
    2729 conn
    2830 |> put_status(:created)
    2931 |> put_resp_header("location", address_path(conn, :show, address))
    3032 1 |> render("show.json", address: address)
    3133 end
    3234 end
    3335
    3436 def show(conn, %{"id" => id}) do
    3537 2 address = Locations.get_address!(id)
    3638 2 render(conn, "show.json", address: address)
    3739 end
    3840
    3941 def update(conn, address_params) do
    4042 1 address = Locations.get_address!(address_params["id"])
    4143
    4244 1 with {:ok, %Address{} = address} <- Locations.update_address(address, address_params) do
    4345 1 render(conn, "show.json", address: address)
    4446 end
    4547 end
    4648
    4749 def delete(conn, %{"id" => id}) do
    4850 2 address = Locations.get_address!(id)
    4951 2 with {:ok, %Address{}} <- Locations.delete_address(address) do
    5052 2 send_resp(conn, :no_content, "")
    5153 end
    5254 end
    5355 end
    5 alias MateriaWeb.ControllerBase
    6 action_fallback MateriaWeb.FallbackController
    7 action_fallback MateriaWeb.FallbackController
    8 require Logger
    9 require Logger
    10
    11 def index(conn, _params) do
    1112 2 users = Accounts.list_users()
    1213 2 render(conn, "index.json", users: users)
    1314 end
    1415
    1516 def list_users_by_params(conn, params) do
    1617 0 users = Accounts.list_users_by_params(params)
    1718 0 render(conn, "index.json", users: users)
    1819 end
    1920
    2021 def create(conn, user_params) do
    2122 2 with {:ok, %User{} = user} <- Accounts.create_user(user_params) do
    2223 conn
    2324 |> put_status(:created)
    2425 |> put_resp_header("location", user_path(conn, :show, user))
    2526 2 |> render("show.json", user: user)
    2627 end
    2728 end
    2829
    2930 def show(conn, %{"id" => id}) do
    3031 2 Logger.debug("show id: #{id}")
    3132 2 user = Accounts.get_user!(id)
    3233 2 render(conn, "show.json", user: user)
    3334 end
    3435
    3536 def show_me(conn, _params) do
    3637 2 Logger.debug("show_me")
    38 #id = String.to_integer(conn.private.guardian_default_claims["sub"])
    3739 2 id = String.to_integer(conn.private.guardian_default_claims["sub"]) id = ControllerBase.get_user_id(conn)
    3840 2 user = Accounts.get_user!(id)
    3941 2 render(conn, "show.json", user: user)
    4042 end
    4143
    4244 def update(conn, user_params) do
    4345 5 user = Accounts.get_user!(user_params["id"])
    4446
    4547 5 with {:ok, %User{} = user} <- Accounts.update_user(user, user_params) do
    4648 5 render(conn, "show.json", user: user)
    4749 end
    4850 end
    4951
    5052 def delete(conn, %{"id" => id}) do
    5153 1 user = Accounts.get_user!(id)
    5254 1 with {:ok, %User{}} <- Accounts.delete_user(user) do
    5355 1 send_resp(conn, :no_content, "")
    5456 end
    5557 end
    5658
    5759 def send_verify_mail(conn, %{"id" => id}) do
    5860 # メールアドレス検証用のメール送信
    5961 0 user = Accounts.get_user!(id)
    6062
    6163 0 with {:ok, _result} = Accounts.send_verify_mail(user) do
    6264 0 send_resp(conn, :no_content, "")
    6365 end
    6466 end
    6567
    6668 def registration_tmp_user(conn, %{"email" => email, "role" => role}) do
    6769 4 MateriaWeb.ControllerBase.transaction_flow(conn, :tmp_user, Materia.Accounts, :regster_tmp_user, [email, role])
    6870 end
    6971
    7072 def registration_user(conn, params) do
    73 #id = String.to_integer(conn.private.guardian_default_claims["sub"])
    7174 3 id = String.to_integer(conn.private.guardian_default_claims["sub"]) id = ControllerBase.get_user_id(conn)
    7275 3 user = Accounts.get_user!(id)
    7376 3 conn = MateriaWeb.ControllerBase.transaction_flow(conn, :user, Materia.Accounts, :registration_user, [user, params])
    7477 3 if Map.has_key?(conn, :private) do
    7578 1 token = conn.private.guardian_default_token
    7679 1 Materia.Authenticator.revoke(token)
    7780 end
    7881 3 conn
    7982 end
    8083
    8184 def registration_user_and_sign_in(conn, params) do
    85 #id = String.to_integer(conn.private.guardian_default_claims["sub"])
    8286 0 id = String.to_integer(conn.private.guardian_default_claims["sub"]) id = ControllerBase.get_user_id(conn)
    8387 0 user = Accounts.get_user!(id)
    8488 0 conn = MateriaWeb.ControllerBase.transaction_flow(conn, :user_token, Materia.Accounts, :registration_user_and_sign_in, [user, params])
    8589 0 token = conn.private.guardian_default_token
    8690 0 Materia.Authenticator.revoke(token)
    8791 0 conn
    8892 end
    8993
    9094 def request_password_reset(conn, %{"email" => email}) do
    9195 5 MateriaWeb.ControllerBase.transaction_flow(conn, :password_reset, Materia.Accounts, :request_password_reset, [email])
    9296 end
    9397
    9498 def reset_my_password(conn, %{"password" => password}) do
    99 #id = String.to_integer(conn.private.guardian_default_claims["sub"])
    95100 2 id = String.to_integer(conn.private.guardian_default_claims["sub"]) id = ControllerBase.get_user_id(conn)
    96101 2 user = Accounts.get_user!(id)
    97102 2 conn = MateriaWeb.ControllerBase.transaction_flow(conn, :user, Materia.Accounts, :reset_my_password, [user, password])
    98103 2 token = conn.private.guardian_default_token
    99104 2 Materia.Authenticator.revoke(token)
    100105 2 conn
    101106 end
    102107
    103108 end