Browse Source

Fixed auth not working with localhost.

tags/2.0.3
Teknikode 4 years ago
parent
commit
25373918a8
2 changed files with 34 additions and 10 deletions
  1. 34
    6
      Teknik/Areas/Profile/Utility/UserHelper.cs
  2. 0
    4
      Teknik/Global.asax.cs

+ 34
- 6
Teknik/Areas/Profile/Utility/UserHelper.cs View File

@@ -5,12 +5,37 @@ using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Security;
using Teknik.Areas.Profile.Models;
using Teknik.Configuration;
using Teknik.Models;

namespace Teknik.Areas.Profile.Utility
{
public static class UserHelper
{
public static User GetUser(string username)
{
TeknikEntities db = new TeknikEntities();

User user = db.Users.Where(b => b.Username == username).FirstOrDefault();

return user;
}

public static bool UserExists(string username)
{
TeknikEntities db = new TeknikEntities();
bool exists = false;

User user = db.Users.Where(b => b.Username == username).FirstOrDefault();
if (user != null)
{
exists = true;
}

return exists;
}

public static HttpCookie CreateAuthCookie(string username, bool remember, string domain, bool local)
{
Config config = Config.Load();
@@ -18,16 +43,19 @@ namespace Teknik.Areas.Profile.Utility
authcookie.Name = "TeknikAuth";
authcookie.HttpOnly = true;
authcookie.Secure = true;
authcookie.Domain = string.Format(".{0}", domain);
if (config.DevEnvironment)

// 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);
}
// Make it work for localhost
if (local)
else // A production instance
{
authcookie.Domain = domain;
authcookie.Secure = false;
authcookie.Domain = string.Format(".{0}", domain);
}

return authcookie;

+ 0
- 4
Teknik/Global.asax.cs View File

@@ -62,10 +62,6 @@ namespace Teknik
{
context.Response.AppendHeader("Access-Control-Allow-Origin", origin);
}
else if (Request.IsLocal)
{
context.Response.AppendHeader("Access-Control-Allow-Origin", "*");
}
}

protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)

Loading…
Cancel
Save