mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
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.
This commit is contained in:
parent
be166a55c0
commit
bef2ec6280
@ -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
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
@ -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">×</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">×</button>' + errorMsg + '</div>');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user