2018-06-15 23:03:24 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import AdminUser from "admin/models/admin-user";
|
2015-11-21 09:27:06 +08:00
|
|
|
|
2014-07-08 04:18:18 +08:00
|
|
|
export default Ember.Component.extend({
|
|
|
|
classNames: ["ip-lookup"],
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
city: function() {
|
2014-07-08 04:18:18 +08:00
|
|
|
return [
|
|
|
|
this.get("location.city"),
|
|
|
|
this.get("location.region"),
|
|
|
|
this.get("location.country")
|
2018-06-15 23:03:24 +08:00
|
|
|
]
|
|
|
|
.filter(Boolean)
|
|
|
|
.join(", ");
|
2014-08-07 03:22:36 +08:00
|
|
|
}.property("location.{city,region,country}"),
|
2014-07-08 04:18:18 +08:00
|
|
|
|
2014-11-25 02:34:04 +08:00
|
|
|
otherAccountsToDelete: function() {
|
|
|
|
// can only delete up to 50 accounts at a time
|
|
|
|
var total = Math.min(50, this.get("totalOthersWithSameIP") || 0);
|
|
|
|
var visible = Math.min(50, this.get("other_accounts.length") || 0);
|
|
|
|
return Math.max(visible, total);
|
|
|
|
}.property("other_accounts", "totalOthersWithSameIP"),
|
|
|
|
|
2014-07-08 04:18:18 +08:00
|
|
|
actions: {
|
2018-06-15 23:03:24 +08:00
|
|
|
lookup: function() {
|
2014-07-08 04:18:18 +08:00
|
|
|
var self = this;
|
|
|
|
this.set("show", true);
|
|
|
|
|
|
|
|
if (!this.get("location")) {
|
2016-07-01 01:55:44 +08:00
|
|
|
ajax("/admin/users/ip-info", {
|
2014-07-08 04:18:18 +08:00
|
|
|
data: { ip: this.get("ip") }
|
2018-06-15 23:03:24 +08:00
|
|
|
}).then(function(location) {
|
2014-07-08 04:18:18 +08:00
|
|
|
self.set("location", Em.Object.create(location));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.get("other_accounts")) {
|
2014-11-18 01:17:24 +08:00
|
|
|
this.set("otherAccountsLoading", true);
|
2014-11-25 02:34:04 +08:00
|
|
|
|
|
|
|
var data = {
|
2018-06-15 23:03:24 +08:00
|
|
|
ip: this.get("ip"),
|
|
|
|
exclude: this.get("userId"),
|
|
|
|
order: "trust_level DESC"
|
2014-11-25 02:34:04 +08:00
|
|
|
};
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
ajax("/admin/users/total-others-with-same-ip", { data }).then(function(
|
|
|
|
result
|
|
|
|
) {
|
2014-11-25 02:34:04 +08:00
|
|
|
self.set("totalOthersWithSameIP", result.total);
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
AdminUser.findAll("active", data).then(function(users) {
|
2014-07-08 04:18:18 +08:00
|
|
|
self.setProperties({
|
|
|
|
other_accounts: users,
|
2018-06-15 23:03:24 +08:00
|
|
|
otherAccountsLoading: false
|
2014-07-08 04:18:18 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
hide: function() {
|
2014-07-08 04:18:18 +08:00
|
|
|
this.set("show", false);
|
2014-11-21 02:59:20 +08:00
|
|
|
},
|
|
|
|
|
2014-11-25 01:04:34 +08:00
|
|
|
deleteOtherAccounts: function() {
|
2014-11-21 02:59:20 +08:00
|
|
|
var self = this;
|
2018-06-15 23:03:24 +08:00
|
|
|
bootbox.confirm(
|
|
|
|
I18n.t("ip_lookup.confirm_delete_other_accounts"),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
|
|
|
function(confirmed) {
|
|
|
|
if (confirmed) {
|
|
|
|
self.setProperties({
|
|
|
|
other_accounts: null,
|
|
|
|
otherAccountsLoading: true,
|
|
|
|
totalOthersWithSameIP: null
|
|
|
|
});
|
2014-11-25 02:34:04 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
ajax("/admin/users/delete-others-with-same-ip.json", {
|
|
|
|
type: "DELETE",
|
|
|
|
data: {
|
|
|
|
ip: self.get("ip"),
|
|
|
|
exclude: self.get("userId"),
|
|
|
|
order: "trust_level DESC"
|
|
|
|
}
|
|
|
|
}).then(function() {
|
|
|
|
self.send("lookup");
|
|
|
|
});
|
|
|
|
}
|
2014-11-21 02:59:20 +08:00
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
);
|
2014-07-08 04:18:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|