Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit ecaed3f56295b8e27cf6bf96df40392aac913bcf Tristan committed Sep 9, 2009
Showing with 2,334 additions and 0 deletions.
  1. +14 −0 _build.cfg
  2. +25 −0 bin/ceug
  3. +42 −0 config/sys.config
  4. +7 −0 deploy
  5. +17 −0 lib/blog/Emakefile
  6. +5 −0 lib/blog/Makefile
  7. +14 −0 lib/blog/ebin/blog.app
  8. BIN lib/blog/ebin/blog_app.beam
  9. BIN lib/blog/ebin/web_index.beam
  10. +37 −0 lib/blog/src/blog_app.erl
  11. +21 −0 lib/blog/src/pages/web_index.erl
  12. +50 −0 lib/blog/src/pages/web_login.erl
  13. +30 −0 lib/blog/src/pages/web_post.erl
  14. +93 −0 lib/blog/src/pages/web_register.erl
  15. +9 −0 lib/blog/start.sh
  16. +5 −0 lib/blog/wwwroot/css/default.css
  17. +82 −0 lib/blog/wwwroot/nitrogen/basic.css
  18. BIN lib/blog/wwwroot/nitrogen/black_bl.png
  19. BIN lib/blog/wwwroot/nitrogen/black_br.png
  20. BIN lib/blog/wwwroot/nitrogen/black_tl.png
  21. BIN lib/blog/wwwroot/nitrogen/black_tr.png
  22. BIN lib/blog/wwwroot/nitrogen/checkmark.png
  23. +143 −0 lib/blog/wwwroot/nitrogen/elements.css
  24. BIN lib/blog/wwwroot/nitrogen/flash_bg.png
  25. BIN lib/blog/wwwroot/nitrogen/gray_bl.png
  26. BIN lib/blog/wwwroot/nitrogen/gray_br.png
  27. BIN lib/blog/wwwroot/nitrogen/gray_tl.png
  28. BIN lib/blog/wwwroot/nitrogen/gray_tr.png
  29. +273 −0 lib/blog/wwwroot/nitrogen/jquery-ui.js
  30. BIN lib/blog/wwwroot/nitrogen/jquery-ui/images/ui-bg_flat_0_aaaaaa_40x100.png
  31. BIN lib/blog/wwwroot/nitrogen/jquery-ui/images/ui-bg_flat_75_ffffff_40x100.png
  32. BIN lib/blog/wwwroot/nitrogen/jquery-ui/images/ui-bg_glass_55_fbf9ee_1x400.png
  33. BIN lib/blog/wwwroot/nitrogen/jquery-ui/images/ui-bg_glass_65_ffffff_1x400.png
  34. BIN lib/blog/wwwroot/nitrogen/jquery-ui/images/ui-bg_glass_75_dadada_1x400.png
  35. BIN lib/blog/wwwroot/nitrogen/jquery-ui/images/ui-bg_glass_75_e6e6e6_1x400.png
  36. BIN lib/blog/wwwroot/nitrogen/jquery-ui/images/ui-bg_glass_95_fef1ec_1x400.png
  37. BIN lib/blog/wwwroot/nitrogen/jquery-ui/images/ui-bg_highlight-soft_75_cccccc_1x100.png
  38. BIN lib/blog/wwwroot/nitrogen/jquery-ui/images/ui-icons_222222_256x240.png
  39. BIN lib/blog/wwwroot/nitrogen/jquery-ui/images/ui-icons_2e83ff_256x240.png
  40. BIN lib/blog/wwwroot/nitrogen/jquery-ui/images/ui-icons_454545_256x240.png
  41. BIN lib/blog/wwwroot/nitrogen/jquery-ui/images/ui-icons_888888_256x240.png
  42. BIN lib/blog/wwwroot/nitrogen/jquery-ui/images/ui-icons_cd0a0a_256x240.png
  43. +405 −0 lib/blog/wwwroot/nitrogen/jquery-ui/jquery-ui.css
  44. +19 −0 lib/blog/wwwroot/nitrogen/jquery.js
  45. +4 −0 lib/blog/wwwroot/nitrogen/livevalidation.js
  46. +3 −0 lib/blog/wwwroot/nitrogen/nitrogen.css
  47. +506 −0 lib/blog/wwwroot/nitrogen/nitrogen.js
  48. +52 −0 lib/blog/wwwroot/nitrogen/reset.css
  49. BIN lib/blog/wwwroot/nitrogen/spinner.gif
  50. BIN lib/blog/wwwroot/nitrogen/spinner2.gif
  51. BIN lib/blog/wwwroot/nitrogen/white_bl.png
  52. BIN lib/blog/wwwroot/nitrogen/white_br.png
  53. BIN lib/blog/wwwroot/nitrogen/white_tl.png
  54. BIN lib/blog/wwwroot/nitrogen/white_tr.png
  55. +28 −0 lib/blog/wwwroot/template.html
  56. +4 −0 lib/blog_db/doc/overview.edoc
  57. +15 −0 lib/blog_db/ebin/blog_db.app
  58. +10 −0 lib/blog_db/include/config.hrl
  59. +60 −0 lib/blog_db/src/blog_db_app.erl
  60. +68 −0 lib/blog_db/src/blog_db_sup.erl
  61. +141 −0 lib/blog_db/src/db_connection_server.erl
  62. +152 −0 lib/blog_db/src/db_interface.erl
@@ -0,0 +1,14 @@
+project : {
+ name : ceug
+ vsn : "0.1.0.0"
+},
+
+build_dir : _build,
+
+ignore_dirs : ["_",
+ "."],
+
+ignore_apps : [],
+
+
+
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+PROG=$0
+PROG_DIR=$(cd `dirname $0`; pwd)
+test -h $0 && PROG=$(readlink $0)
+PREFIX=$(dirname $PROG_DIR)
+
+#### Fill in values for these variables ####
+REL_NAME=ceug
+REL_VSN=0.1.0.0
+ERTS_VSN=5.7.1
+INVOCATION_SUFFIX="$@"
+###########################################
+
+
+export ROOTDIR=$PREFIX
+ERTS_DIR=$ROOTDIR/erts-$ERTS_VSN
+export BINDIR=$ERTS_DIR/bin
+export EMU=beam
+export PROGNAME=erl
+export LD_LIBRARY_PATH=$ERTS_DIR/lib
+
+REL_DIR=$PREFIX/releases/$REL_NAME-$REL_VSN
+
+$BINDIR/erlexec -sname ceug -config $REL_DIR/sys.config -boot $REL_DIR/$REL_NAME $INVOCATION_SUFFIX
@@ -0,0 +1,42 @@
+%%% -*- mode:erlang -*-
+%%% Warning - this config file *must* end with <dot><whitespace>
+
+%% write log files to sasl_dir
+[
+ {sasl,
+ [
+ {sasl_error_logger, {file, "/tmp/chatyeo.sasl_log"}}
+ ]
+ },
+
+ %% (G)eneric (A)pplication (S)services config below here. This default config provides
+ %% the release with log rotaion and trunctation.
+ {gas,
+ [
+ {mod_specs, [{elwrap, {ewl_elwrap_h, start_link}}]},
+
+ {wiring, [
+ {elwrap, [
+ {wire, sasl, sasl_error_logger, "V:{sasl_error_logger, V}"},
+ {err_log, "/tmp/chatyeo.err_log"},
+ {err_log_wrap_info, {{err,5000000,10},{sasl,5000000,10}}},
+ {transform_previous, "V:[V]"}
+ ]}
+ ]
+ },
+
+ {err_log_tty, true} % Log to the screen
+
+ ]
+ },
+
+ {blog,
+ [
+ {platform, yaws}, %% {inets|yaws|mochiweb}
+ {port, 8000},
+ {session_timeout, 720},
+ {sign_key, "SIGN_KEY"},
+ {wwwroot, "/home/tristan/Devel/ceug/lib/blog/wwwroot"}
+ ]
+ }
+].
7 deploy
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+echo Deploying CEUG Blog
+
+/usr/local/erlware/bin/sinan dist
+sudo /usr/local/erlware/bin/faxien ir _build/development/tar/ceug-0.1.0.0.tar.gz
+
@@ -0,0 +1,17 @@
+{ './src/*', [
+ { i, "./include" },
+ { outdir, "./ebin" },
+ debug_info
+]}.
+
+{ './src/*/*', [
+ { i, "./include" },
+ { outdir, "./ebin" },
+ debug_info
+]}.
+
+{ './src/*/*/*', [
+ { i, "./include" },
+ { outdir, "./ebin" },
+ debug_info
+]}.
@@ -0,0 +1,5 @@
+compile:
+ erl -make
+
+clean:
+ rm -rf ./ebin/*.beam
@@ -0,0 +1,14 @@
+{application, blog, [
+ {description, "Nitrogen Website"},
+ {mod, {blog_app, []}},
+ {vsn, "0.1.0"},
+ {modules, [
+ blog_app,
+ web_index,
+ web_post,
+ web_login,
+ web_register
+ ]},
+ {registered,[blog]},
+ {applications, [kernel, stdlib, sasl, gas]}
+]}.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,37 @@
+-module (blog_app).
+-export ([start/2, stop/1, route/1, request/1]).
+-behavior(application).
+
+start(_, _) -> nitrogen:start(blog).
+stop(_) -> nitrogen:stop().
+
+%% route/1 lets you define new URL routes to your web pages,
+%% or completely create a new routing scheme.
+%% The 'Path' argument specifies the request path. Your
+%% function should return either an atom which is the page module
+%% to run, or a tuple containing {Module, PathInfo}. PathInfo
+%% can be accessed using wf:get_path_info().
+%%
+%% Uncomment the line below to direct requests
+%% from "/web/newroute" to the web_index module:
+%%
+%% route("/web/newroute") -> web_index;
+%%
+%% Uncomment the line below to direct requests
+%% from "/web/newroute" to the web_index module,
+%% with trailing PathInfo included:
+%%
+%% route("/web/newroute/" ++ PathInfo) -> {web_index, PathInfo};
+
+route(Path) -> nitrogen:route(Path).
+
+
+%% request/1 is executed before every Nitrogen page, and lets
+%% you add authentication and authorization. The 'Module' argument
+%% is the name of the page module.
+%% This function should return either 'ok' if processing can proceed,
+%% or it can return a full-fledged page by treating it just like the main function
+%% of a page. Alternatively, you can use the wf:redirect* functions to
+%% issue a client-side redirect to a new page.
+
+request(Module) -> nitrogen:request(Module).
@@ -0,0 +1,21 @@
+-module (web_index).
+-include_lib ("nitrogen/include/wf.inc").
+-compile(export_all).
+
+main() ->
+ #template { file=nitrogen:get_wwwroot()++"/template.html"}.
+
+title() ->
+ "CEUG Blog".
+
+body() ->
+ Posts = db_interface:get_posts(),
+ lists:map(fun([Title, Post]) ->
+ #p {body=
+ [#h1{class="title", text=Title},
+ #span{class="post", text=Post},
+ #hr{}]}
+ end, Posts).
+
+event(_) ->
+ ok.
@@ -0,0 +1,50 @@
+-module (web_login).
+-include_lib ("nitrogen/include/wf.inc").
+-compile(export_all).
+
+main() ->
+ case wf:user() of
+ undefined ->
+ #template { file=nitrogen:get_wwwroot()++"/template.html" };
+ _ ->
+ wf:redirect("post")
+ end.
+
+title() -> "CEUG Blog".
+headline() -> "Validation".
+
+body() ->
+ Cell1 = #tablecell { body = ["Login",
+ #br{}] },
+ Cell2a = #tablecell { body = ["Username: "] },
+ Cell2b = #tablecell { body = [#textbox { id=username, postback=login }] },
+ Cell3a = #tablecell { body = ["Password: "] },
+ Cell3b = #tablecell { body = [#password { id=pass, postback=login }] },
+
+ Row1 = #tablerow {cells = [Cell1] },
+ Row2 = #tablerow {cells = [Cell2a,Cell2b] },
+ Row3 = #tablerow {cells = [Cell3a,Cell3b] },
+
+ Body = [#table {rows=[Row1, Row2, Row3]},
+ #button { id=submit, text="Login", postback=login }],
+
+ wf:wire(submit, username, #validate { validators=[
+ #is_required { text="Required." }
+ ]}),
+
+ wf:render(Body).
+
+event (login) ->
+ Username = hd(wf:q(username)),
+ Password = hd(wf:q(pass)),
+
+ case db_interface:validate_user(Username, Password) of
+ {ok, valid} ->
+ wf:user(Username),
+ wf:redirect("post");
+ {error, _Reason} ->
+ wf:flash ("Incorrect")
+ end;
+
+event (_) ->
+ ok.
@@ -0,0 +1,30 @@
+-module (web_post).
+-include_lib ("nitrogen/include/wf.inc").
+-compile(export_all).
+
+main() ->
+ case wf:user() of
+ undefined ->
+ wf:redirect("login");
+ _ ->
+ #template { file=nitrogen:get_wwwroot()++"/template.html"}
+ end.
+
+title() ->
+ "CEUG Blog: New Post".
+
+body() ->
+ [#table{rows=[
+ #tablerow {cells=[#tablecell{body=[#textbox {id=title, class="textbox_input"}]}]},
+ #tablerow {cells=[#tablecell{body=[#textarea {id=post, class="textarea_input"}]}]},
+ #tablerow {cells=[#tablecell{body=[#button {id=submit, text="Submit",
+ postback=submit}]}]}
+ ]}].
+
+event(submit) ->
+ [Title] = wf:q(title),
+ [Post] = wf:q(post),
+ db_interface:submit_post(Title, Post),
+ wf:flash("Post Saved!");
+event(_) ->
+ ok.
@@ -0,0 +1,93 @@
+%%% This file is part of beerenthusiasts.
+%%%
+%%% beerenthusiasts is free software: you can redistribute it and/or modify
+%%% it under the terms of the GNU Affero General Public License as published by
+%%% the Free Software Foundation, either version 3 of the License, or
+%%% (at your option) any later version.
+%%%
+%%% beerenthusiasts is distributed in the hope that it will be useful,
+%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
+%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+%%% GNU Affero General Public License for more details.
+%%%
+%%% You should have received a copy of the GNU Affero General Public License
+%%% along with beerenthusiasts. If not, see <http://www.gnu.org/licenses/>.
+
+-module (web_register).
+-include_lib ("nitrogen/include/wf.inc").
+-compile(export_all).
+
+main() ->
+ wf:wire(submit, username, #validate { attach_to=username, validators=[#is_required { text="Required." }] }),
+ wf:wire(submit, username, #validate { attach_to=username, validators=[#custom { text="Username already registered.", function=(fun (X, Y) -> is_username_used (X, Y) end) }] }),
+ wf:wire(submit, username, #validate { attach_to=username, validators=[#custom { text="Error: No spaces allowed in username.", function=(fun (X, Y) -> check_username (X, Y) end) }] }),
+ wf:wire(submit, username, #validate { attach_to=username, validators=[#min_length { text="Error: Username must be at least 3 characters.", length=3 }] }),
+ wf:wire(submit, email_address, #validate { attach_to=email_address, validators=[#is_required { text="Required." }] }),
+ wf:wire(submit, email_address, #validate { attach_to=email_address, validators=[#is_email { text="Required: Proper email address." }] }),
+ wf:wire(submit, email_address, #validate { attach_to=email_address, validators=[#custom { text="Email address already registered.", function=(fun (X, Y) -> is_email_used (X, Y) end) }] }),
+ wf:wire(submit, pass, #validate { attach_to=pass2, validators=[#confirm_password { text="Error: Passwords do not match", password=pass2 }] }),
+ wf:wire(submit, pass, #validate { attach_to=pass, validators=[#min_length { text="Error: Passwords must be at least 8 characters.", length=8 }] }),
+
+ Header = nitrogen:get_wwwroot()++"/template.html",
+ #template { file=Header }.
+
+title() -> "Chatyeo".
+
+body() ->
+ Cell1 = #tablecell { body = ["Register",
+ #br{}] },
+ Cell2a = #tablecell { body = ["Username: "] },
+ Cell2b = #tablecell { body = [#textbox { id=username }] },
+ Cell3a = #tablecell { body = ["Email Address: "] },
+ Cell3b = #tablecell { body = [#textbox { id=email_address }] },
+
+ Cell4a = #tablecell { body = ["Password: "] },
+ Cell4b = #tablecell { body = [#password { id=pass }] },
+ Cell5a = #tablecell { body = ["Retype Password: "] },
+ Cell5b = #tablecell { body = [#password { id=pass2 }] },
+
+ Row1 = #tablerow {cells = [Cell1] },
+ Row2 = #tablerow {cells = [Cell2a,Cell2b] },
+ Row3 = #tablerow {cells = [Cell3a,Cell3b] },
+ Row4 = #tablerow {cells = [Cell4a,Cell4b] },
+ Row5 = #tablerow {cells = [Cell5a,Cell5b] },
+
+ [#table {rows=[Row1, Row2, Row3, Row4, Row5]},
+ #button { id=submit, text="Register", postback=register },
+ #br{},
+ "Already Registered? ",
+ #link { text="Login Here", url="login" },
+ #br{},
+ #flash { id=flash },
+ #panel { id=test }].
+
+event (register) ->
+ Pass = hd(wf:q(pass)),
+ if
+ Pass == "temp4now" ->
+ wf:flash ("Error: that password is not allowable.");
+ true ->
+ case db_interface:add_user (hd(wf:q(username)), "Mr. Nobody", hd(wf:q(email_address)), hd(wf:q(pass))) of
+ ok ->
+ wf:redirect("login");
+ {aborted, Reason} ->
+ wf:flash (io_lib:format("Error: ~p", [Reason]))
+ end
+ end;
+
+event (_) ->
+ ok.
+
+is_username_used (_, _) ->
+ db_interface:is_username_used (hd(wf:q(username))).
+
+is_email_used (_, _) ->
+ db_interface:is_email_used (hd(wf:q(email_address))).
+
+check_username (_, _) ->
+ case string:chr (hd(wf:q(username)), $ ) of
+ 0 ->
+ true;
+ _ ->
+ false
+ end.
@@ -0,0 +1,9 @@
+#!/bin/sh
+cd `dirname $0`
+
+echo Starting Nitrogen.
+erl \
+ -name nitrogen@localhost \
+ -pa ./ebin -pa ./include \
+ -s make all \
+ -eval "application:start(blog)"
@@ -0,0 +1,5 @@
+.title{font-size:18px;font-family:Arial;}
+.post{font-size:12px;font-family:Arial;}
+
+.textbox_input{float:left;color:#000000;font-size:18px;font-family:Arial;margin-top:10px;margin-left:30px;padding:7px;width:421px;height:20px;overflow:auto;border:1px solid #cfcfcf;}
+.textarea_input{float:left;color:#000000;font-size:18px;font-family:Arial;margin-top:10px;margin-left:30px;padding:7px;width:421px;height:100px;overflow:auto;border:1px solid #cfcfcf;}
Oops, something went wrong.

0 comments on commit ecaed3f

Please sign in to comment.