Commits

Anonymous committed 07adffd

Fixed comments handling and openid authentication.

Comments (0)

Files changed (13)

 NPROCREG_EBIN=$NITROGEN_TOP_DIR/apps/nprocreg/ebin
 EOPENID_EBIN=/home/tobbe/git/eopenid/ebin
 REDBUG_EBIN=/home/tobbe/Kreditor/svn/trunk/lib/eper/ebin
+TRANE_EBIN=/home/tobbe/git/trane/ebin
 
 
Add a comment to this file

ebin/redhot2_common.beam

Binary file modified.

src/redhot2_app.erl

 -include_lib("nitrogen/include/wf.hrl").
 
 start(_, _) ->
-    %% Uncomment below iff using eopenid!
-    %%eopenid:start(),
+    eopenid:start(),
     Res = redhot2_sup:start_link(),
     {ok,_Pid} = redhot2_inets:start_link(), % ends up under the inets supervisors
     Res.
 
 stop(_) ->
-    %% Uncomment below iff using eopenid!
-    %%eopenid:stop(),
+    eopenid:stop(),
     ok.
 
 

src/redhot2_common.erl

          , logo_text/0
         ]).
 
+
+-define(INDEX_PAGE, redhot2_web_index).
+
+
 title() ->
     "redhot2".
 
                     ]}.
 
 menu_box() ->
+    P = "p="++wf:url_encode(raw_path()),
     #panel { class=menu, 
-             body=[#link { id=home,    url='/',          text="Home" },
-                   #link { id=twitter, url='/twitter',   text="Twitter" },
-                   #link { id=logout,  url='/logout',    text="Logout" },
-                   #link { id=about,   url='/about',     text="About" }
+             body=[#link { id=home,    url='/',           text="Home" },
+                   #link { id=twitter, url='/twitter',    text="Twitter" },
+                   #link { id=logout,  url="/logout?"++P, text="Logout" },
+                   #link { id=about,   url='/about',      text="About" }
                   ]}.
 
 openid_box() ->
             #panel { class = "openid_box",
                      body = [wf:user()]};
         _ ->
+            Id = claimed_id,
             #panel { class = "openid_box",
-                     body = [#textbox{ class = "openid_login", 
-                                       id    = "claimed_id"}]}
+                     body = [#textbox{ class    = "openid_login", 
+                                       id       = Id,
+                                       postback = {Id,raw_path()},
+                                       delegate = ?INDEX_PAGE}]}
     end.
 
 logo_text() ->

src/redhot2_inets.erl

      , {"/entry",     redhot2_web_entry}
      , {"/about",     redhot2_web_about}
      , {"/twitter",   redhot2_web_twitter}
+     , {"/web",       redhot2_web_bwcompat}
      , {"/login",     redhot2_web_login}
      , {"/logout",    redhot2_web_logout}
      , {"/auth",      redhot2_web_auth}

src/redhot2_web_auth.erl

 main() -> 
     try
         Dict = wf:session(eopenid_dict),
-        RequestBridge = wf_context:request_bridge(),
-        RawPath = RequestBridge:uri(),
+        RawPath = redhot2_common:raw_path(),
         %% assertion
         true = eopenid_v1:verify_signed_keys(RawPath, Dict),
         ClaimedId = eopenid_lib:out("openid.claimed_id", Dict),
         wf:user(ClaimedId),
         wf:session(authenticated, true),
-        wf:redirect("/")
+        wf:redirect(wf:qs("p"))
     catch
 	_:_Err ->
             io:format("~p: Error(~p), ~p~n",[?MODULE,_Err,erlang:get_stacktrace()]),

src/redhot2_web_bwcompat.erl

+%% @author Torbjorn Tornkvist etnt@redhoterlang.com
+%% @copyright 2010, Torbjorn Tornkvist.
+%%
+%% @doc Handling of backward compatibility issues.
+%% @end
+
+-module(redhot2_web_bwcompat).
+
+-include_lib("nitrogen/include/wf.hrl").
+
+-export([main/0
+	]).
+
+
+main() ->
+    case string:tokens(redhot2_common:raw_path(), "/?") of
+        [_,"plink"|_] -> 
+            % v.3 used /web/plink?id=.... for permalinks
+            wf:redirect("/entry/"++wf:qs("id"));
+        _ -> 
+            wf:redirect("/fixme_error_msg_here")
+    end.
+

src/redhot2_web_entry.erl

 %% @author Torbjorn Tornkvist etnt@redhoterlang.com
-%% @copyright YYYY Torbjorn Tornkvist.
+%% @copyright 2010, Torbjorn Tornkvist.
 
 -module(redhot2_web_entry).
 
     A = proplists:get_value("author",L),
     H = proplists:get_value("html",L),
     Comform = "e_comform",
-    #panel{body=[#panel{class="e_author", body=[#panel{body=[gravatar(author2email(A))]},
-						#panel{body=["by: ",#span{class="blue",text=A}]}]},
-                 #span{class="e_date" , text=gtostr(C)},
-                 #span{class="e_title", text=to_latin1(T)},
-                 %#panel{class="e_author", body=["by: ",#span{class="blue",text=A}]},
-                 #panel{class="l_body" , body=to_latin1(H)}
-%                 #panel{class="e_comhdr", body=comhdr(Comform,Id)},
-%                 #panel{class=Comform, body=comform(Comform,Id)},
-%                 #panel{class="l_comments" , 
-%                        body=format_comments(Id)}
+    #panel{body=[#panel{class="e_author", 
+                        body=[#panel{body=[gravatar(author2email(A))]},
+                              #panel{body=["by: ",#span{class="by_who",text=A}]}]},
+                 #span{class="e_date" ,      text=gtostr(C)},
+                 #span{class="e_title",      text=to_latin1(T)},
+                 #panel{class="l_body" ,     body=to_latin1(H)},
+                 #panel{class="e_comhdr",    body=comhdr(Comform,Id)},
+                 #panel{class=Comform,       body=comform(Comform,Id)},
+                 #panel{class="l_comments" , body=format_comments(Id)}
                 ]}.
 
 comhdr(Comform, Id) ->
             wf:wire("com_submit", #event {type=click, postback={comment,Id}, delegate=?MODULE}),
             B;
         _ ->
-            Op = fun() -> nav:mk_article(Id) end,
-% FIXME            push(Op),
-            mk_openid_form(openid_comment_form_text())
+            %mk_openid_form(openid_comment_form_text())
+            openid_comment_form_text()
     end.
 
 
 %%% Format the comments
 %%%
 format_comments(Id) ->
-    F = fun({obj,L}) ->
-                C = proplists:get_value("created", L),
-                T = proplists:get_value("text", L),
-                W = proplists:get_value("who",L),
-                A = proplists:get_value("author",L),
-                {true, {W,C,T,A}}
+    F = fun({obj,L},Acc) ->
+                [C,T,W,A] = 
+                    [proplists:get_value(K,L) 
+                     || K <- ["created","text","who","author"]],
+                [{b2l(W),C,b2l(T),A}|Acc]
         end,
-    Cs = redhot_couchdb:find(F, ["rows","value"], redhot_couchdb:comments(Id)),
+    Cs = lists:foldr(F, [], redhot2_couchdb:comments(Id)),
     G = fun({Who,Created,Text,Author}) ->
                 #panel{class = "c_body",
                        body  = [#panel{class=c_is_author(Author),
     B.
 
 openid_comment_form_text() ->
-    "To avoid spammers you are required to authenticate yourself "
-        "with OpenId. A bit of a hassle perhaps "
-        "but the upside is that you'll be exercising the "
-        "<a href='http://github.com/etnt/eopenid'>eopenid</a> code.".
+    "To avoid spammers you are required to authenticate yourself with OpenId."
+        "<br />A bit of a hassle perhaps but the upside is that you'll be "
+        "exercising the <a href='http://github.com/etnt/eopenid'>eopenid</a> "
+        "code. <br />You'll find the OpenId login entry at the top of the page.".
 
 
 c_is_author(true) -> "c_is_author";
 c_is_author(_)    -> "".
 
-c_txt(true) -> "c_txt c_is_author_txt";
+c_txt(true) -> "c_is_author_txt";
 c_txt(_)    -> "c_txt".

src/redhot2_web_index.erl

         "either in form of tips and tricks from a couple of passionate Erlang "
         "hackers, or in form of some experimental code being run.".
 
+event({claimed_id = Id,RawPath}) ->
+    redhot2_web_login:claimed_id(hd(wf:qs(Id)),RawPath);
 event(Event) ->
     io:format("Event=~p~n",[Event]),
     ok.

src/redhot2_web_login.erl

 
 -include_lib ("nitrogen/include/wf.hrl").
 
--export([main/0,
-         title/0,
-         layout/0,
-	 event/1
+-export([claimed_id/2
 	]).
 
-main() ->
-    #template { file="./templates/grid.html" }.
-
-title() ->
-    redhot2_common:title().
-
-layout() ->
-    #container_12 {
-        body=[
-              #grid_12 { class=header, body=login_header() },
-              #grid_clear {},
-              #grid_4 { body=[] },
-              #grid_4 { body=[login_form()] },
-              #grid_4 { body=[] },
-              #grid_clear {},              
-              #grid_12 { body=redhot2_common:footer() }
-             ]}.
-
-event(claimed_id) ->
+claimed_id(ClaimedId0,ReturnPage) ->
     try
-        [ClaimedId0] = wf:qs(claimed_id),
 	ClaimedId    = eopenid_lib:http_path_norm(ClaimedId0),
         HostName     = redhot2_deps:get_env(hostname, redhot2:hostname()),
         Port         = redhot2_deps:get_env(port, redhot2:default_port()),
         URL          = "http://"++HostName++":"++redhot2:i2l(Port),
         Dict0        = eopenid_lib:foldf(
-                         [eopenid_lib:in("openid.return_to", URL++"/auth"),
+                         [eopenid_lib:in("openid.return_to", 
+                                         URL++"/auth?p="++wf:url_encode(ReturnPage)),
                           eopenid_lib:in("openid.trust_root", URL)
                          ], eopenid_lib:new()),
 
         wf:redirect(Url)
     catch      
         _:Error ->
-            io:format("ERROR=~p~n",[Error]),
-            M = lists:flatten(
-                  io_lib:format("~p:~p", [Error, erlang:get_stacktrace()])),
-            wf:flash("ERROR: "++M)
-    end;
-event(E) ->
-    io:format("E=~p~n",[E]).
-    
+            io:format("ERROR=~p, ~p~n",[Error,erlang:get_stacktrace()]),
+            wf:redirect("/?error")
+    end.
 
-login_header() ->
-    #panel { class = "login_header", body = ["redhot2 logo here..."] }.
-
-
-login_form() ->
-    Text = "Type in your OpenID and press Enter:",
-    B = #panel { class = "openid",
-                 body  = [ #panel { body = [Text]},
-                           #panel { class= "openid_box",
-                                    body = [#panel { body = [ #textbox { class = "openid_login", 
-                                                                         id    = "claimed_id", 
-                                                                         next  = "auth" }]},
-                                            #panel { body = [#button {   id    = "auth", 
-                                                                         text  = "Enter"}]}]}
-                          ]},
-    wf:wire("auth", #event { type     = click, 
-                             postback = claimed_id, 
-                             delegate = ?MODULE}),
-    B.
-
-

src/redhot2_web_logout.erl

 main() -> 
     wf:user(undefined),
     wf:session(authenticated, false),
-    wf:redirect("/").
+    wf:redirect(wf:qs("p")).
 
 
 	
 erl \
     -sname ${NAME} \
     -pa ./ebin ${NITROGEN_EBIN} ${SIMPLE_BRIDGE_EBIN} ${NPROCREG_EBIN} \
-        ${EOPENID_EBIN} ${REDBUG_EBIN} \
+        ${EOPENID_EBIN} ${REDBUG_EBIN}  ${TRANE_EBIN} \
     -pa ./ebin ${NITROGEN_EBIN} ${SIMPLE_BRIDGE_EBIN} ${NPROCREG_EBIN} \
     -eval "application:start(nprocreg)" \
     -eval "application:start(redhot2)"

www/css/digitalchili.css

 	padding:0;
 }
 
-// .header {margin:0 10px 0 -10px;}
-
 .openid_box {margin:25px 0px -25px 0px; padding-left:5px;}
-
 input.openid_login {
    background: url(http://openid.net/login-bg.gif) no-repeat;
    background-color: #fff;
    background-position: 0 50%;
    color: #000;
-   width:95%;
+   width:85%;
+   padding-left: 18px;
 }
 
-
-
 .menu_box {
 	margin:-40px 0 40px 0;
 	padding:0;
 .e_title {font-size:1em; margin-left:2em; font-weight:bold; letter-spacing:1px; color:black;}
 .e_author {float:left; font-size:0.9em; margin:4em 0 -4em -7em; padding-left:0; font-weight:normal;}
 
+/*
+ * Comments
+ */
+.e_comhdr{margin-left:1.5em; margin-bottom:1em;}
+.comhdr{margin-left:0.5em}
+.e_comform{display:none;margin:2em;}
+textarea.comment {height: 100px; width: 450px;}
+.c_date {font-size:0.9em; color:#d13430; font-weight:bold;}
+.c_who {font-size:0.9em; margin-left:2em; font-weight:bold; color:black;}
+.c_txt {
+    font-size:0.9em; 
+    margin-left:1em; 
+    margin:0.2em 0;
+    padding-left:0.6em; 
+    border-left:2px solid #cbd0c2;
+}
+.c_body {margin-left:2em; margin-top:0.6em;}
+.c_is_author {background-color:#e5ff87;}
+.c_is_author_txt {
+    background-color:#f6feda;
+    font-size:0.9em; 
+    margin-left:1em; 
+    margin:0.2em 0;
+    padding-left:0.6em; 
+}
+.c_is_author:after {margin:0 0.5em 0 1em; content:"Author comment"; font-size:0.80em; text-transform:uppercase;}
+
+
 code {font-size: 110%;line-height:90%;}
 
 a.selected {color:black; background-color:#d7d8cf;}
 
+.by_who {color:black;}
 
 .footer {
 	clear:both;
 	border-top:2px solid #cbd0c2;
 	color:#91918d;
 	font-weight:normal;
-	font-size:1.1em;
+	font-size:70%;
 }
 
 .intro {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.