diff options
author | Paul Joseph Davis <davisp@apache.org> | 2010-02-23 18:48:33 +0000 |
---|---|---|
committer | Paul Joseph Davis <davisp@apache.org> | 2010-02-23 18:48:33 +0000 |
commit | c18afdf0d7e33455f3509d3a2165baaffd2d9186 (patch) | |
tree | 01397e5db93f3fa467790b1b92980b6ad6c9050a /src | |
parent | 209ad1637907df094ccadcaad6af18ea9dd96e76 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/couchdb/couch_httpd_auth.erl | 13 |
1 files changed, 7 insertions, 6 deletions
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), <<Secret/binary, UserSalt/binary>>, 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. |