private static SystemAdmin AddSystemAdminToken(string email, string token) { using (var service = new SystemAdminService()) { var sysAdmin = service.GetWhere(SystemAdminService.EmailCol == email).FirstOrDefault(); if (sysAdmin != null) { using (var tokenService = new SystemAdminTokenService()) { var storedToken = tokenService.GetWhere(SystemAdminTokenService.SystemAdminCodeCol == sysAdmin.Code).FirstOrDefault(); if (storedToken == null) { tokenService.Create(new SystemAdminToken(sysAdmin, token)); } else { storedToken.Token = token; storedToken.Expires = DateTime.Now.ToUniversalTime().AddHours(Config.TokenDuration); tokenService.Update(storedToken); } } } return(sysAdmin); } }
public static SystemAdmin VerifySystemAdminToken(string token) { using (var service = new SystemAdminTokenService()) { var adminToken = service.GetWhere(SystemAdminTokenService.TokenCol == token).FirstOrDefault(); if (adminToken != null && adminToken.Expires > DateTime.Now.ToUniversalTime()) { return(adminToken.SystemAdmin); } return(null); } }
public static bool ResetSystemAdminPassword(string token, SystemAdmin admin, byte[] newPasswordHash) { using (var service = new SystemAdminTokenService()) { var adminToken = service.GetWhere(SystemAdminTokenService.TokenCol == token).FirstOrDefault(); if (adminToken != null && admin != null && adminToken.Expires > DateTime.Now.ToUniversalTime() && adminToken.SystemAdmin.Code == admin.Code) { service.Delete(adminToken.Code); using (var adminService = new SystemAdminService()) { admin.PasswordHash = newPasswordHash; adminService.Update(admin); } return(true); } return(false); } }