Browse Source

Added clearing of trusted devices, and showing of current count of trusted devices.

Added scrollboxes for Uploads/Pastets/Shortened Urls on the Profile.
tags/2.0.3
Teknikode 4 years ago
parent
commit
25b07d0896

+ 36
- 0
Teknik/Areas/User/Controllers/UserController.cs View File

@@ -111,6 +111,7 @@ namespace Teknik.Areas.Users.Controllers

model.UserID = user.UserId;
model.Username = user.Username;
model.TrustedDeviceCount = user.TrustedDevices.Count;

model.UserSettings = user.UserSettings;
model.SecuritySettings = user.SecuritySettings;
@@ -711,5 +712,40 @@ namespace Teknik.Areas.Users.Controllers
Bitmap qrCodeImage = qrCode.GetGraphic(20);
return File(Helpers.Utility.ImageToByte(qrCodeImage), "image/png");
}

[HttpPost]
public ActionResult ClearTrustedDevices()
{
try
{
User user = UserHelper.GetUser(db, User.Identity.Name);
if (user != null)
{
if (user.SecuritySettings.AllowTrustedDevices)
{
// let's clear the trusted devices
user.TrustedDevices.Clear();
List<TrustedDevice> foundDevices = db.TrustedDevices.Where(d => d.UserId == user.UserId).ToList();
if (foundDevices != null)
{
foreach (TrustedDevice device in foundDevices)
{
db.TrustedDevices.Remove(device);
}
}
db.Entry(user).State = EntityState.Modified;
db.SaveChanges();

return Json(new { result = true });
}
return Json(new { error = "User does not allow trusted devices" });
}
return Json(new { error = "User does not exist" });
}
catch (Exception ex)
{
return Json(new { error = ex.GetFullMessage(true) });
}
}
}
}

+ 26
- 0
Teknik/Areas/User/Scripts/User.js View File

@@ -66,6 +66,32 @@
});
});

$('#ClearDevices').click(function () {
$.ajax({
type: "POST",
url: clearTrustedDevicesURL,
data: {},
success: function (html) {
if (html.result) {
$('#ClearDevices').html('Clear Trusted Devices (0)');
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-success alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Successfully Cleared Trusted Devices</div>');
}
else {
errorMsg = html;
if (html.error) {
errorMsg = html.error;
if (html.error.message) {
errorMsg = html.error.message;
}
}
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + errorMsg + '</div>');
}
}
});
});

$('#delete_account').click(function () {
bootbox.confirm("Are you sure you want to delete your account?", function (result) {
if (result) {

+ 2
- 0
Teknik/Areas/User/ViewModels/SettingsViewModel.cs View File

@@ -13,6 +13,8 @@ namespace Teknik.Areas.Users.ViewModels

public string Username { get; set; }

public int TrustedDeviceCount { get; set; }

public UserSettings UserSettings { get; set; }

public SecuritySettings SecuritySettings { get; set; }

+ 3
- 3
Teknik/Areas/User/Views/User/Index.cshtml View File

@@ -117,7 +117,7 @@
</div><!--/tab-pane-->
@if (OwnProfile)
{
<div class="tab-pane" id="uploads">
<div class="tab-pane" id="uploads" style="overflow-y: auto; max-height: 500px;">
@foreach (Teknik.Areas.Upload.Models.Upload upload in Model.Uploads)
{
<div class="panel panel-default">
@@ -149,7 +149,7 @@
</div>
}
</div><!--/tab-pane-->
<div class="tab-pane" id="pastes">
<div class="tab-pane" id="pastes" style="overflow-y: auto; max-height: 500px;">
@foreach (Teknik.Areas.Paste.Models.Paste paste in Model.Pastes)
{
<div class="panel panel-default">
@@ -188,7 +188,7 @@
</div>
}
</div>
<div class="tab-pane" id="shortenedUrls">
<div class="tab-pane" id="shortenedUrls" style="overflow-y: auto; max-height: 500px;">
@foreach (Teknik.Areas.Shortener.Models.ShortenedUrl url in Model.ShortenedUrls)
{
string shortUrl = Url.SubRouteUrl(string.Empty, "Shortener.View", new { url = url.ShortUrl });

+ 4
- 0
Teknik/Areas/User/Views/User/Settings.cshtml View File

@@ -8,6 +8,7 @@
var deleteUserURL = '@Url.SubRouteUrl("user", "User.Action", new { action = "Delete" })';
var resendVerifyURL = '@Url.SubRouteUrl("user", "User.Action", new { action = "ResendVerifyRecoveryEmail"})';
var confirmAuthSetupURL = '@Url.SubRouteUrl("user", "User.Action", new { action = "VerifyAuthenticatorCode" })';
var clearTrustedDevicesURL = '@Url.SubRouteUrl("user", "User.Action", new { action = "ClearTrustedDevices" })';
</script>

@Styles.Render("~/Content/user")
@@ -167,6 +168,9 @@
<input id="update_security_allow_trusted" name="update_security_allow_trusted" title="whether a device could be cached to bypass two factor authentication" type="checkbox" value="true" @(Model.SecuritySettings.AllowTrustedDevices ? "checked" : string.Empty) />
</label>
</div>
<p class="form-control-static @(Model.SecuritySettings.AllowTrustedDevices ? string.Empty : "hide")" id="ClearDevicesLink">
<small><a href="#" class="text-primary" id="ClearDevices">Clear Trusted Devices (@Model.TrustedDeviceCount)</a></small>
</p>
</div>
</div>
</div>

Loading…
Cancel
Save