out(Arg) ->
%% Handles the global login/logout functions
{ok,NewCookie,LoginRsn} =
preprocess_post(Arg,(Arg#arg.req)#http_request.method),
case NewCookie of
%% No Cookies to set
%% Serve the page as normal
false ->
%% System Globals
H = Arg#arg.headers,
C = H#headers.cookie,
R = Arg#arg.req,
%% Global Variables
{_,EncPath} = R#http_request.path,
Path=yaws_api:url_decode(EncPath),
Root = "/",
Docroot = string:concat(Arg#arg.docroot,Root),
TempSectionList = string:tokens(Path, "/"),
Filter = fun([A|_]) -> A /= 63 end,
SectionList = lists:filter(Filter,TempSectionList),
%% Loads the Users Session Data
Cookie = get_cookie(C),
%% Now postprocess the post
%% Most post options can only be done once you are logged in
{ok,Reason} = postprocess_post(Arg,
(Arg#arg.req)#http_request.method,Cookie),
Content = get_content(Docroot,Root,SectionList,Cookie,Arg),
SubContent = get_sub_content(Docroot,Root,SectionList,Cookie,Arg),
%% Add a user naviation bar if the user is logged in
case Cookie of
#user{loggedin=true, name=UserPath} ->
UserNavigation=wutils:read_tpl(Docroot++
"tpl/loggedin_nav.tpl",
[{"root",Root},{"user",Cookie#user.name}]);
_ ->
UserNavigation=wutils:read_tpl(Docroot++
"tpl/notloggedin_nav.tpl",[{"root",Root}])
end,
%% Variables to be replaced in the template
Globals = [
{"root",Root},
{"docroot",Docroot},
{"address",wutils:make_address(Path,SectionList,Root,"")},
{"userinfo",get_user_info(Cookie,Root,Docroot,LoginRsn)},
{"content",Content},
{"subcontent",SubContent},
{"reason",Reason},
{"usernavigation",UserNavigation}
],
%% Read the template and replace markers
%% with variables
Page = wutils:read_tpl(Docroot++"tpl/index.tpl",Globals),
%% Output the page
{html,Page};
%% Ok, I want to set a cookie,and redirect so I can read it immediately
RedirectCookie ->
[{redirect_local,(Arg#arg.req)#http_request.path},RedirectCookie]
end.