Browse Source

Fixed issue where deletions were failing if email was missing, or git user didnt exist.

Fixed issue where shortened URLs weren't being updated from deleted user.
master
Teknikode 6 years ago
parent
commit
bef2ec6280
  1. 45
      Teknik/Areas/Profile/Controllers/ProfileController.cs
  2. 9
      Teknik/Areas/Profile/Scripts/Profile.js

45
Teknik/Areas/Profile/Controllers/ProfileController.cs

@ -6,6 +6,7 @@ using System.Runtime.InteropServices; @@ -6,6 +6,7 @@ using System.Runtime.InteropServices;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Teknik.Areas.Shortener.Models;
using Teknik.Areas.Blog.Models;
using Teknik.Areas.Error.Controllers;
using Teknik.Areas.Error.ViewModels;
@ -361,21 +362,40 @@ namespace Teknik.Areas.Profile.Controllers @@ -361,21 +362,40 @@ namespace Teknik.Areas.Profile.Controllers
app.Authenticate(Config.EmailConfig.Username, Config.EmailConfig.Password);
var domain = app.Domains.ItemByName[Config.EmailConfig.Domain];
var account = domain.Accounts.ItemByAddress[string.Format("{0}@{1}", User.Identity.Name, Config.EmailConfig.Domain)];
account.Delete();
if (account != null)
{
account.Delete();
}
}
catch (COMException)
{ }
{
}
catch (Exception)
{
return Json(new { error = "Unable to delete email account." });
}
}
// Delete Git
if (Config.GitConfig.Enabled)
{
Uri baseUri = new Uri(Config.GitConfig.Host);
Uri finalUri = new Uri(baseUri, "api/v1/admin/users/" + User.Identity.Name + "?token=" + Config.GitConfig.AccessToken);
WebRequest request = WebRequest.Create(finalUri);
request.Method = "DELETE";
try
{
Uri baseUri = new Uri(Config.GitConfig.Host);
Uri finalUri = new Uri(baseUri, "api/v1/admin/users/" + User.Identity.Name + "?token=" + Config.GitConfig.AccessToken);
WebRequest request = WebRequest.Create(finalUri);
request.Method = "DELETE";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.OK)
{
return Json(new { error = "Unable to delete git account. Response Code: " + response.StatusCode });
}
}
catch (Exception)
{
return Json(new { error = "Unable to delete git account." });
}
}
// Update uploads
@ -400,6 +420,17 @@ namespace Teknik.Areas.Profile.Controllers @@ -400,6 +420,17 @@ namespace Teknik.Areas.Profile.Controllers
}
}
// Update shortened urls
List<ShortenedUrl> shortUrls = db.ShortenedUrls.Include("User").Where(u => u.User.Username == User.Identity.Name).ToList();
if (shortUrls != null)
{
foreach (ShortenedUrl shortUrl in shortUrls)
{
shortUrl.UserId = null;
db.Entry(shortUrl).State = EntityState.Modified;
}
}
// Delete Blogs
Blog.Models.Blog blog = db.Blogs.Include("BlogPosts").Include("BlogPosts.Comments").Include("User").Where(u => u.User.Username == User.Identity.Name).FirstOrDefault();
if (blog != null)

9
Teknik/Areas/Profile/Scripts/Profile.js

@ -14,8 +14,15 @@ @@ -14,8 +14,15 @@
window.location.replace(homeUrl);
}
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>Unable to delete your account. Please contact an Administrator.</div>');
$("#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>');
}
}
});

Loading…
Cancel
Save