Browse Source

- Added Git Service.

- Made Modify Vault use markdown preview
core
Teknikode 4 years ago
parent
commit
f5d1f94eef
  1. 14
      GitService/GitService.csproj
  2. 148
      GitService/GiteaService.cs
  3. 23
      GitService/IGitService.cs
  4. 173
      GitService/MysqlDatabase.cs
  5. 32
      MailService/HMailService.cs
  6. 8
      MailService/IMailService.cs
  7. 29
      MailService/MailService.cs
  8. 6
      Teknik.sln
  9. 245
      Teknik/Areas/User/Utility/UserHelper.cs
  10. 18
      Teknik/Areas/Vault/Views/Vault/ModifyVault.cshtml
  11. 22
      Teknik/Scripts/Vault/Vault.js
  12. 1
      Teknik/Teknik.csproj
  13. 2
      Teknik/bundleconfig.json

14
GitService/GitService.csproj

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Teknik.GitService</AssemblyName>
<RootNamespace>Teknik.GitService</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MySql.Data" Version="8.0.11" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>
</Project>

148
GitService/GiteaService.cs

@ -0,0 +1,148 @@ @@ -0,0 +1,148 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
namespace Teknik.GitService
{
public class GiteaService : IGitService
{
private readonly int _sourceId;
private readonly string _host;
private readonly string _accessToken;
private readonly string _server;
private readonly string _database;
private readonly string _username;
private readonly string _password;
private readonly int _port;
public GiteaService(int sourceId, string host, string accessToken, string server, string database, string username, string password, int port)
{
_sourceId = sourceId;
_host = host;
_accessToken = accessToken;
_server = server;
_database = database;
_username = username;
_password = password;
_port = port;
}
public bool AccountExists(string username)
{
Uri baseUri = new Uri(_host);
Uri finalUri = new Uri(baseUri, "api/v1/users/" + username + "?token=" + _accessToken);
WebRequest request = WebRequest.Create(finalUri);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
return true;
}
return false;
}
public void CreateAccount(string username, string email, string password)
{
// Add gogs user
using (var client = new WebClient())
{
var obj = new { source_id = _sourceId, username = 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(_host);
Uri finalUri = new Uri(baseUri, "api/v1/admin/users?token=" + _accessToken);
string result = client.UploadString(finalUri, "POST", json);
}
}
public void DeleteAccount(string username)
{
try
{
Uri baseUri = new Uri(_host);
Uri finalUri = new Uri(baseUri, "api/v1/admin/users/" + username + "?token=" + _accessToken);
WebRequest request = WebRequest.Create(finalUri);
request.Method = "DELETE";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.NoContent)
{
throw new Exception("Response Code: " + response.StatusCode);
}
}
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);
}
}
}
public void EditPassword(string username, string email, string password)
{
using (var client = new WebClient())
{
var obj = new { source_id = _sourceId, email = email, login_name = email, password = password };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
client.Headers[HttpRequestHeader.ContentType] = "application/json";
Uri baseUri = new Uri(_host);
Uri finalUri = new Uri(baseUri, "api/v1/admin/users/" + username + "?token=" + _accessToken);
string result = client.UploadString(finalUri, "PATCH", json);
}
}
public void EnableAccount(string username, string email)
{
ChangeAccountStatus(username, email, true);
}
public void DisableAccount(string username, string email)
{
ChangeAccountStatus(username, email, false);
}
public void ChangeAccountStatus(string username, string email, bool active)
{
using (var client = new WebClient())
{
var obj = new { active = active, email = email };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
client.Headers[HttpRequestHeader.ContentType] = "application/json";
Uri baseUri = new Uri(_host);
Uri finalUri = new Uri(baseUri, "api/v1/admin/users/" + username + "?token=" + _accessToken);
string result = client.UploadString(finalUri, "PATCH", json);
}
}
public DateTime LastActive(string email)
{
// We need to check the actual git database
MysqlDatabase mySQL = new MysqlDatabase(_server, _database, _username, _password, _port);
string sql = @"SELECT
CASE
WHEN MAX(gogs.action.created) >= MAX(gogs.user.updated) THEN MAX(gogs.action.created)
WHEN MAX(gogs.user.updated) >= MAX(gogs.action.created) THEN MAX(gogs.user.updated)
ELSE MAX(gogs.user.updated)
END AS LastUpdate
FROM gogs.user
LEFT JOIN gogs.action ON gogs.user.id = gogs.action.act_user_id
WHERE gogs.user.login_name = {0}";
var results = mySQL.Query(sql, new object[] { email });
DateTime lastActive = new DateTime(1, 0, 0);
if (results != null && results.Any())
{
var result = results.First();
DateTime.TryParse(result["LastUpdate"].ToString(), out lastActive);
}
return lastActive;
}
}
}

23
GitService/IGitService.cs

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Teknik.GitService
{
public interface IGitService
{
bool AccountExists(string username);
DateTime LastActive(string username);
void CreateAccount(string username, string email, string password);
void EditPassword(string username, string email, string password);
void EnableAccount(string username, string email);
void DisableAccount(string username, string email);
void DeleteAccount(string username);
}
}

173
GitService/MysqlDatabase.cs

@ -0,0 +1,173 @@ @@ -0,0 +1,173 @@
using System;
using System.Collections.Generic;
using System.Threading;
using MySql.Data.MySqlClient;
namespace Teknik.GitService
{
public class MysqlDatabase
{
public event EventHandler<string> MysqlErrorEvent;
private bool Connected { get; set; }
private MySqlConnection Connection { get; set; }
private ReaderWriterLockSlim DatabaseLock { get; set; }
public MysqlDatabase(string server, string database, string username, string password, int port)
{
Connected = false;
Connection = null;
DatabaseLock = new ReaderWriterLockSlim();
Connect(server, database, username, password, port);
}
public List<Dictionary<string, object>> Query(string query, params object[] args)
{
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
if (Connected)
{
DatabaseLock.EnterWriteLock();
MySqlCommand cmd = PrepareQuery(query, args);
try
{
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Dictionary<string, object> row = new Dictionary<string, object>();
for (int i = 0; i < reader.FieldCount; i++)
{
row.Add(reader.GetName(i), reader.GetValue(i));
}
rows.Add(row);
}
reader.Close();
}
catch (MySqlException exception)
{
if (MysqlErrorEvent != null)
{
MysqlErrorEvent(this, exception.Message);
}
}
catch (Exception exception)
{
if (MysqlErrorEvent != null)
{
MysqlErrorEvent(this, exception.Message);
}
}
DatabaseLock.ExitWriteLock();
}
return rows;
}
public object ScalarQuery(string query, params object[] args)
{
if (Connected)
{
DatabaseLock.EnterWriteLock();
MySqlCommand cmd = PrepareQuery(query, args);
object result = null;
try
{
result = cmd.ExecuteScalar();
}
catch (MySqlException exception)
{
if (MysqlErrorEvent != null)
{
MysqlErrorEvent(this, exception.Message);
}
}
catch (Exception exception)
{
if (MysqlErrorEvent != null)
{
MysqlErrorEvent(this, exception.Message);
}
}
DatabaseLock.ExitWriteLock();
return result;
}
return null;
}
public void Execute(string query, params object[] args)
{
if (Connected)
{
DatabaseLock.EnterWriteLock();
MySqlCommand cmd = PrepareQuery(query, args);
try
{
int result = cmd.ExecuteNonQuery();
}
catch (MySqlException exception)
{
if (MysqlErrorEvent != null)
{
MysqlErrorEvent(this, exception.Message);
}
}
catch (Exception exception)
{
if (MysqlErrorEvent != null)
{
MysqlErrorEvent(this, exception.Message);
}
}
DatabaseLock.ExitWriteLock();
}
}
private void Connect(string server, string database, string username, string password, int port)
{
if (Connection == null)
{
if (!string.IsNullOrEmpty(server) && !string.IsNullOrEmpty(database) && !string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
{
string strCon = string.Format("Server={0}; database={1}; user={2}; password={3}; port={4}; charset=utf8; Allow Zero Datetime=true;", server, database, username, password, port);
Connection = new MySqlConnection(strCon);
try
{
Connection.Open();
Connected = true;
}
catch (MySqlException ex)
{
Connected = false;
}
}
}
}
private void Disconnect()
{
if (Connection != null && Connected)
{
Connected = false;
Connection.Close();
}
}
private MySqlCommand PrepareQuery(string query, object[] args)
{
if (Connected)
{
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = Connection;
for (int i = 0; i < args.Length; i++)
{
string param = "{" + i + "}";
string paramName = "@DBVar_" + i;
query = query.Replace(param, paramName);
cmd.Parameters.AddWithValue(paramName, args[i]);
}
cmd.CommandText = query;
return cmd;
}
return null;
}
}
}

32
MailService/HMailService.cs

@ -4,7 +4,7 @@ using System.Text; @@ -4,7 +4,7 @@ using System.Text;
namespace Teknik.MailService
{
public class HMailService : MailService
public class HMailService : IMailService
{
private readonly hMailServer.Application _App;
@ -33,7 +33,7 @@ namespace Teknik.MailService @@ -33,7 +33,7 @@ namespace Teknik.MailService
_App = InitApp();
}
public override void CreateAccount(string username, string password, int size)
public void CreateAccount(string username, string password, int size)
{
var domain = _App.Domains.ItemByName[_Domain];
var newAccount = domain.Accounts.Add();
@ -45,7 +45,7 @@ namespace Teknik.MailService @@ -45,7 +45,7 @@ namespace Teknik.MailService
newAccount.Save();
}
public override bool AccountExists(string username)
public bool AccountExists(string username)
{
try
{
@ -57,29 +57,37 @@ namespace Teknik.MailService @@ -57,29 +57,37 @@ namespace Teknik.MailService
return false;
}
public override void Delete(string username)
public void DeleteAccount(string username)
{
throw new NotImplementedException();
var app = new hMailServer.Application();
app.Connect();
app.Authenticate(_Username, _Password);
var domain = app.Domains.ItemByName[_Domain];
var account = domain.Accounts.ItemByAddress[username];
if (account != null)
{
account.Delete();
}
}
public override void Enable(string username)
public void EnableAccount(string username)
{
EditActivity(username, true);
}
public override void Disable(string username)
public void DisableAccount(string username)
{
EditActivity(username, false);
}
public override void EditActivity(string username, bool active)
public void EditActivity(string username, bool active)
{
var account = GetAccount(username);
account.Active = active;
account.Save();
}
public override void EditMaxEmailsPerDay(string username, int maxPerDay)
public void EditMaxEmailsPerDay(string username, int maxPerDay)
{
//We need to check the actual git database
MysqlDatabase mySQL = new MysqlDatabase(_CounterServer, _CounterDatabase, _CounterUsername, _CounterPassword, _CounterPort);
@ -88,21 +96,21 @@ namespace Teknik.MailService @@ -88,21 +96,21 @@ namespace Teknik.MailService
mySQL.Execute(sql, new object[] { maxPerDay, username });
}
public override void EditMaxSize(string username, int size)
public void EditMaxSize(string username, int size)
{
var account = GetAccount(username);
account.MaxSize = size;
account.Save();
}
public override void EditPassword(string username, string password)
public void EditPassword(string username, string password)
{
var account = GetAccount(username);
account.Password = password;
account.Save();
}
public override DateTime LastActive(string username)
public DateTime LastActive(string username)
{
var account = GetAccount(username);
return (DateTime)account.LastLogonTime;

8
MailService/IMailService.cs

@ -10,18 +10,16 @@ namespace Teknik.MailService @@ -10,18 +10,16 @@ namespace Teknik.MailService
void CreateAccount(string username, string password, int size);
void EditActivity(string username, bool active);
void EditPassword(string username, string password);
void EditMaxSize(string username, int size);
void EditMaxEmailsPerDay(string username, int maxPerDay);
void Enable(string username);
void EnableAccount(string username);
void Disable(string username);
void DisableAccount(string username);
void Delete(string username);
void DeleteAccount(string username);
}
}

29
MailService/MailService.cs

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Teknik.MailService
{
public abstract class MailService : IMailService
{
public abstract void CreateAccount(string username, string password, int size);
public abstract bool AccountExists(string username);
public abstract void Delete(string username);
public abstract void Disable(string username);
public abstract void EditActivity(string username, bool active);
public abstract void EditMaxEmailsPerDay(string username, int maxPerDay);
public abstract void EditMaxSize(string username, int size);
public abstract void EditPassword(string username, string password);
public abstract void Enable(string username);
public abstract DateTime LastActive(string username);
}
}

6
Teknik.sln

@ -22,6 +22,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Piwik", "Piwik\Piwik.csproj @@ -22,6 +22,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Piwik", "Piwik\Piwik.csproj
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MailService", "MailService\MailService.csproj", "{03636C30-DA61-4307-8934-2FCC3BAC3255}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitService", "GitService\GitService.csproj", "{014879B1-DDD5-4F8C-9597-6D7960912CF0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -52,6 +54,10 @@ Global @@ -52,6 +54,10 @@ Global
{03636C30-DA61-4307-8934-2FCC3BAC3255}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03636C30-DA61-4307-8934-2FCC3BAC3255}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03636C30-DA61-4307-8934-2FCC3BAC3255}.Release|Any CPU.Build.0 = Release|Any CPU
{014879B1-DDD5-4F8C-9597-6D7960912CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{014879B1-DDD5-4F8C-9597-6D7960912CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{014879B1-DDD5-4F8C-9597-6D7960912CF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{014879B1-DDD5-4F8C-9597-6D7960912CF0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

245
Teknik/Areas/User/Utility/UserHelper.cs

@ -26,6 +26,7 @@ using Microsoft.AspNetCore.Http; @@ -26,6 +26,7 @@ using Microsoft.AspNetCore.Http;
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication.Cookies;
using Teknik.MailService;
using Teknik.GitService;
namespace Teknik.Areas.Users.Utility
{
@ -931,15 +932,22 @@ If you recieved this email and you did not reset your password, you can ignore t @@ -931,15 +932,22 @@ If you recieved this email and you did not reset your password, you can ignore t
public static void EnableUserEmail(Config config, string email)
{
EditUserEmailActivity(config, email, true);
try
{
// If Email Server is enabled
if (config.EmailConfig.Enabled)
{
var svc = CreateMailService(config);
svc.EnableAccount(email);
}
}
catch (Exception ex)
{
throw new Exception("Unable to enable email account.", ex);
}
}
public static void DisableUserEmail(Config config, string email)
{
EditUserEmailActivity(config, email, false);
}
public static void EditUserEmailActivity(Config config, string email, bool active)
{
try
{
@ -947,12 +955,12 @@ If you recieved this email and you did not reset your password, you can ignore t @@ -947,12 +955,12 @@ If you recieved this email and you did not reset your password, you can ignore t
if (config.EmailConfig.Enabled)
{
var svc = CreateMailService(config);
svc.EditActivity(email, active);
svc.DisableAccount(email);
}
}
catch (Exception ex)
{
throw new Exception("Unable to edit email account status.", ex);
throw new Exception("Unable to disable email account.", ex);
}
}
@ -1015,7 +1023,7 @@ If you recieved this email and you did not reset your password, you can ignore t @@ -1015,7 +1023,7 @@ If you recieved this email and you did not reset your password, you can ignore t
if (config.EmailConfig.Enabled)
{
var svc = CreateMailService(config);
svc.Delete(email);
svc.DeleteAccount(email);
}
}
catch (Exception ex)
@ -1026,22 +1034,28 @@ If you recieved this email and you did not reset your password, you can ignore t @@ -1026,22 +1034,28 @@ If you recieved this email and you did not reset your password, you can ignore t
#endregion
#region Git Management
public static IGitService CreateGitService(Config config)
{
return new GiteaService(
config.GitConfig.SourceId,
config.GitConfig.Host,
config.GitConfig.AccessToken,
config.GitConfig.Database.Server,
config.GitConfig.Database.Database,
config.GitConfig.Database.Username,
config.GitConfig.Database.Password,
config.GitConfig.Database.Port
);
}
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;
}
var svc = CreateGitService(config);
return svc.AccountExists(username);
}
catch { }
}
@ -1061,27 +1075,11 @@ If you recieved this email and you did not reset your password, you can ignore t @@ -1061,27 +1075,11 @@ If you recieved this email and you did not reset your password, you can ignore t
}
string email = GetUserEmailAddress(config, username);
// We need to check the actual git database
Utilities.MysqlDatabase mySQL = new Utilities.MysqlDatabase(config.GitConfig.Database.Server, config.GitConfig.Database.Database, config.GitConfig.Database.Username, config.GitConfig.Database.Password, config.GitConfig.Database.Port);
string sql = @"SELECT
CASE
WHEN MAX(gogs.action.created) >= MAX(gogs.user.updated) THEN MAX(gogs.action.created)
WHEN MAX(gogs.user.updated) >= MAX(gogs.action.created) THEN MAX(gogs.user.updated)
ELSE MAX(gogs.user.updated)
END AS LastUpdate
FROM gogs.user
LEFT JOIN gogs.action ON gogs.user.id = gogs.action.act_user_id
WHERE gogs.user.login_name = {0}";
var results = mySQL.Query(sql, new object[] { email });
if (results != null && results.Any())
{
var result = results.First();
DateTime tmpLast = lastActive;
DateTime.TryParse(result["LastUpdate"].ToString(), out tmpLast);
if (lastActive < tmpLast)
lastActive = tmpLast;
}
var svc = CreateGitService(config);
DateTime tmpLast = svc.LastActive(email);
if (lastActive < tmpLast)
lastActive = tmpLast;
}
return lastActive;
}
@ -1094,16 +1092,9 @@ If you recieved this email and you did not reset your password, you can ignore t @@ -1094,16 +1092,9 @@ If you recieved this email and you did not reset your password, you can ignore t
if (config.GitConfig.Enabled)
{
string email = GetUserEmailAddress(config, username);
// Add gogs user
using (var client = new WebClient())
{
var obj = new { source_id = config.GitConfig.SourceId, username = 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);
}
var svc = CreateGitService(config);
svc.CreateAccount(username, email, password);
}
}
catch (Exception ex)
@ -1126,15 +1117,9 @@ If you recieved this email and you did not reset your password, you can ignore t @@ -1126,15 +1117,9 @@ If you recieved this email and you did not reset your password, you can ignore t
}
string email = GetUserEmailAddress(config, username);
using (var client = new WebClient())
{
var obj = new {source_id = config.GitConfig.SourceId, 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/" + username + "?token=" + config.GitConfig.AccessToken);
string result = client.UploadString(finalUri, "PATCH", json);
}
var svc = CreateGitService(config);
svc.EditPassword(username, email, password);
}
}
catch (Exception ex)
@ -1145,15 +1130,30 @@ If you recieved this email and you did not reset your password, you can ignore t @@ -1145,15 +1130,30 @@ If you recieved this email and you did not reset your password, you can ignore t
public static void EnableUserGit(Config config, string username)
{
EditUserGitActivity(config, username, true);
}
try
{
// If Git is enabled
if (config.GitConfig.Enabled)
{
// Git user exists?
if (!UserGitExists(config, username))
{
throw new Exception($"Git User '{username}' does not exist.");
}
public static void DisableUserGit(Config config, string username)
{
EditUserGitActivity(config, username, false);
string email = GetUserEmailAddress(config, username);
var svc = CreateGitService(config);
svc.EnableAccount(username, email);
}
}
catch (Exception ex)
{
throw new Exception("Unable to enable git account.", ex);
}
}
public static void EditUserGitActivity(Config config, string username, bool active)
public static void DisableUserGit(Config config, string username)
{
try
{
@ -1167,20 +1167,37 @@ If you recieved this email and you did not reset your password, you can ignore t @@ -1167,20 +1167,37 @@ If you recieved this email and you did not reset your password, you can ignore t
}
string email = GetUserEmailAddress(config, username);
using (var client = new WebClient())
var svc = CreateGitService(config);
svc.EnableAccount(username, email);
}
}
catch (Exception ex)
{
throw new Exception("Unable to disable git account.", ex);
}
}
public static void DeleteUserGit(Config config, string username)
{
try
{
// If Git is enabled
if (config.GitConfig.Enabled)
{
// Git user exists?
if (!UserGitExists(config, username))
{
var obj = new { active = active, email = email };
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/" + username + "?token=" + config.GitConfig.AccessToken);
string result = client.UploadString(finalUri, "PATCH", json);
throw new Exception($"Git User '{username}' does not exist.");
}
var svc = CreateGitService(config);
svc.DeleteAccount(username);
}
}
catch (Exception ex)
{
throw new Exception("Unable to edit git account password.", ex);
throw new Exception("Unable to delete git account.", ex);
}
}
@ -1283,48 +1300,6 @@ If you recieved this email and you did not reset your password, you can ignore t @@ -1283,48 +1300,6 @@ If you recieved this email and you did not reset your password, you can ignore t
throw new Exception("Unable to delete git account two factor.", ex);
}
}
public static void DeleteUserGit(Config config, string username)
{
try
{
// If Git is enabled
if (config.GitConfig.Enabled)
{
// Git user exists?
if (!UserGitExists(config, username))
{
throw new Exception($"Git User '{username}' does not exist.");
}
try
{
Uri baseUri = new Uri(config.GitConfig.Host);
Uri finalUri = new Uri(baseUri, "api/v1/admin/users/" + 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 && response.StatusCode != HttpStatusCode.NoContent)
{
throw new Exception("Unable to delete git account. Response Code: " + response.StatusCode);
}
}
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 ClaimsIdentity CreateClaimsIdentity(TeknikEntities db, string username)
@ -1349,46 +1324,6 @@ If you recieved this email and you did not reset your password, you can ignore t @@ -1349,46 +1324,6 @@ If you recieved this email and you did not reset your password, you can ignore t
return null;
}
//public static HttpCookie CreateAuthCookie(Config config, string username, bool remember, string domain, bool local)
//{
// DateTime curTime = DateTime.Now;
// DateTime expireTime = curTime.AddMonths(1);
// FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
// 1,
// username,
// curTime,
// expireTime,
// remember,
// username
// );
// string encTicket = FormsAuthentication.Encrypt(ticket);
// HttpCookie authcookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
// authcookie.HttpOnly = true;
// authcookie.Secure = true;
// if (remember)
// {
// authcookie.Expires = expireTime;
// }
// // Set domain dependent on where it's being ran from
// if (local) // localhost
// {
// authcookie.Domain = null;
// }
// else if (config.DevEnvironment) // dev.example.com
// {
// authcookie.Domain = string.Format("dev.{0}", domain);
// }
// else // A production instance
// {
// authcookie.Domain = string.Format(".{0}", domain);
// }
// return authcookie;
//}
public static Tuple<CookieOptions, string> CreateTrustedDeviceCookie(Config config, string username, string domain, bool local)
{
byte[] time = BitConverter.GetBytes(DateTime.UtcNow.ToBinary());

18
Teknik/Areas/Vault/Views/Vault/ModifyVault.cshtml

@ -127,20 +127,22 @@ @@ -127,20 +127,22 @@
<div class="row">
<div class="col-sm-10">
<div class="row">
<div class="form-group col-sm-10 col-sm-offset-1">
<div class="form-group col-sm-12">
<label for="title"><h4>Title</h4></label>
<input class="form-control" name="title" id="title" placeholder="Collection of items" title="enter a title for your vault." type="text" value="@Model.title" />
</div>
</div>
<div class="row">
<div class="form-group col-sm-10 col-sm-offset-1">
<label for="article"><h4>Description</h4></label>
<div class="mdd_toolbar"></div>
<textarea class="form-control mdd_editor" name="description" id="description" placeholder="This is a cool collection of uploads and pastes" title="enter the description for this vault" data-provide="markdown" rows="5">@Model.description</textarea>
<div class="col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Description</div>
<div class="panel-body">
<div class="mdd_toolbar"></div>
<textarea class="form-control mdd_editor" name="description" id="description" placeholder="This is a cool collection of uploads and pastes" title="enter the description for this vault" data-provide="markdown" rows="5">@Model.description</textarea>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Preview</div>
<div class="panel-body">

22
Teknik/Scripts/Vault/Vault.js

@ -1,12 +1,18 @@ @@ -1,12 +1,18 @@
$(document).ready(function () {
//$("textarea.mdd_editor").MarkdownDeep({
// help_location: helpURL,
// disableTabHandling: false,
// resizebar: false,
// SafeMode: true,
// ExtraMode: true,
// MarkdownInHtml: true
//});
// Initial Load
var oldVal = $('textarea.mdd_editor').val();
$('.mdd_preview').html(marked(sanitizeHtml(oldVal)));
$('textarea.mdd_editor').on('change keyup paste', function () {
var currentVal = $(this).val();
if (currentVal == oldVal) {
return; //check to prevent multiple simultaneous triggers
}
oldVal = currentVal;
$('.mdd_preview').html(marked(sanitizeHtml(oldVal)));
});
$('.hideContent').each(function () {
if ($(this).find('pre').height() > 400) {

1
Teknik/Teknik.csproj

@ -76,6 +76,7 @@ @@ -76,6 +76,7 @@
<ItemGroup>
<ProjectReference Include="..\Configuration\Configuration.csproj" />
<ProjectReference Include="..\GitService\GitService.csproj" />
<ProjectReference Include="..\Logging\Logging.csproj" />
<ProjectReference Include="..\MailService\MailService.csproj" />
<ProjectReference Include="..\Piwik\Piwik.csproj" />

2
Teknik/bundleconfig.json

@ -232,6 +232,8 @@ @@ -232,6 +232,8 @@
"inputFiles": [
"wwwroot/lib/bootbox/js/bootbox.js",
"wwwroot/lib/jquery/js/jquery.BlockUI.js",
"wwwroot/lib/marked/js/marked.js",
"wwwroot/lib/sanitize-html/js/sanitize-html.js",
"wwwroot/js/app/Vault/Vault.js"
]
},

Loading…
Cancel
Save