Skip to content
Browse files

Log the user agent and IP address for each comment

  • Loading branch information...
1 parent 254cc51 commit 9805670e85147f1187067d2b04f21d668005aeb1 Hans-Christian Espérer committed May 3, 2012
Showing with 9 additions and 3 deletions.
  1. +5 −3 modules/mod_comment/models/m_comment.erl
  2. +4 −0 modules/mod_comment/templates/_comments_form.tpl
View
8 modules/mod_comment/models/m_comment.erl
@@ -112,7 +112,9 @@ insert(RscId, Name, Email, Message, Is_visible, Context) ->
Name1 = z_html:escape(z_string:trim(Name)),
Message1 = z_html:escape_link(z_string:trim(Message)),
KeepInformed = z_convert:to_bool(z_context:get_q("keep_informed", Context, false)),
- Props = [
+ UserAgent = z_context:get_q("user_agent", Context, <<"">>),
+ IPAddress = wrq:peer(z_context:get_reqdata(Context)),
+ Props = [
{rsc_id, z_convert:to_integer(RscId)},
{is_visible, Is_visible},
{user_id, z_acl:user(Context)},
@@ -122,8 +124,8 @@ insert(RscId, Name, Email, Message, Is_visible, Context) ->
{email, Email},
{gravatar_code, gravatar_code(Email)},
{keep_informed, KeepInformed},
- {ip_address, ""},
- {user_agent, ""}
+ {ip_address, IPAddress},
+ {user_agent, UserAgent}
],
case z_db:insert(comment, Props, Context) of
{ok, CommentId} = Result ->
View
4 modules/mod_comment/templates/_comments_form.tpl
@@ -50,6 +50,10 @@
<button class="btn btn-primary" type="submit">{_ Send _}</button>
</div>
</div>
+
+ <div>
+ <input type="hidden" name="user_agent" value="{{ m.req.user_agent }}" />
+ </div>
</fieldset>
</form>

0 comments on commit 9805670

Please sign in to comment.
Something went wrong with that request. Please try again.