Browse Source

Added GetUser and UserExists helpers.

tags/2.0.3
Teknikode 4 years ago
parent
commit
37ab1e2eb3

+ 3
- 4
Teknik/Areas/Profile/Controllers/ProfileController.cs View File

@@ -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
{
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
}

// 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);

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

@@ -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