Browse Source

Added GetUser and UserExists helpers.

pull/29/head
Teknikode 6 years ago
parent
commit
37ab1e2eb3
  1. 7
      Teknik/Areas/Profile/Controllers/ProfileController.cs
  2. 9
      Teknik/Areas/Profile/Utility/UserHelper.cs

7
Teknik/Areas/Profile/Controllers/ProfileController.cs

@ -189,8 +189,7 @@ namespace Teknik.Areas.Profile.Controllers @@ -189,8 +189,7 @@ namespace Teknik.Areas.Profile.Controllers
{
if (Config.UserConfig.RegistrationEnabled)
{
var foundUser = db.Users.Where(b => b.Username == model.Username).FirstOrDefault();
if (foundUser != null)
if (Utility.UserHelper.UserExists(model.Username))
{
return Json(new { error = "That username already exists." });
}
@ -275,7 +274,7 @@ namespace Teknik.Areas.Profile.Controllers @@ -275,7 +274,7 @@ namespace Teknik.Areas.Profile.Controllers
{
if (ModelState.IsValid)
{
User user = db.Users.Where(u => u.Username == User.Identity.Name).First();
User user = Utility.UserHelper.GetUser(User.Identity.Name);
if (user != null)
{
string email = string.Format("{0}@{1}", User.Identity.Name, Config.EmailConfig.Domain);
@ -427,7 +426,7 @@ namespace Teknik.Areas.Profile.Controllers @@ -427,7 +426,7 @@ namespace Teknik.Areas.Profile.Controllers
}
// Delete User
User user = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault();
User user = Utility.UserHelper.GetUser(User.Identity.Name);
if (user != null)
{
user.UserSettings = db.UserSettings.Find(user.UserId);

9
Teknik/Areas/Profile/Utility/UserHelper.cs

@ -24,16 +24,13 @@ namespace Teknik.Areas.Profile.Utility @@ -24,16 +24,13 @@ namespace Teknik.Areas.Profile.Utility
public static bool UserExists(string username)
{
TeknikEntities db = new TeknikEntities();
bool exists = false;
User user = db.Users.Where(b => b.Username == username).FirstOrDefault();
User user = GetUser(username);
if (user != null)
{
exists = true;
return true;
}
return exists;
return false;
}
public static HttpCookie CreateAuthCookie(string username, bool remember, string domain, bool local)

Loading…
Cancel
Save