ip locator on ipinfo.io basis added to admin

This commit is contained in:
Benjamin Kampmann
2014-06-15 18:14:19 +02:00
parent 806ddb4ccb
commit 2aabf4fdcd
6 changed files with 134 additions and 1 deletions
@@ -0,0 +1,54 @@
{{#if view.ip}}
<button class='btn' {{action lookup target="view"}}>
<span class="fa fa-globe"></span> {{i18n admin.user.ip_lookup}}
</button>
{{/if}}
{{#if view.showBox }}
<div class="location-box">
<h4>{{i18n ip_info.title}}</h4>
<dl>
{{#if view.location}}
{{#if view.location.hostname}}
<dt>{{i18n ip_info.hostname}}</dt>
<dd>{{view.location.hostname}}</dd>
{{/if}}
<dt>{{i18n ip_info.location}}</dt>
<dd>
{{#if view.location.loc}}
<a href="https://maps.google.com/maps?q={{unbound view.location.loc}}" target="_blank">{{view.location.loc}}</a><br>
{{view.location.city}}, {{view.location.region}}, {{view.location.country}}
{{else}}
{{i18n ip_info.location_not_found}}
{{/if}}
</dd>
{{#if view.location.org}}
<dt>{{i18n ip_info.organisation}}</dt>
<dd>{{view.location.org}}</dd>
{{/if}}
{{#if view.location.phone}}
<dt>{{i18n ip_info.phone}}</dt>
<dd>{{view.location.phone}}</dd>
{{/if}}
{{else}}
<div class='spinner'>{{i18n loading}}</div>
{{/if}}
<dt>{{i18n ip_info.other_accounts}}</dt>
<dd>
{{#if view.other_accounts_loading}}
{{i18n loading}}
{{else}}
{{#each view.other_accounts}}
{{#link-to 'adminUser' this}}{{avatar this usernamePath="user.username" imageSize="small"}}{{/link-to}}
{{else}}
{{i18n ip_info.no_other_accounts}}
{{/each}}
{{/if}}
<dd>
</dl>
<button class='btn close' {{action hideBox target="view" }}>{{i18n close}}</button>
</div>
{{/if}}
@@ -79,6 +79,7 @@
<button class='btn' {{action refreshBrowsers target="content"}}>
{{i18n admin.user.refresh_browsers}}
</button>
{{view Discourse.AdminIpLocatorView ipBinding="ip_address"}}
{{/if}}
</div>
</div>
@@ -86,7 +87,11 @@
<div class='display-row'>
<div class='field'>{{i18n user.registration_ip_address.title}}</div>
<div class='value'>{{registration_ip_address}}</div>
<div class='controls'></div>
<div class='controls'>
{{#if currentUser.admin}}
{{view Discourse.AdminIpLocatorView ipBinding="registration_ip_address"}}
{{/if}}
</div>
</div>
{{#if showBadges}}
@@ -0,0 +1,29 @@
Discourse.AdminIpLocatorView = Discourse.View.extend({
templateName: 'admin/templates/ip_locator',
classNames: ["iplocator"],
actions: {
hideBox: function(){
this.set("showBox", false);
},
lookup: function(){
if (!this.get("location")){
$.get("http://ipinfo.io/" + this.get("ip"), function(response) {
this.set("location", response);
}.bind(this), "jsonp");
}
if (!this.get("other_accounts")){
this.set("other_accounts_loading", true);
Discourse.ajax("/admin/users/list/active.json", {
data: {"ip": this.get("ip"),
"exclude": this.get("controller.id")
}
}).then(function (users) {
this.set("other_accounts", users.map(function(u) { return Discourse.AdminUser.create(u);}));
this.set("other_accounts_loading", false);
}.bind(this));
}
this.set("showBox", true);
}
}
});