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

Added 'Enabled' for most service configs.

Added Git configration on user modifications.
This commit is contained in:
Uncled1023 2016-01-28 15:24:12 -08:00
parent 638d90bf9b
commit 1c7f0ce4f0
19 changed files with 414 additions and 254 deletions

View File

@ -32,47 +32,51 @@ namespace Teknik.Areas.Contact.Controllers
{
if (ModelState.IsValid)
{
try
if (Config.ContactConfig.Enabled)
{
// Insert the message into the DB
Models.Contact newContact = db.Contact.Create();
newContact.Name = model.Name;
newContact.Email = model.Email;
newContact.Subject = model.Subject;
newContact.Message = model.Message;
newContact.DateAdded = DateTime.Now;
db.Contact.Add(newContact);
db.SaveChanges();
try
{
// Insert the message into the DB
Models.Contact newContact = db.Contact.Create();
newContact.Name = model.Name;
newContact.Email = model.Email;
newContact.Subject = model.Subject;
newContact.Message = model.Message;
newContact.DateAdded = DateTime.Now;
db.Contact.Add(newContact);
db.SaveChanges();
// Let's also email the message to support
SmtpClient client = new SmtpClient();
client.Host = Config.ContactConfig.Host;
client.Port = Config.ContactConfig.Port;
client.EnableSsl = Config.ContactConfig.SSL;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential(Config.ContactConfig.Username, Config.ContactConfig.Password);
client.Timeout = 5000;
// Let's also email the message to support
SmtpClient client = new SmtpClient();
client.Host = Config.ContactConfig.Host;
client.Port = Config.ContactConfig.Port;
client.EnableSsl = Config.ContactConfig.SSL;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential(Config.ContactConfig.Username, Config.ContactConfig.Password);
client.Timeout = 5000;
MailMessage mail = new MailMessage(Config.SupportEmail, Config.SupportEmail);
mail.Subject = string.Format("Support Message from: {0} <{1}>", model.Name, model.Email);
mail.Body = string.Format(@"
MailMessage mail = new MailMessage(Config.SupportEmail, Config.SupportEmail);
mail.Subject = string.Format("Support Message from: {0} <{1}>", model.Name, model.Email);
mail.Body = string.Format(@"
New Support Message from: {0} <{1}>
---------------------------------
Subject: {2}
Message: {3}", model.Name, model.Email, model.Subject, model.Message);
mail.BodyEncoding = UTF8Encoding.UTF8;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Never;
mail.BodyEncoding = UTF8Encoding.UTF8;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Never;
client.Send(mail);
}
catch (Exception ex)
{
return Json(new { error = "Error submitting message. Exception: " + ex.Message});
}
client.Send(mail);
}
catch (Exception ex)
{
return Json(new { error = "Error submitting message. Exception: " + ex.Message });
}
return Json(new { result = "true" });
return Json(new { result = "true" });
}
return Json(new { error = "Contact Form is disabled" });
}
else
{

View File

@ -107,33 +107,37 @@ namespace Teknik.Areas.Paste.Controllers
{
if (ModelState.IsValid)
{
try
if (Config.PasteConfig.Enabled)
{
Models.Paste paste = PasteHelper.CreatePaste(model.Content, model.Title, model.Syntax, model.ExpireUnit, model.ExpireLength ?? 1, model.Password, model.Hide);
if (model.ExpireUnit == "view")
try
{
paste.Views = -1;
}
Models.Paste paste = PasteHelper.CreatePaste(model.Content, model.Title, model.Syntax, model.ExpireUnit, model.ExpireLength ?? 1, model.Password, model.Hide);
if (User.Identity.IsAuthenticated)
{
Profile.Models.User user = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault();
if (user != null)
if (model.ExpireUnit == "view")
{
paste.UserId = user.UserId;
paste.Views = -1;
}
if (User.Identity.IsAuthenticated)
{
Profile.Models.User user = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault();
if (user != null)
{
paste.UserId = user.UserId;
}
}
db.Pastes.Add(paste);
db.SaveChanges();
return Redirect(Url.SubRouteUrl("paste", "Paste.View", new { type = "Full", url = paste.Url, password = model.Password }));
}
catch (Exception ex)
{
return Redirect(Url.SubRouteUrl("error", "Error.500", new { exception = ex }));
}
db.Pastes.Add(paste);
db.SaveChanges();
return Redirect(Url.SubRouteUrl("paste", "Paste.View", new { type = "Full", url = paste.Url, password = model.Password }));
}
catch (Exception ex)
{
return Redirect(Url.SubRouteUrl("error", "Error.500", new { exception = ex }));
}
Redirect(Url.SubRouteUrl("error", "Error.Http403"));
}
return View("~/Areas/Paste/Views/Paste/Index.cshtml", model);
}

View File

@ -16,6 +16,7 @@ using Teknik.Helpers;
using Teknik.Models;
using Teknik.ViewModels;
using System.Windows;
using System.Net;
namespace Teknik.Areas.Profile.Controllers
{
@ -158,65 +159,83 @@ namespace Teknik.Areas.Profile.Controllers
{
if (ModelState.IsValid)
{
var foundUser = db.Users.Where(b => b.Username == model.Username).FirstOrDefault();
if (foundUser != null)
if (Config.UserConfig.RegistrationEnabled)
{
return Json(new { error = "That username already exists." });
}
if (model.Password != model.ConfirmPassword)
{
return Json(new { error = "Passwords must match." });
}
try
{
// Connect to hmailserver COM
if (!Config.DevEnvironment)
var foundUser = db.Users.Where(b => b.Username == model.Username).FirstOrDefault();
if (foundUser != null)
{
return Json(new { error = "That username already exists." });
}
if (model.Password != model.ConfirmPassword)
{
return Json(new { error = "Passwords must match." });
}
try
{
string email = string.Format("{0}@{1}", model.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];
try
// If Email Server is enabled
if (Config.EmailConfig.Enabled)
{
var account = domain.Accounts.ItemByAddress[email];
return Json(new { error = "That email already exists." });
// 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];
try
{
var account = domain.Accounts.ItemByAddress[email];
return Json(new { error = "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 = model.Password;
newAccount.Active = true;
newAccount.MaxSize = Config.EmailConfig.MaxSize;
newAccount.Save();
}
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 = model.Password;
newAccount.Active = true;
newAccount.MaxSize = Config.EmailConfig.MaxSize;
// If Git is enabled
if (Config.GitConfig.Enabled)
{
// Add gogs user
using (var client = new WebClient())
{
var obj = new { source_id = 1, username = model.Username, email = email, password = model.Password };
client.Headers[HttpRequestHeader.ContentType] = "application/json";
Uri baseUri = new Uri(Config.GitConfig.Host);
string result = client.UploadString(new Uri(baseUri, "admin/users").ToString(), "POST", Newtonsoft.Json.JsonConvert.SerializeObject(obj));
}
}
newAccount.Save();
// Add User
User newUser = db.Users.Create();
newUser.JoinDate = DateTime.Now;
newUser.Username = model.Username;
newUser.HashedPassword = SHA384.Hash(model.Username, model.Password);
newUser.UserSettings = new UserSettings();
newUser.BlogSettings = new BlogSettings();
newUser.UploadSettings = new UploadSettings();
db.Users.Add(newUser);
db.SaveChanges();
// Generate blog for the user
var newBlog = db.Blogs.Create();
newBlog.UserId = db.Users.Where(u => u.Username == model.Username).Select(u => u.UserId).First();
db.Blogs.Add(newBlog);
db.SaveChanges();
}
// Add User
User newUser = db.Users.Create();
newUser.JoinDate = DateTime.Now;
newUser.Username = model.Username;
newUser.HashedPassword = SHA384.Hash(model.Username, model.Password);
newUser.UserSettings = new UserSettings();
newUser.BlogSettings = new BlogSettings();
newUser.UploadSettings = new UploadSettings();
db.Users.Add(newUser);
db.SaveChanges();
// Generate blog for the user
var newBlog = db.Blogs.Create();
newBlog.UserId = db.Users.Where(u => u.Username == model.Username).Select(u => u.UserId).First();
db.Blogs.Add(newBlog);
db.SaveChanges();
catch (Exception ex)
{
return Json(new { error = "Unable to create the user." });
}
return Login(new LoginViewModel { Username = model.Username, Password = model.Password, RememberMe = false, ReturnUrl = model.ReturnUrl });
}
catch (Exception ex)
{
return Json(new { error = "Unable to create the user." });
}
return Login(new LoginViewModel { Username = model.Username, Password = model.Password, RememberMe = false, ReturnUrl = model.ReturnUrl });
return Json(new { error = "User Registration is Disabled" });
}
return Json(new { error = "You must include all fields." });
}
@ -230,6 +249,7 @@ namespace Teknik.Areas.Profile.Controllers
User user = db.Users.Where(u => u.Username == User.Identity.Name).First();
if (user != null)
{
string email = string.Format("{0}@{1}", User.Identity.Name, Config.EmailConfig.Domain);
// Changing Password?
if (!string.IsNullOrEmpty(curPass) && (!string.IsNullOrEmpty(newPass) || !string.IsNullOrEmpty(newPassConfirm)))
{
@ -244,16 +264,31 @@ namespace Teknik.Areas.Profile.Controllers
return Json(new { error = "New Password Must Match." });
}
user.HashedPassword = SHA384.Hash(User.Identity.Name, newPass);
}
// Update Email Pass
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.Identity.Name, Config.EmailConfig.Domain)];
account.Password = newPass;
account.Save();
// Update Email Pass
if (Config.EmailConfig.Enabled)
{
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();
}
// Update Git Pass
if (Config.GitConfig.Enabled)
{
using (var client = new WebClient())
{
var obj = new { source_id = 1, email = email, password = newPass };
client.Headers[HttpRequestHeader.ContentType] = "application/json";
Uri baseUri = new Uri(Config.GitConfig.Host);
string result = client.UploadString(new Uri(baseUri, "admin/users/" + User.Identity.Name).ToString(), "PATCH", Newtonsoft.Json.JsonConvert.SerializeObject(obj));
}
}
}
user.UserSettings.Website = website;
user.UserSettings.Quote = quote;
@ -288,6 +323,16 @@ namespace Teknik.Areas.Profile.Controllers
var account = domain.Accounts.ItemByAddress[string.Format("{0}@{1}", User.Identity.Name, Config.EmailConfig.Domain)];
account.Delete();
// Delete Git
if (Config.GitConfig.Enabled)
{
Uri baseUri = new Uri(Config.GitConfig.Host);
WebRequest request = WebRequest.Create(new Uri(baseUri, "admin/users/" + User.Identity.Name).ToString());
request.Method = "DELETE";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
}
// Update uploads
List<Upload.Models.Upload> uploads = db.Uploads.Include("User").Where(u => u.User.Username == User.Identity.Name).ToList();
if (uploads != null)

View File

@ -1,5 +1,7 @@
@model Teknik.Areas.Profile.ViewModels.LoginViewModel
@if (Model.Config.UserConfig.LoginEnabled)
{
<form role="form" id="loginForm" action="@Url.SubRouteUrl("profile", "Profile.Login")" method="post" accept-charset="UTF-8">
@Html.AntiForgeryToken()
<input name="ReturnUrl" id="ReturnUrl" type="hidden" value="@Model.ReturnUrl" />
@ -18,3 +20,8 @@
<button class="btn btn-primary" id="login_submit" type="submit" name="submit">Sign In</button>
</div>
</form>
}
else
{
<h3>User logins have been disabled</h3>
}

View File

@ -1,5 +1,7 @@
@model Teknik.Areas.Profile.ViewModels.RegisterViewModel
@if (Model.Config.UserConfig.RegistrationEnabled)
{
<form role="form" id="registrationForm" action="@Url.SubRouteUrl("profile", "Profile.Register")" method="post" accept-charset="UTF-8">
@Html.AntiForgeryToken()
<input name="ReturnUrl" id="ReturnUrl" type="hidden" value="@Model.ReturnUrl" />
@ -15,4 +17,9 @@
<div class="form-group text-center">
<button class="btn btn-primary" id="reg_submit" type="submit" name="submit">Sign Up</button>
</div>
</form>
</form>
}
else
{
<h3>Registration has been disabled</h3>
}

View File

@ -44,51 +44,55 @@ namespace Teknik.Areas.Upload.Controllers
[ValidateAntiForgeryToken]
public ActionResult Upload(string fileType, string fileExt, string iv, int keySize, int blockSize, bool encrypt, HttpPostedFileWrapper data, string key = null)
{
if (data.ContentLength <= Config.UploadConfig.MaxUploadSize)
if (Config.UploadConfig.UploadEnabled)
{
// convert file to bytes
byte[] fileData = null;
int contentLength = data.ContentLength;
using (var binaryReader = new BinaryReader(data.InputStream))
if (data.ContentLength <= Config.UploadConfig.MaxUploadSize)
{
fileData = binaryReader.ReadBytes(data.ContentLength);
}
// if they want us to encrypt it, we do so here
if (encrypt)
{
// Generate key and iv if empty
if (string.IsNullOrEmpty(key))
// convert file to bytes
byte[] fileData = null;
int contentLength = data.ContentLength;
using (var binaryReader = new BinaryReader(data.InputStream))
{
key = Utility.RandomString(keySize / 8);
fileData = binaryReader.ReadBytes(data.ContentLength);
}
fileData = AES.Encrypt(fileData, key, iv);
if (fileData == null || fileData.Length <= 0)
// if they want us to encrypt it, we do so here
if (encrypt)
{
return Json(new { error = new { message = "Unable to encrypt file" } });
}
}
Models.Upload upload = Uploader.SaveFile(fileData, fileType, contentLength, fileExt, iv, key, keySize, blockSize);
if (upload != null)
{
if (User.Identity.IsAuthenticated)
{
Profile.Models.User user = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault();
if (user != null)
// Generate key and iv if empty
if (string.IsNullOrEmpty(key))
{
upload.UserId = user.UserId;
db.Entry(upload).State = EntityState.Modified;
db.SaveChanges();
key = Utility.RandomString(keySize / 8);
}
fileData = AES.Encrypt(fileData, key, iv);
if (fileData == null || fileData.Length <= 0)
{
return Json(new { error = new { message = "Unable to encrypt file" } });
}
}
return Json(new { result = new { name = upload.Url, url = Url.SubRouteUrl("upload", "Upload.Download", new { file = upload.Url }) } }, "text/plain");
Models.Upload upload = Uploader.SaveFile(fileData, fileType, contentLength, fileExt, iv, key, keySize, blockSize);
if (upload != null)
{
if (User.Identity.IsAuthenticated)
{
Profile.Models.User user = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault();
if (user != null)
{
upload.UserId = user.UserId;
db.Entry(upload).State = EntityState.Modified;
db.SaveChanges();
}
}
return Json(new { result = new { name = upload.Url, url = Url.SubRouteUrl("upload", "Upload.Download", new { file = upload.Url }) } }, "text/plain");
}
return Json(new { error = "Unable to upload file" });
}
else
{
return Json(new { error = "File Too Large" });
}
return Json(new { error = "Unable to upload file" });
}
else
{
return Json(new { error = "File Too Large" });
}
return Json(new { error = "Uploads are disabled" });
}
// User did not supply key
@ -96,52 +100,56 @@ namespace Teknik.Areas.Upload.Controllers
[AllowAnonymous]
public ActionResult Download(string file)
{
ViewBag.Title = "Teknik Download - " + file;
Models.Upload upload = db.Uploads.Where(up => up.Url == file).FirstOrDefault();
if (upload != null)
if (Config.UploadConfig.DownloadEnabled)
{
upload.Downloads += 1;
db.Entry(upload).State = EntityState.Modified;
db.SaveChanges();
// We don't have the key, so we need to decrypt it client side
if (string.IsNullOrEmpty(upload.Key) && !string.IsNullOrEmpty(upload.IV))
ViewBag.Title = "Teknik Download - " + file;
Models.Upload upload = db.Uploads.Where(up => up.Url == file).FirstOrDefault();
if (upload != null)
{
DownloadViewModel model = new DownloadViewModel();
model.FileName = file;
model.ContentType = upload.ContentType;
model.ContentLength = upload.ContentLength;
model.IV = upload.IV;
return View(model);
}
else // We have the key, so that means server side decryption
{
if (System.IO.File.Exists(upload.FileName))
upload.Downloads += 1;
db.Entry(upload).State = EntityState.Modified;
db.SaveChanges();
// We don't have the key, so we need to decrypt it client side
if (string.IsNullOrEmpty(upload.Key) && !string.IsNullOrEmpty(upload.IV))
{
// Read in the file
byte[] data = System.IO.File.ReadAllBytes(upload.FileName);
DownloadViewModel model = new DownloadViewModel();
model.FileName = file;
model.ContentType = upload.ContentType;
model.ContentLength = upload.ContentLength;
model.IV = upload.IV;
// If the IV is set, and Key is set, then decrypt it
if (!string.IsNullOrEmpty(upload.Key) && !string.IsNullOrEmpty(upload.IV))
return View(model);
}
else // We have the key, so that means server side decryption
{
if (System.IO.File.Exists(upload.FileName))
{
// Decrypt the data
data = AES.Decrypt(data, upload.Key, upload.IV);
// Read in the file
byte[] data = System.IO.File.ReadAllBytes(upload.FileName);
// If the IV is set, and Key is set, then decrypt it
if (!string.IsNullOrEmpty(upload.Key) && !string.IsNullOrEmpty(upload.IV))
{
// Decrypt the data
data = AES.Decrypt(data, upload.Key, upload.IV);
}
// Create content disposition
var cd = new System.Net.Mime.ContentDisposition
{
FileName = upload.Url,
Inline = true
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(data, upload.ContentType);
}
// Create content disposition
var cd = new System.Net.Mime.ContentDisposition
{
FileName = upload.Url,
Inline = true
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(data, upload.ContentType);
}
}
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
}
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
return Redirect(Url.SubRouteUrl("error", "Error.Http403"));
}
[HttpPost]
@ -149,33 +157,38 @@ namespace Teknik.Areas.Upload.Controllers
[ValidateAntiForgeryToken]
public FileResult DownloadData(string file)
{
Models.Upload upload = db.Uploads.Where(up => up.Url == file).FirstOrDefault();
if (upload != null)
if (Config.UploadConfig.DownloadEnabled)
{
string filePath = Path.Combine(Config.UploadConfig.UploadDirectory, upload.FileName);
if (System.IO.File.Exists(filePath))
Models.Upload upload = db.Uploads.Where(up => up.Url == file).FirstOrDefault();
if (upload != null)
{
byte[] buffer;
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
try
string filePath = Path.Combine(Config.UploadConfig.UploadDirectory, upload.FileName);
if (System.IO.File.Exists(filePath))
{
int length = (int)fileStream.Length; // get file length
buffer = new byte[length]; // create buffer
int count; // actual number of bytes read
int sum = 0; // total number of bytes read
byte[] buffer;
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
try
{
int length = (int)fileStream.Length; // get file length
buffer = new byte[length]; // create buffer
int count; // actual number of bytes read
int sum = 0; // total number of bytes read
// read until Read method returns 0 (end of the stream has been reached)
while ((count = fileStream.Read(buffer, sum, length - sum)) > 0)
sum += count; // sum is a buffer offset for next reading
// read until Read method returns 0 (end of the stream has been reached)
while ((count = fileStream.Read(buffer, sum, length - sum)) > 0)
sum += count; // sum is a buffer offset for next reading
}
finally
{
fileStream.Close();
}
return File(buffer, System.Net.Mime.MediaTypeNames.Application.Octet, file);
}
finally
{
fileStream.Close();
}
return File(buffer, System.Net.Mime.MediaTypeNames.Application.Octet, file);
}
Redirect(Url.SubRouteUrl("error", "Error.Http404"));
return null;
}
Redirect(Url.SubRouteUrl("error", "Error.Http404"));
Redirect(Url.SubRouteUrl("error", "Error.Http403"));
return null;
}

View File

@ -8,10 +8,13 @@ namespace Teknik.Configuration
{
public class ApiConfig
{
public bool Enabled { get; set; }
public int Version { get; set; }
public ApiConfig()
{
Enabled = true;
Version = 1;
}
}

View File

@ -7,6 +7,7 @@ namespace Teknik.Configuration
{
public class BlogConfig
{
public bool Enabled { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public int PostsToLoad { get; set; }
@ -19,6 +20,7 @@ namespace Teknik.Configuration
public void SetDefaults()
{
Enabled = true;
Title = string.Empty;
Description = string.Empty;
PostsToLoad = 10;

View File

@ -17,8 +17,10 @@ namespace Teknik.Configuration
private string _Description;
private string _Author;
private string _Host;
private ContactConfig _ContactConfig;
private UserConfig _UserConfig;
private ContactConfig _ContactConfig;
private EmailConfig _EmailConfig;
private GitConfig _GitConfig;
private UploadConfig _UploadConfig;
private PasteConfig _PasteConfig;
private BlogConfig _BlogConfig;
@ -34,6 +36,11 @@ namespace Teknik.Configuration
public string Description { get { return _Description; } set { _Description = value; } }
public string Author { get { return _Author; } set { _Author = value; } }
public string Host { get { return _Host; } set { _Host = value; } }
public string SupportEmail { get { return _SupportEmail; } set { _SupportEmail = value; } }
public string BitcoinAddress { get { return _BitcoinAddress; } set { _BitcoinAddress = value; } }
// User Configuration
public UserConfig UserConfig { get { return _UserConfig; } set { _UserConfig = value; } }
// Contact Configuration
public ContactConfig ContactConfig { get { return _ContactConfig; } set { _ContactConfig = value; } }
@ -41,11 +48,8 @@ namespace Teknik.Configuration
// Mail Server Configuration
public EmailConfig EmailConfig { get { return _EmailConfig; } set { _EmailConfig = value; } }
// Contact Configuration
public string SupportEmail { get { return _SupportEmail; } set { _SupportEmail = value; } }
// About Configuration
public string BitcoinAddress { get { return _BitcoinAddress; } set { _BitcoinAddress = value; } }
// Git Service Configuration
public GitConfig GitConfig { get { return _GitConfig; } set { _GitConfig = value; } }
// Blog Configuration
public BlogConfig BlogConfig { get { return _BlogConfig; } set { _BlogConfig = value; } }
@ -79,8 +83,10 @@ namespace Teknik.Configuration
Description = string.Empty;
Author = string.Empty;
Host = string.Empty;
UserConfig = new UserConfig();
EmailConfig = new EmailConfig();
ContactConfig = new ContactConfig();
GitConfig = new GitConfig();
BlogConfig = new BlogConfig();
UploadConfig = new UploadConfig();
PasteConfig = new PasteConfig();

View File

@ -9,6 +9,7 @@ namespace Teknik.Configuration
{
public class ContactConfig
{
public bool Enabled { get; set; }
public string Host { get; set; }
public int Port { get; set; }
public string Username { get; set; }
@ -22,6 +23,7 @@ namespace Teknik.Configuration
public void SetDefaults()
{
Enabled = true;
Host = string.Empty;
Port = 25;
Username = string.Empty;

View File

@ -7,6 +7,8 @@ namespace Teknik.Configuration
{
public class EmailConfig
{
public bool Enabled { get; set; }
public string Username { get; set; }
public string Password { get; set; }
@ -19,6 +21,7 @@ namespace Teknik.Configuration
public EmailConfig()
{
Enabled = true;
Username = string.Empty;
Password = string.Empty;
Domain = string.Empty;

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Teknik.Configuration
{
public class GitConfig
{
public bool Enabled { get; set; }
public string Host { get; set; }
public int SourceId { get; set; }
public GitConfig()
{
Enabled = true;
Host = string.Empty;
SourceId = 1;
}
}
}

View File

@ -8,12 +8,14 @@ namespace Teknik.Configuration
{
public class PasteConfig
{
public bool Enabled { get; set; }
public int UrlLength { get; set; }
public int KeySize { get; set; }
public int BlockSize { get; set; }
public PasteConfig()
{
Enabled = true;
UrlLength = 5;
KeySize = 256;
BlockSize = 128;

View File

@ -8,6 +8,7 @@ namespace Teknik.Configuration
{
public class PodcastConfig
{
public bool Enabled { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public int PodcastsToLoad { get; set; }
@ -21,6 +22,7 @@ namespace Teknik.Configuration
public void SetDefaults()
{
Enabled = true;
Title = string.Empty;
Description = string.Empty;
PodcastsToLoad = 10;

View File

@ -8,6 +8,8 @@ namespace Teknik.Configuration
{
public class UploadConfig
{
public bool UploadEnabled { get; set; }
public bool DownloadEnabled { get; set; }
// Max upload size in bytes
public int MaxUploadSize { get; set; }
// Location of the upload directory
@ -29,6 +31,8 @@ namespace Teknik.Configuration
public void SetDefaults()
{
UploadEnabled = true;
DownloadEnabled = true;
MaxUploadSize = 100000000;
UploadDirectory = Directory.GetCurrentDirectory();
FileExtension = "enc";

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Teknik.Configuration
{
public class UserConfig
{
public bool RegistrationEnabled { get; set; }
public bool LoginEnabled { get; set; }
public UserConfig()
{
RegistrationEnabled = true;
LoginEnabled = true;
}
}
}

View File

@ -220,6 +220,7 @@
<Compile Include="Areas\Upload\ViewModels\UploadViewModel.cs" />
<Compile Include="Configuration\ApiConfig.cs" />
<Compile Include="Configuration\EmailConfig.cs" />
<Compile Include="Configuration\GitConfig.cs" />
<Compile Include="Configuration\PodcastConfig.cs" />
<Compile Include="Configuration\BlogConfig.cs" />
<Compile Include="Configuration\Config.cs" />
@ -227,6 +228,7 @@
<Compile Include="Configuration\PasteConfig.cs" />
<Compile Include="Configuration\ContactConfig.cs" />
<Compile Include="Configuration\UploadConfig.cs" />
<Compile Include="Configuration\UserConfig.cs" />
<Compile Include="Controllers\DefaultController.cs" />
<Compile Include="Areas\Dev\Controllers\DevController.cs" />
<Compile Include="Global.asax.cs">

View File

@ -1,46 +1,56 @@
@using Microsoft.AspNet.Identity
@model Teknik.ViewModels.ViewModelBase
<ul class="nav navbar-nav pull-right">
@if (Request.IsAuthenticated)
{
<li class="dropdown">
<a href="#" id="user_menu" class="dropdown-toggle" data-toggle="dropdown">@User.Identity.Name <strong class="caret"></strong></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="user_menu">
<li>
<a href="@Url.SubRouteUrl("profile", "Profile.Index", new { username = User.Identity.Name })">Profile</a>
</li>
<li>
<a href="@Url.SubRouteUrl("blog", "Blog.Blog", new { username = User.Identity.Name })">Blog</a>
</li>
<li>
<a href="@Url.SubRouteUrl("profile", "Profile.Settings")">Settings</a>
</li>
@if (User.IsInRole("Admin"))
{
<li>
<a href="@Url.SubRouteUrl("admin", "Admin.Index")">Administration</a>
</li>
}
<li>
<a href="@Url.SubRouteUrl("profile", "Profile.Logout")">Sign Out</a>
</li>
</ul>
</li>
}
else
{
<li class="dropdown">
<a class="dropdown-toggle" href="#" data-toggle="dropdown" id="reg_dropdown">Sign Up <strong class="caret"></strong></a>
<div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
@Html.Partial("../../Areas/Profile/Views/Profile/Register", new Teknik.Areas.Profile.ViewModels.RegisterViewModel())
</div>
</li>
@using Microsoft.AspNet.Identity
<li class="dropdown">
<a class="dropdown-toggle" href="#" data-toggle="dropdown" id="login_dropdown">Sign In <strong class="caret"></strong></a>
<div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
@Html.Partial("../../Areas/Profile/Views/Profile/Login", new Teknik.Areas.Profile.ViewModels.LoginViewModel())
</div>
</li>
}
</ul>
@if (Model.Config.UserConfig.RegistrationEnabled || Model.Config.UserConfig.LoginEnabled)
{
<ul class="nav navbar-nav pull-right">
@if (Request.IsAuthenticated)
{
<li class="dropdown">
<a href="#" id="user_menu" class="dropdown-toggle" data-toggle="dropdown">@User.Identity.Name <strong class="caret"></strong></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="user_menu">
<li>
<a href="@Url.SubRouteUrl("profile", "Profile.Index", new { username = User.Identity.Name })">Profile</a>
</li>
<li>
<a href="@Url.SubRouteUrl("blog", "Blog.Blog", new { username = User.Identity.Name })">Blog</a>
</li>
<li>
<a href="@Url.SubRouteUrl("profile", "Profile.Settings")">Settings</a>
</li>
@if (User.IsInRole("Admin"))
{
<li>
<a href="@Url.SubRouteUrl("admin", "Admin.Index")">Administration</a>
</li>
}
<li>
<a href="@Url.SubRouteUrl("profile", "Profile.Logout")">Sign Out</a>
</li>
</ul>
</li>
}
else
{
if (Model.Config.UserConfig.RegistrationEnabled)
{
<li class="dropdown">
<a class="dropdown-toggle" href="#" data-toggle="dropdown" id="reg_dropdown">Sign Up <strong class="caret"></strong></a>
<div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
@Html.Partial("../../Areas/Profile/Views/Profile/Register", new Teknik.Areas.Profile.ViewModels.RegisterViewModel())
</div>
</li>
}
if (Model.Config.UserConfig.LoginEnabled)
{
<li class="dropdown">
<a class="dropdown-toggle" href="#" data-toggle="dropdown" id="login_dropdown">Sign In <strong class="caret"></strong></a>
<div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
@Html.Partial("../../Areas/Profile/Views/Profile/Login", new Teknik.Areas.Profile.ViewModels.LoginViewModel())
</div>
</li>
}
}
</ul>
}

View File

@ -50,7 +50,7 @@
<a href="@Url.SubRouteUrl("help", "Help.Index")">Help</a>
</li>
</ul>
@Html.Partial("_LoginPartial")
@Html.Partial("_LoginPartial", Model)
</div>
</div>
</div>