From c18afdf0d7e33455f3509d3a2165baaffd2d9186 Mon Sep 17 00:00:00 2001 From: Paul Joseph Davis Date: Tue, 23 Feb 2010 18:48:33 +0000 Subject: Minor cleanup thanks to Joel Clark. Closes COUCHDB-669 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@915476 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_httpd_auth.erl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/couchdb') diff --git a/src/couchdb/couch_httpd_auth.erl b/src/couchdb/couch_httpd_auth.erl index 3e2981ac..a1e8f11e 100644 --- a/src/couchdb/couch_httpd_auth.erl +++ b/src/couchdb/couch_httpd_auth.erl @@ -312,8 +312,7 @@ cookie_authentication_handler(#httpd{mochi_req=MochiReq}=Req) -> throw({bad_request, Reason}) end, % Verify expiry and hash - {NowMS, NowS, _} = erlang:now(), - CurrentTime = NowMS * 1000000 + NowS, + CurrentTime = make_cookie_time(), case couch_config:get("couch_httpd_auth", "secret", nil) of nil -> ?LOG_ERROR("cookie auth secret is not set",[]), @@ -362,8 +361,7 @@ cookie_auth_header(#httpd{user_ctx=#user_ctx{name=User}, auth={Secret, true}}, H Cookies = mochiweb_cookies:parse_cookie(CookieHeader), AuthSession = proplists:get_value("AuthSession", Cookies), if AuthSession == undefined -> - {NowMS, NowS, _} = erlang:now(), - TimeStamp = NowMS * 1000000 + NowS, + TimeStamp = make_cookie_time(), [cookie_auth_cookie(?b2l(User), Secret, TimeStamp)]; true -> [] @@ -414,8 +412,7 @@ handle_session_req(#httpd{method='POST', mochi_req=MochiReq}=Req) -> true -> % setup the session cookie Secret = ?l2b(ensure_cookie_auth_secret()), - {NowMS, NowS, _} = erlang:now(), - CurrentTime = NowMS * 1000000 + NowS, + CurrentTime = make_cookie_time(), Cookie = cookie_auth_cookie(?b2l(UserName), <>, CurrentTime), % TODO document the "next" feature in Futon {Code, Headers} = case couch_httpd:qs_value(Req, "next", nil) of @@ -487,3 +484,7 @@ to_int(Value) when is_list(Value) -> list_to_integer(Value); to_int(Value) when is_integer(Value) -> Value. + +make_cookie_time() -> + {NowMS, NowS, _} = erlang:now(), + NowMS * 1000000 + NowS. -- cgit v1.2.3