Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan committed Sep 9, 2009
0 parents commit ecaed3f
Show file tree
Hide file tree
Showing 62 changed files with 2,334 additions and 0 deletions.
14 changes: 14 additions & 0 deletions _build.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
project : {
name : ceug
vsn : "0.1.0.0"
},

build_dir : _build,

ignore_dirs : ["_",
"."],

ignore_apps : [],



25 changes: 25 additions & 0 deletions bin/ceug
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions config/sys.config
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions deploy
Original file line number Diff line number Diff line change
@@ -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

17 changes: 17 additions & 0 deletions lib/blog/Emakefile
Original file line number Diff line number Diff line change
@@ -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
]}.
5 changes: 5 additions & 0 deletions lib/blog/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
compile:
erl -make

clean:
rm -rf ./ebin/*.beam
14 changes: 14 additions & 0 deletions lib/blog/ebin/blog.app
Original file line number Diff line number Diff line change
@@ -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 added lib/blog/ebin/blog_app.beam
Binary file not shown.
Binary file added lib/blog/ebin/web_index.beam
Binary file not shown.
37 changes: 37 additions & 0 deletions lib/blog/src/blog_app.erl
Original file line number Diff line number Diff line change
@@ -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).
21 changes: 21 additions & 0 deletions lib/blog/src/pages/web_index.erl
Original file line number Diff line number Diff line change
@@ -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.
50 changes: 50 additions & 0 deletions lib/blog/src/pages/web_login.erl
Original file line number Diff line number Diff line change
@@ -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.
30 changes: 30 additions & 0 deletions lib/blog/src/pages/web_post.erl
Original file line number Diff line number Diff line change
@@ -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.
93 changes: 93 additions & 0 deletions lib/blog/src/pages/web_register.erl
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions lib/blog/start.sh
Original file line number Diff line number Diff line change
@@ -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)"
5 changes: 5 additions & 0 deletions lib/blog/wwwroot/css/default.css
Original file line number Diff line number Diff line change
@@ -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;}
Loading

0 comments on commit ecaed3f

Please sign in to comment.