mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Added hmail server support for user
This commit is contained in:
parent
3e9afafd09
commit
3b6532daff
@ -46,12 +46,12 @@ namespace Teknik.Areas.Contact.Controllers
|
||||
|
||||
// Let's also email the message to support
|
||||
SmtpClient client = new SmtpClient();
|
||||
client.Host = Config.SMTPConfig.Host;
|
||||
client.Port = Config.SMTPConfig.Port;
|
||||
client.EnableSsl = Config.SMTPConfig.SSL;
|
||||
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.SMTPConfig.Username, Config.SMTPConfig.Password);
|
||||
client.Credentials = new System.Net.NetworkCredential(Config.ContactConfig.Username, Config.ContactConfig.Password);
|
||||
client.Timeout = 5000;
|
||||
|
||||
MailMessage mail = new MailMessage(Config.SupportEmail, Config.SupportEmail);
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Security;
|
||||
@ -14,6 +15,7 @@ using Teknik.Controllers;
|
||||
using Teknik.Helpers;
|
||||
using Teknik.Models;
|
||||
using Teknik.ViewModels;
|
||||
using System.Windows;
|
||||
|
||||
namespace Teknik.Areas.Profile.Controllers
|
||||
{
|
||||
@ -167,6 +169,32 @@ namespace Teknik.Areas.Profile.Controllers
|
||||
}
|
||||
try
|
||||
{
|
||||
// Connect to hmailserver COM
|
||||
if (!Config.DevEnvironment)
|
||||
{
|
||||
string email = string.Format("{0}@{1}", model.Username, Config.Host);
|
||||
var app = new hMailServer.Application();
|
||||
app.Connect();
|
||||
app.Authenticate(Config.EmailConfig.Username, Config.EmailConfig.Password);
|
||||
|
||||
var domain = app.Domains.ItemByName[Config.Host];
|
||||
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();
|
||||
}
|
||||
|
||||
// Add User
|
||||
User newUser = db.Users.Create();
|
||||
newUser.JoinDate = DateTime.Now;
|
||||
@ -217,6 +245,16 @@ namespace Teknik.Areas.Profile.Controllers
|
||||
}
|
||||
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.Host];
|
||||
var account = domain.Accounts.ItemByAddress[string.Format("{0}@{1}",User.Identity.Name, Config.Host)];
|
||||
account.Password = newPass;
|
||||
account.Save();
|
||||
|
||||
user.UserSettings.Website = website;
|
||||
user.UserSettings.Quote = quote;
|
||||
user.UserSettings.About = about;
|
||||
@ -242,6 +280,14 @@ namespace Teknik.Areas.Profile.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
// Delete Email
|
||||
var app = new hMailServer.Application();
|
||||
app.Connect();
|
||||
app.Authenticate(Config.EmailConfig.Username, Config.EmailConfig.Password);
|
||||
var domain = app.Domains.ItemByName[Config.Host];
|
||||
var account = domain.Accounts.ItemByAddress[string.Format("{0}@{1}", User.Identity.Name, Config.Host)];
|
||||
account.Delete();
|
||||
|
||||
// Update uploads
|
||||
List<Upload.Models.Upload> uploads = db.Uploads.Include("User").Where(u => u.User.Username == User.Identity.Name).ToList();
|
||||
if (uploads != null)
|
||||
|
@ -17,7 +17,8 @@ namespace Teknik.Configuration
|
||||
private string _Description;
|
||||
private string _Author;
|
||||
private string _Host;
|
||||
private SMTPConfig _SMTPConfig;
|
||||
private ContactConfig _ContactConfig;
|
||||
private EmailConfig _EmailConfig;
|
||||
private UploadConfig _UploadConfig;
|
||||
private PasteConfig _PasteConfig;
|
||||
private BlogConfig _BlogConfig;
|
||||
@ -34,8 +35,11 @@ namespace Teknik.Configuration
|
||||
public string Author { get { return _Author; } set { _Author = value; } }
|
||||
public string Host { get { return _Host; } set { _Host = value; } }
|
||||
|
||||
// Contact Configuration
|
||||
public ContactConfig ContactConfig { get { return _ContactConfig; } set { _ContactConfig = value; } }
|
||||
|
||||
// Mail Server Configuration
|
||||
public SMTPConfig SMTPConfig { get { return _SMTPConfig; } set { _SMTPConfig = value; } }
|
||||
public EmailConfig EmailConfig { get { return _EmailConfig; } set { _EmailConfig = value; } }
|
||||
|
||||
// Contact Configuration
|
||||
public string SupportEmail { get { return _SupportEmail; } set { _SupportEmail = value; } }
|
||||
@ -75,7 +79,8 @@ namespace Teknik.Configuration
|
||||
Description = string.Empty;
|
||||
Author = string.Empty;
|
||||
Host = string.Empty;
|
||||
SMTPConfig = new SMTPConfig();
|
||||
EmailConfig = new EmailConfig();
|
||||
ContactConfig = new ContactConfig();
|
||||
BlogConfig = new BlogConfig();
|
||||
UploadConfig = new UploadConfig();
|
||||
PasteConfig = new PasteConfig();
|
||||
|
@ -7,7 +7,7 @@ using System.Net.Mail;
|
||||
|
||||
namespace Teknik.Configuration
|
||||
{
|
||||
public class SMTPConfig
|
||||
public class ContactConfig
|
||||
{
|
||||
public string Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
@ -15,7 +15,7 @@ namespace Teknik.Configuration
|
||||
public string Password { get; set; }
|
||||
public bool SSL { get; set; }
|
||||
|
||||
public SMTPConfig()
|
||||
public ContactConfig()
|
||||
{
|
||||
SetDefaults();
|
||||
}
|
23
Teknik/Configuration/EmailConfig.cs
Normal file
23
Teknik/Configuration/EmailConfig.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Teknik.Configuration
|
||||
{
|
||||
public class EmailConfig
|
||||
{
|
||||
public string Username { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
|
||||
public int MaxSize { get; set; }
|
||||
|
||||
public EmailConfig()
|
||||
{
|
||||
Username = string.Empty;
|
||||
Password = string.Empty;
|
||||
MaxSize = 1000;
|
||||
}
|
||||
}
|
||||
}
|
@ -76,6 +76,7 @@
|
||||
<HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="RouteDebugger, Version=2.1.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\routedebugger.2.1.4.0\lib\net40\RouteDebugger.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@ -218,12 +219,13 @@
|
||||
<Compile Include="Areas\Upload\ViewModels\DownloadViewModel.cs" />
|
||||
<Compile Include="Areas\Upload\ViewModels\UploadViewModel.cs" />
|
||||
<Compile Include="Configuration\ApiConfig.cs" />
|
||||
<Compile Include="Configuration\EmailConfig.cs" />
|
||||
<Compile Include="Configuration\PodcastConfig.cs" />
|
||||
<Compile Include="Configuration\BlogConfig.cs" />
|
||||
<Compile Include="Configuration\Config.cs" />
|
||||
<Compile Include="Areas\Blog\Controllers\BlogController.cs" />
|
||||
<Compile Include="Configuration\PasteConfig.cs" />
|
||||
<Compile Include="Configuration\SMTPConfig.cs" />
|
||||
<Compile Include="Configuration\ContactConfig.cs" />
|
||||
<Compile Include="Configuration\UploadConfig.cs" />
|
||||
<Compile Include="Controllers\DefaultController.cs" />
|
||||
<Compile Include="Areas\Dev\Controllers\DevController.cs" />
|
||||
@ -549,6 +551,17 @@
|
||||
<ItemGroup>
|
||||
<Content Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<COMReference Include="hMailServer">
|
||||
<Guid>{DB241B59-A1B1-4C59-98FC-8D101A2995F2}</Guid>
|
||||
<VersionMajor>1</VersionMajor>
|
||||
<VersionMinor>0</VersionMinor>
|
||||
<Lcid>0</Lcid>
|
||||
<WrapperTool>tlbimp</WrapperTool>
|
||||
<Isolated>False</Isolated>
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
</COMReference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
Loading…
Reference in New Issue
Block a user