mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Fixed unable to logoff on dev.
Moved cookie creation to user helper. Added try/catch around hmail COM.
This commit is contained in:
parent
245a72f191
commit
64871e8564
@ -137,22 +137,7 @@ namespace Teknik.Areas.Profile.Controllers
|
||||
db.Entry(user).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
}
|
||||
HttpCookie authcookie = FormsAuthentication.GetAuthCookie(model.Username, model.RememberMe);
|
||||
authcookie.Name = "TeknikAuth";
|
||||
authcookie.HttpOnly = true;
|
||||
authcookie.Secure = true;
|
||||
authcookie.Domain = string.Format(".{0}", Request.Url.Host.GetDomain());
|
||||
if (Config.DevEnvironment)
|
||||
{
|
||||
authcookie.Domain = string.Format("dev.{0}", Request.Url.Host.GetDomain());
|
||||
}
|
||||
// Make it work for localhost
|
||||
if (Request.IsLocal)
|
||||
{
|
||||
authcookie.Domain = Request.Url.Host.GetDomain();
|
||||
authcookie.HttpOnly = false;
|
||||
authcookie.Secure = false;
|
||||
}
|
||||
HttpCookie authcookie = Utility.UserHelper.CreateAuthCookie(model.Username, model.RememberMe, Request.Url.Host.GetDomain(), Request.IsLocal);
|
||||
Response.Cookies.Add(authcookie);
|
||||
|
||||
if (string.IsNullOrEmpty(model.ReturnUrl))
|
||||
@ -171,7 +156,17 @@ namespace Teknik.Areas.Profile.Controllers
|
||||
|
||||
public ActionResult Logout()
|
||||
{
|
||||
// Get cookie
|
||||
HttpCookie authCookie = Utility.UserHelper.CreateAuthCookie(User.Identity.Name, false, Request.Url.Host.GetDomain(), Request.IsLocal);
|
||||
|
||||
// Signout
|
||||
FormsAuthentication.SignOut();
|
||||
Session.Abandon();
|
||||
|
||||
// Destroy Cookies
|
||||
authCookie.Expires = DateTime.Now.AddYears(-1);
|
||||
Response.Cookies.Add(authCookie);
|
||||
|
||||
return Redirect(Url.SubRouteUrl("www", "Home.Index"));
|
||||
}
|
||||
|
||||
@ -302,13 +297,18 @@ namespace Teknik.Areas.Profile.Controllers
|
||||
// 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();
|
||||
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
|
||||
@ -352,13 +352,18 @@ namespace Teknik.Areas.Profile.Controllers
|
||||
{
|
||||
if (Config.EmailConfig.Enabled)
|
||||
{
|
||||
// Delete Email
|
||||
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.Delete();
|
||||
try
|
||||
{
|
||||
// Delete Email
|
||||
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.Delete();
|
||||
}
|
||||
catch (COMException)
|
||||
{ }
|
||||
}
|
||||
|
||||
// Delete Git
|
||||
|
36
Teknik/Areas/Profile/Utility/UserHelper.cs
Normal file
36
Teknik/Areas/Profile/Utility/UserHelper.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using Teknik.Configuration;
|
||||
|
||||
namespace Teknik.Areas.Profile.Utility
|
||||
{
|
||||
public static class UserHelper
|
||||
{
|
||||
public static HttpCookie CreateAuthCookie(string username, bool remember, string domain, bool local)
|
||||
{
|
||||
Config config = Config.Load();
|
||||
HttpCookie authcookie = FormsAuthentication.GetAuthCookie(username, remember);
|
||||
authcookie.Name = "TeknikAuth";
|
||||
authcookie.HttpOnly = true;
|
||||
authcookie.Secure = true;
|
||||
authcookie.Domain = string.Format(".{0}", domain);
|
||||
if (config.DevEnvironment)
|
||||
{
|
||||
authcookie.Domain = string.Format("dev.{0}", domain);
|
||||
}
|
||||
// Make it work for localhost
|
||||
if (local)
|
||||
{
|
||||
authcookie.Domain = domain;
|
||||
authcookie.Secure = false;
|
||||
}
|
||||
|
||||
return authcookie;
|
||||
}
|
||||
}
|
||||
}
|
@ -202,6 +202,7 @@
|
||||
<Compile Include="Areas\Profile\Models\UploadSettings.cs" />
|
||||
<Compile Include="Areas\Profile\Models\UserSettings.cs" />
|
||||
<Compile Include="Areas\Profile\ProfileAreaRegistration.cs" />
|
||||
<Compile Include="Areas\Profile\Utility\UserHelper.cs" />
|
||||
<Compile Include="Areas\Profile\ViewModels\ProfileViewModel.cs" />
|
||||
<Compile Include="Areas\Profile\ViewModels\SettingsViewModel.cs" />
|
||||
<Compile Include="Areas\RSS\Controllers\RSSController.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user