From a13b80d5aaa88ba3e33db4bcdc1c3b53638ef4bf Mon Sep 17 00:00:00 2001 From: Graham Hay Date: Thu, 12 Feb 2015 18:15:08 +0000 Subject: [PATCH] Added login page --- Makefile | 2 +- priv/static/css/login.css | 40 ++++++++++++++++++++++++++++++ src/cowboy_stormpath.app.src | 3 ++- src/cowboy_stormpath_app.erl | 1 + src/login_handler.erl | 19 ++++++++++++++ templates/login.dtl | 48 ++++++++++++++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 priv/static/css/login.css create mode 100644 src/login_handler.erl create mode 100644 templates/login.dtl diff --git a/Makefile b/Makefile index 1ef6f37..9ef4b35 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ PROJECT = cowboy_stormpath -DEPS = cowboy +DEPS = cowboy erlydtl include erlang.mk diff --git a/priv/static/css/login.css b/priv/static/css/login.css new file mode 100644 index 0000000..3a23349 --- /dev/null +++ b/priv/static/css/login.css @@ -0,0 +1,40 @@ +body { + padding-top: 40px; + padding-bottom: 40px; + background-color: #eee; +} + +.form-signin { + max-width: 330px; + padding: 15px; + margin: 0 auto; +} +.form-signin .form-signin-heading, +.form-signin .checkbox { + margin-bottom: 10px; +} +.form-signin .checkbox { + font-weight: normal; +} +.form-signin .form-control { + position: relative; + height: auto; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + padding: 10px; + font-size: 16px; +} +.form-signin .form-control:focus { + z-index: 2; +} +.form-signin input[type="email"] { + margin-bottom: -1px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; +} +.form-signin input[type="password"] { + margin-bottom: 10px; + border-top-left-radius: 0; + border-top-right-radius: 0; +} diff --git a/src/cowboy_stormpath.app.src b/src/cowboy_stormpath.app.src index 9052d31..a606e12 100644 --- a/src/cowboy_stormpath.app.src +++ b/src/cowboy_stormpath.app.src @@ -7,7 +7,8 @@ {applications, [ kernel, stdlib, - cowboy + cowboy, + erlydtl ]}, {mod, {cowboy_stormpath_app, []}}, {env, []} diff --git a/src/cowboy_stormpath_app.erl b/src/cowboy_stormpath_app.erl index 0bfc25d..d2ca2f5 100644 --- a/src/cowboy_stormpath_app.erl +++ b/src/cowboy_stormpath_app.erl @@ -7,6 +7,7 @@ start(_Type, _Args) -> Dispatch = cowboy_router:compile([ {'_', [ + {"/login", login_handler, []}, {"/", cowboy_static, {priv_file, cowboy_stormpath, "static/index.html"}}, {"/[...]", cowboy_static, {priv_dir, cowboy_stormpath, "static/"}} ]} diff --git a/src/login_handler.erl b/src/login_handler.erl new file mode 100644 index 0000000..0739964 --- /dev/null +++ b/src/login_handler.erl @@ -0,0 +1,19 @@ +-module(login_handler). +-behaviour(cowboy_http_handler). + +-export([init/3]). +-export([handle/2]). +-export([terminate/3]). + +-record(state, {}). + +init(_, Req, _Opts) -> + {ok, Req, #state{}}. + +handle(Req, State=#state{}) -> + {ok, Body} = login_dtl:render(), + {ok, Req2} = cowboy_req:reply(200, [{<<"content-type">>, <<"text/html">>}], Body, Req), + {ok, Req2, State}. + +terminate(_Reason, _Req, _State) -> + ok. diff --git a/templates/login.dtl b/templates/login.dtl new file mode 100644 index 0000000..b000723 --- /dev/null +++ b/templates/login.dtl @@ -0,0 +1,48 @@ + + + + + + + + + + + Log in + + + + + + + + + + + +
+ + + +
+ + + +