1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

- Moved git and email management to their own functions.

- Added deletion of account on email or git account missing.
- Added exception deep message generation extension.
- Added better exception handling to user management.
- Cleaned up user management functions.
This commit is contained in:
Uncled1023 2016-05-16 16:50:02 -07:00
parent 644c7eefd1
commit 89683efcad
6 changed files with 519 additions and 271 deletions

View File

@ -73,7 +73,7 @@ namespace ServerMaint
} }
catch (Exception ex) catch (Exception ex)
{ {
string msg = string.Format("[{0}] Exception: {1}", DateTime.Now, ex.Message); string msg = string.Format("[{0}] Exception: {1}", DateTime.Now, ex.GetFullMessage(true));
File.AppendAllLines(errorFile, new List<string> { msg }); File.AppendAllLines(errorFile, new List<string> { msg });
Output(msg); Output(msg);
} }
@ -166,6 +166,13 @@ namespace ServerMaint
List<User> curUsers = db.Users.ToList(); List<User> curUsers = db.Users.ToList();
foreach (User user in curUsers) foreach (User user in curUsers)
{ {
// If the username isn't valid, don't clean it (Reserved, not formatted correctly, etc)
if (!UserHelper.ValidUsername(db, config, user.Username))
{
continue;
}
#region Inactivity Cleaning
DateTime lastActivity = UserHelper.GetLastActivity(db, config, user); DateTime lastActivity = UserHelper.GetLastActivity(db, config, user);
TimeSpan inactiveTime = DateTime.Now.Subtract(lastActivity); TimeSpan inactiveTime = DateTime.Now.Subtract(lastActivity);
@ -181,7 +188,7 @@ namespace ServerMaint
int daysForEmail = (int)Math.Floor((double)(maxDays / (numEmails + 1))); int daysForEmail = (int)Math.Floor((double)(maxDays / (numEmails + 1)));
for (int i = daysForEmail; i < maxDays; i = i + daysForEmail) for (int i = daysForEmail; i < maxDays; i = i + daysForEmail)
{ {
if (inactiveTime.Days == daysForEmail) if (inactiveTime.Days == i)
{ {
string email = string.Format("{0}@{1}", user.Username, config.EmailConfig.Domain); string email = string.Format("{0}@{1}", user.Username, config.EmailConfig.Domain);
// Let's send them an email // Let's send them an email
@ -211,6 +218,23 @@ Thank you for your use of Teknik and I hope you decide to come back.
break; break;
} }
} }
#endregion
#region Missing Email Accounts
if (!UserHelper.UserEmailExists(config, user.Username))
{
// They are missing an email account. Something bad happened, so let's delete their account so they can start over. :D
UserHelper.DeleteUser(db, config, user);
}
#endregion
#region Missing Git Accounts
if (!UserHelper.UserGitExists(config, user.Username))
{
// They are missing a git account. Something bad happened, so let's delete their account so they can start over. :D
UserHelper.DeleteUser(db, config, user);
}
#endregion
} }
// Add to transparency report if any users were removed // Add to transparency report if any users were removed

View File

@ -39,6 +39,8 @@ namespace Teknik.Areas.Users.Controllers
ViewBag.Title = "User Does Not Exist - " + Config.Title; ViewBag.Title = "User Does Not Exist - " + Config.Title;
ViewBag.Description = "The User does not exist"; ViewBag.Description = "The User does not exist";
try
{
User user = db.Users.Where(u => u.Username == username).FirstOrDefault(); User user = db.Users.Where(u => u.Username == username).FirstOrDefault();
if (user != null) if (user != null)
@ -69,6 +71,12 @@ namespace Teknik.Areas.Users.Controllers
} }
model.Error = true; model.Error = true;
model.ErrorMessage = "The user does not exist"; model.ErrorMessage = "The user does not exist";
}
catch (Exception ex)
{
model.Error = true;
model.ErrorMessage = ex.GetFullMessage(true);
}
return View(model); return View(model);
} }
@ -210,9 +218,9 @@ namespace Teknik.Areas.Users.Controllers
{ {
if (Config.UserConfig.RegistrationEnabled) if (Config.UserConfig.RegistrationEnabled)
{ {
if (UserHelper.UserExists(db, model.Username)) if (UserHelper.UsernameAvailable(db, Config, model.Username))
{ {
return Json(new { error = "That username already exists." }); return Json(new { error = "That username is not available." });
} }
if (model.Password != model.ConfirmPassword) if (model.Password != model.ConfirmPassword)
{ {
@ -224,7 +232,6 @@ namespace Teknik.Areas.Users.Controllers
User newUser = db.Users.Create(); User newUser = db.Users.Create();
newUser.JoinDate = DateTime.Now; newUser.JoinDate = DateTime.Now;
newUser.Username = model.Username; newUser.Username = model.Username;
newUser.HashedPassword = SHA384.Hash(model.Username, model.Password);
newUser.UserSettings = new UserSettings(); newUser.UserSettings = new UserSettings();
newUser.BlogSettings = new BlogSettings(); newUser.BlogSettings = new BlogSettings();
newUser.UploadSettings = new UploadSettings(); newUser.UploadSettings = new UploadSettings();
@ -233,7 +240,7 @@ namespace Teknik.Areas.Users.Controllers
} }
catch (Exception ex) catch (Exception ex)
{ {
return Json(new { error = ex.Message }); return Json(new { error = ex.GetFullMessage(true) });
} }
return Login(new LoginViewModel { Username = model.Username, Password = model.Password, RememberMe = false, ReturnUrl = model.ReturnUrl }); return Login(new LoginViewModel { Username = model.Username, Password = model.Password, RememberMe = false, ReturnUrl = model.ReturnUrl });
} }
@ -246,6 +253,8 @@ namespace Teknik.Areas.Users.Controllers
public ActionResult Edit(string curPass, string newPass, string newPassConfirm, string pgpPublicKey, string website, string quote, string about, string blogTitle, string blogDesc, bool saveKey, bool serverSideEncrypt) public ActionResult Edit(string curPass, string newPass, string newPassConfirm, string pgpPublicKey, string website, string quote, string about, string blogTitle, string blogDesc, bool saveKey, bool serverSideEncrypt)
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
{
try
{ {
User user = UserHelper.GetUser(db, User.Identity.Name); User user = UserHelper.GetUser(db, User.Identity.Name);
if (user != null) if (user != null)
@ -265,7 +274,6 @@ namespace Teknik.Areas.Users.Controllers
{ {
return Json(new { error = "New Password Must Match." }); return Json(new { error = "New Password Must Match." });
} }
user.HashedPassword = SHA384.Hash(User.Identity.Name, newPass);
changePass = true; changePass = true;
} }
@ -285,11 +293,16 @@ namespace Teknik.Areas.Users.Controllers
user.UploadSettings.SaveKey = saveKey; user.UploadSettings.SaveKey = saveKey;
user.UploadSettings.ServerSideEncrypt = serverSideEncrypt; user.UploadSettings.ServerSideEncrypt = serverSideEncrypt;
UserHelper.SaveUser(db, Config, user, changePass, newPass); UserHelper.EditUser(db, Config, user, changePass, newPass);
return Json(new { result = true }); return Json(new { result = true });
} }
return Json(new { error = "User does not exist" }); return Json(new { error = "User does not exist" });
} }
catch (Exception ex)
{
return Json(new { error = ex.GetFullMessage(true) });
}
}
return Json(new { error = "Invalid Parameters" }); return Json(new { error = "Invalid Parameters" });
} }
@ -297,6 +310,8 @@ namespace Teknik.Areas.Users.Controllers
public ActionResult Delete() public ActionResult Delete()
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
{
try
{ {
User user = UserHelper.GetUser(db, User.Identity.Name); User user = UserHelper.GetUser(db, User.Identity.Name);
if (user != null) if (user != null)
@ -314,6 +329,11 @@ namespace Teknik.Areas.Users.Controllers
return Json(new { result = true }); return Json(new { result = true });
} }
} }
catch (Exception ex)
{
return Json(new { error = ex.GetFullMessage(true) });
}
}
return Json(new { error = "Unable to delete user" }); return Json(new { error = "Unable to delete user" });
} }
} }

View File

@ -19,6 +19,7 @@ namespace Teknik.Areas.Users.Utility
{ {
public static class UserHelper public static class UserHelper
{ {
#region User Management
public static User GetUser(TeknikEntities db, string username) public static User GetUser(TeknikEntities db, string username)
{ {
User user = db.Users.Where(b => b.Username == username).FirstOrDefault(); User user = db.Users.Where(b => b.Username == username).FirstOrDefault();
@ -43,53 +44,66 @@ namespace Teknik.Areas.Users.Utility
return false; return false;
} }
public static bool ValidUsername(TeknikEntities db, Config config, string username)
{
bool isValid = true;
if (config.UserConfig.ReservedUsernames.Exists(u => u.ToLower() == username.ToLower()))
isValid = false;
return isValid;
}
public static bool UsernameAvailable(TeknikEntities db, Config config, string username)
{
bool isAvailable = true;
isAvailable &= ValidUsername(db, config, username);
isAvailable &= !UserExists(db, username);
isAvailable &= !UserEmailExists(config, username);
isAvailable &= !UserGitExists(config, username);
return isAvailable;
}
public static DateTime GetLastActivity(TeknikEntities db, Config config, User user)
{
try
{
DateTime lastActive = new DateTime(1900, 1, 1);
string email = string.Format("{0}@{1}", user.Username, config.EmailConfig.Domain);
DateTime emailLastActive = UserEmailLastActive(config, user.Username);
if (lastActive < emailLastActive)
lastActive = emailLastActive;
DateTime gitLastActive = UserGitLastActive(config, user.Username);
if (lastActive < gitLastActive)
lastActive = gitLastActive;
if (lastActive < user.LastSeen)
lastActive = user.LastSeen;
return lastActive;
}
catch (Exception ex)
{
throw new Exception("Unable to determine last activity.", ex);
}
}
public static void AddUser(TeknikEntities db, Config config, User user, string password) public static void AddUser(TeknikEntities db, Config config, User user, string password)
{ {
try try
{ {
string email = string.Format("{0}@{1}", user.Username, config.EmailConfig.Domain); // Create an Email Account
// If Email Server is enabled AddUserEmail(config, user, password);
if (config.EmailConfig.Enabled)
{
// Connect to hmailserver COM
var app = new hMailServer.Application();
app.Connect();
app.Authenticate(config.EmailConfig.Username, config.EmailConfig.Password);
var domain = app.Domains.ItemByName[config.EmailConfig.Domain]; // Create a Git Account
try AddUserGit(config, user, password);
{
var account = domain.Accounts.ItemByAddress[email];
throw new Exception("That email already exists.");
}
catch { }
// If we got an exception, then the email doesnt exist and we continue on!
var newAccount = domain.Accounts.Add();
newAccount.Address = email;
newAccount.Password = password;
newAccount.Active = true;
newAccount.MaxSize = config.EmailConfig.MaxSize;
newAccount.Save();
}
// If Git is enabled
if (config.GitConfig.Enabled)
{
// Add gogs user
using (var client = new WebClient())
{
var obj = new { source_id = config.GitConfig.SourceId, username = user.Username, email = email, login_name = email, password = password };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
client.Headers[HttpRequestHeader.ContentType] = "application/json";
Uri baseUri = new Uri(config.GitConfig.Host);
Uri finalUri = new Uri(baseUri, "api/v1/admin/users?token=" + config.GitConfig.AccessToken);
string result = client.UploadString(finalUri, "POST", json);
}
}
// Add User // Add User
user.HashedPassword = SHA384.Hash(user.Username, password);
db.Users.Add(user); db.Users.Add(user);
db.SaveChanges(); db.SaveChanges();
@ -105,104 +119,41 @@ namespace Teknik.Areas.Users.Utility
} }
} }
public static void SaveUser(TeknikEntities db, Config config, User user, bool changePass, string newPass) public static void EditUser(TeknikEntities db, Config config, User user, bool changePass, string password)
{
try
{ {
string email = string.Format("{0}@{1}", user.Username, config.EmailConfig.Domain); string email = string.Format("{0}@{1}", user.Username, config.EmailConfig.Domain);
// Changing Password? // Changing Password?
if (changePass) if (changePass)
{ {
// Update Email Pass // Change email password
if (config.EmailConfig.Enabled) EditUserEmailPassword(config, user, password);
{
try
{
var app = new hMailServer.Application();
app.Connect();
app.Authenticate(config.EmailConfig.Username, config.EmailConfig.Password);
var domain = app.Domains.ItemByName[config.EmailConfig.Domain];
var account = domain.Accounts.ItemByAddress[email];
account.Password = newPass;
account.Save();
}
catch (COMException)
{ }
}
// Update Git Pass // Update Git password
if (config.GitConfig.Enabled) EditUserGitPassword(config, user, password);
{
using (var client = new WebClient()) // Update User password
{ user.HashedPassword = SHA384.Hash(user.Username, password);
var obj = new { source_id = config.GitConfig.SourceId, email = email, password = newPass };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
client.Headers[HttpRequestHeader.ContentType] = "application/json";
Uri baseUri = new Uri(config.GitConfig.Host);
Uri finalUri = new Uri(baseUri, "api/v1/admin/users/" + user.Username + "?token=" + config.GitConfig.AccessToken);
string result = client.UploadString(finalUri, "PATCH", json);
}
}
} }
db.Entry(user).State = EntityState.Modified; db.Entry(user).State = EntityState.Modified;
db.SaveChanges(); db.SaveChanges();
} }
catch (Exception ex)
{
throw new Exception("Unable to edit user.", ex);
}
}
public static void DeleteUser(TeknikEntities db, Config config, User user) public static void DeleteUser(TeknikEntities db, Config config, User user)
{
// Check to see if we need to delete their email.
if (config.EmailConfig.Enabled)
{ {
try try
{ {
// Delete Email // Delete Email Account
var app = new hMailServer.Application(); DeleteUserEmail(config, user);
app.Connect();
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.Username, config.EmailConfig.Domain)];
if (account != null)
{
account.Delete();
}
}
catch (COMException)
{
}
catch (Exception ex)
{
throw new Exception("Unable to delete email account.", ex);
}
}
// Delete Git // Delete Git Account
if (config.GitConfig.Enabled) DeleteUserGit(config, user);
{
try
{
Uri baseUri = new Uri(config.GitConfig.Host);
Uri finalUri = new Uri(baseUri, "api/v1/admin/users/" + user.Username + "?token=" + config.GitConfig.AccessToken);
WebRequest request = WebRequest.Create(finalUri);
request.Method = "DELETE";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.OK)
{
throw new Exception("Unable to delete git account. Response Code: " + response.StatusCode);
}
}
catch (HttpException htex)
{
if (htex.GetHttpCode() != 404)
throw new Exception("Unable to delete git account. Http Exception: " + htex.Message);
}
catch (Exception ex)
{
// This error signifies the user doesn't exist, so we can continue deleting
if (ex.Message != "The remote server returned an error: (404) Not Found.")
{
throw new Exception("Unable to delete git account. Exception: " + ex.Message);
}
}
}
// Update uploads // Update uploads
List<Upload.Models.Upload> uploads = db.Uploads.Include("User").Where(u => u.User.Username == user.Username).ToList(); List<Upload.Models.Upload> uploads = db.Uploads.Include("User").Where(u => u.User.Username == user.Username).ToList();
@ -254,7 +205,7 @@ namespace Teknik.Areas.Users.Utility
} }
} }
// Delete post comments // Delete podcast comments
List<Podcast.Models.PodcastComment> podComments = db.PodcastComments.Include("User").Where(u => u.User.Username == user.Username).ToList(); List<Podcast.Models.PodcastComment> podComments = db.PodcastComments.Include("User").Where(u => u.User.Username == user.Username).ToList();
if (podComments != null) if (podComments != null)
{ {
@ -268,15 +219,44 @@ namespace Teknik.Areas.Users.Utility
db.Users.Remove(user); db.Users.Remove(user);
db.SaveChanges(); db.SaveChanges();
} }
catch (Exception ex)
{
throw new Exception("Unable to delete user.", ex);
}
}
#endregion
public static DateTime GetLastActivity(TeknikEntities db, Config config, User user) #region Email Management
public static bool UserEmailExists(Config config, string username)
{
// If Email Server is enabled
if (config.EmailConfig.Enabled)
{
string email = string.Format("{0}@{1}", username, config.EmailConfig.Domain);
// Connect to hmailserver COM
var app = new hMailServer.Application();
app.Connect();
app.Authenticate(config.EmailConfig.Username, config.EmailConfig.Password);
try
{
var domain = app.Domains.ItemByName[config.EmailConfig.Domain];
var account = domain.Accounts.ItemByAddress[email];
// We didn't error out, so the email exists
return true;
}
catch { }
}
return false;
}
public static DateTime UserEmailLastActive(Config config, string username)
{ {
DateTime lastActive = new DateTime(1900, 1, 1); DateTime lastActive = new DateTime(1900, 1, 1);
string email = string.Format("{0}@{1}", user.Username, config.EmailConfig.Domain);
if (config.EmailConfig.Enabled) if (config.EmailConfig.Enabled)
{ {
// Connect to hmailserver COM string email = string.Format("{0}@{1}", username, config.EmailConfig.Domain);
var app = new hMailServer.Application(); var app = new hMailServer.Application();
app.Connect(); app.Connect();
app.Authenticate(config.EmailConfig.Username, config.EmailConfig.Password); app.Authenticate(config.EmailConfig.Username, config.EmailConfig.Password);
@ -289,11 +269,119 @@ namespace Teknik.Areas.Users.Utility
if (lastActive < lastEmail) if (lastActive < lastEmail)
lastActive = lastEmail; lastActive = lastEmail;
} }
catch (Exception ex) { } catch { }
} }
return lastActive;
}
public static void AddUserEmail(Config config, User user, string password)
{
try
{
// If Email Server is enabled
if (config.EmailConfig.Enabled)
{
string email = string.Format("{0}@{1}", user.Username, config.EmailConfig.Domain);
// Connect to hmailserver COM
var app = new hMailServer.Application();
app.Connect();
app.Authenticate(config.EmailConfig.Username, config.EmailConfig.Password);
var domain = app.Domains.ItemByName[config.EmailConfig.Domain];
var newAccount = domain.Accounts.Add();
newAccount.Address = email;
newAccount.Password = password;
newAccount.Active = true;
newAccount.MaxSize = config.EmailConfig.MaxSize;
newAccount.Save();
}
}
catch (Exception ex)
{
throw new Exception("Unable to add email.", ex);
}
}
public static void EditUserEmailPassword(Config config, User user, string password)
{
try
{
// If Email Server is enabled
if (config.EmailConfig.Enabled)
{
string email = string.Format("{0}@{1}", user.Username, config.EmailConfig.Domain);
var app = new hMailServer.Application();
app.Connect();
app.Authenticate(config.EmailConfig.Username, config.EmailConfig.Password);
var domain = app.Domains.ItemByName[config.EmailConfig.Domain];
var account = domain.Accounts.ItemByAddress[email];
account.Password = password;
account.Save();
}
}
catch (Exception ex)
{
throw new Exception("Unable to edit email account password.", ex);
}
}
public static void DeleteUserEmail(Config config, User user)
{
try
{
// If Email Server is enabled
if (config.EmailConfig.Enabled)
{
string email = string.Format("{0}@{1}", user.Username, config.EmailConfig.Domain);
var app = new hMailServer.Application();
app.Connect();
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.Username, config.EmailConfig.Domain)];
if (account != null)
{
account.Delete();
}
}
}
catch (Exception ex)
{
throw new Exception("Unable to delete email account.", ex);
}
}
#endregion
#region Git Management
public static bool UserGitExists(Config config, string username)
{
if (config.GitConfig.Enabled)
{
try
{
Uri baseUri = new Uri(config.GitConfig.Host);
Uri finalUri = new Uri(baseUri, "api/v1/users/" + username + "?token=" + config.GitConfig.AccessToken);
WebRequest request = WebRequest.Create(finalUri);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
return true;
}
}
catch { }
}
return false;
}
public static DateTime UserGitLastActive(Config config, string username)
{
DateTime lastActive = new DateTime(1900, 1, 1);
if (config.GitConfig.Enabled) if (config.GitConfig.Enabled)
{ {
string email = string.Format("{0}@{1}", username, config.EmailConfig.Domain);
// We need to check the actual git database // We need to check the actual git database
MysqlDatabase mySQL = new MysqlDatabase(config.GitConfig.Database); MysqlDatabase mySQL = new MysqlDatabase(config.GitConfig.Database);
string sql = @"SELECT MAX(gogs.repository.updated) AS LastUpdate string sql = @"SELECT MAX(gogs.repository.updated) AS LastUpdate
@ -310,13 +398,102 @@ namespace Teknik.Areas.Users.Utility
lastActive = tmpLast; lastActive = tmpLast;
} }
} }
if (lastActive < user.LastSeen)
lastActive = user.LastSeen;
return lastActive; return lastActive;
} }
public static void AddUserGit(Config config, User user, string password)
{
try
{
// If Git is enabled
if (config.GitConfig.Enabled)
{
string email = string.Format("{0}@{1}", user.Username, config.EmailConfig.Domain);
// Add gogs user
using (var client = new WebClient())
{
var obj = new { source_id = config.GitConfig.SourceId, username = user.Username, email = email, login_name = email, password = password };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
client.Headers[HttpRequestHeader.ContentType] = "application/json";
Uri baseUri = new Uri(config.GitConfig.Host);
Uri finalUri = new Uri(baseUri, "api/v1/admin/users?token=" + config.GitConfig.AccessToken);
string result = client.UploadString(finalUri, "POST", json);
}
}
}
catch (Exception ex)
{
throw new Exception("Unable to add git account.", ex);
}
}
public static void EditUserGitPassword(Config config, User user, string password)
{
try
{
// If Git is enabled
if (config.GitConfig.Enabled)
{
string email = string.Format("{0}@{1}", user.Username, config.EmailConfig.Domain);
using (var client = new WebClient())
{
var obj = new { source_id = config.GitConfig.SourceId, email = email, password = password };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
client.Headers[HttpRequestHeader.ContentType] = "application/json";
Uri baseUri = new Uri(config.GitConfig.Host);
Uri finalUri = new Uri(baseUri, "api/v1/admin/users/" + user.Username + "?token=" + config.GitConfig.AccessToken);
string result = client.UploadString(finalUri, "PATCH", json);
}
}
}
catch (Exception ex)
{
throw new Exception("Unable to edit git account password.", ex);
}
}
public static void DeleteUserGit(Config config, User user)
{
try
{
// If Git is enabled
if (config.GitConfig.Enabled)
{
try
{
Uri baseUri = new Uri(config.GitConfig.Host);
Uri finalUri = new Uri(baseUri, "api/v1/admin/users/" + user.Username + "?token=" + config.GitConfig.AccessToken);
WebRequest request = WebRequest.Create(finalUri);
request.Method = "DELETE";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.OK)
{
throw new Exception("Unable to delete git account. Response Code: " + response.StatusCode);
}
}
catch (HttpException htex)
{
if (htex.GetHttpCode() != 404)
throw new Exception("Unable to delete git account. Http Exception: " + htex.Message);
}
catch (Exception ex)
{
// This error signifies the user doesn't exist, so we can continue deleting
if (ex.Message != "The remote server returned an error: (404) Not Found.")
{
throw new Exception("Unable to delete git account. Exception: " + ex.Message);
}
}
}
}
catch (Exception ex)
{
throw new Exception("Unable to delete git account.", ex);
}
}
#endregion
public static HttpCookie CreateAuthCookie(string username, bool remember, string domain, bool local) public static HttpCookie CreateAuthCookie(string username, bool remember, string domain, bool local)
{ {
Config config = Config.Load(); Config config = Config.Load();

View File

@ -10,11 +10,13 @@ namespace Teknik.Configuration
{ {
public bool RegistrationEnabled { get; set; } public bool RegistrationEnabled { get; set; }
public bool LoginEnabled { get; set; } public bool LoginEnabled { get; set; }
public List<string> ReservedUsernames { get; set; }
public UserConfig() public UserConfig()
{ {
RegistrationEnabled = true; RegistrationEnabled = true;
LoginEnabled = true; LoginEnabled = true;
ReservedUsernames = new List<string>();
} }
} }
} }

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Teknik.Helpers
{
public static class ExceptionExtensions
{
public static string GetFullMessage(this Exception ex, bool recursive = false, bool stackTrace = false)
{
string message = ex.Message;
if (recursive && ex.InnerException != null)
{
message += " | Inner Exception: " + ex.InnerException.GetFullMessage(recursive, stackTrace);
}
if (stackTrace && !string.IsNullOrEmpty(ex.StackTrace))
{
message += " | Stack Trace: " + ex.StackTrace;
}
return message;
}
}
}

View File

@ -274,6 +274,7 @@
<Compile Include="Areas\User\Models\PermissionType.cs" /> <Compile Include="Areas\User\Models\PermissionType.cs" />
<Compile Include="Areas\Blog\Models\BlogPost.cs" /> <Compile Include="Areas\Blog\Models\BlogPost.cs" />
<Compile Include="Areas\User\Models\Role.cs" /> <Compile Include="Areas\User\Models\Role.cs" />
<Compile Include="Helpers\ExceptionExtensions.cs" />
<Compile Include="Helpers\HttpRequestExtensions.cs" /> <Compile Include="Helpers\HttpRequestExtensions.cs" />
<Compile Include="Helpers\MysqlDatabase.cs" /> <Compile Include="Helpers\MysqlDatabase.cs" />
<Compile Include="Helpers\MarkdownHelper.cs" /> <Compile Include="Helpers\MarkdownHelper.cs" />