private void UpdateOperations() { var syncInfo = new SyncInfo(); using (var context = new PhoneDexContext()) { bool isUpdated = false; if (context.SyncInfo.FirstOrDefault() != null) { syncInfo = context.SyncInfo.First(); } if (syncInfo.lastLdapSyncDate != null) { isUpdated = IsUpToDate(DateTime.Now, syncInfo.lastLdapSyncDate.Value); } if (isUpdated == false) { var integratedContacts = new LdapServiceManager().getAllUsers(); var manualContacts = context.Contacts.Where(x => x.isManual); if (integratedContacts.Any()) { DeleteIntegratedUsers(context); } _contactList.AddRange(manualContacts); _contactList.AddRange(integratedContacts); context.Contacts.AddRange(integratedContacts); context.SyncInfo.RemoveRange(context.SyncInfo); context.SaveChanges(); syncInfo.recordsCount = integratedContacts.Count; syncInfo.lastLdapSyncDate = DateTime.Now; context.SyncInfo.Add(syncInfo); context.SaveChanges(); } else { foreach (var contact in (from r in context.Contacts select r)) { _contactList.Add(contact); } } } }
public JsonResult Authentication(UserLoginInfo loginInfo) { bool isAuthenticated = new LdapServiceManager().isAuthenticated(loginInfo); lastRetry = getTimeCookie(); if (isAuthenticated && !isBanned(lastRetry)) { setEncryptedUsernameCookie(loginInfo.username); setEncryptedPasswordCookie(loginInfo.password); deleteBannedTimeCookie("time"); Session["authorized"] = true; Session["LoginRetryCount"] = 0; return(Json(new { success = true, location = "/Home/Index" })); } //WRONG PASSWORD, BACK TO LOGIN PAGE setTimeCookie(DateTime.Now); Session["message"] = "Yanlış kullanıcı adı ya da şifre"; Session["LoginRetryCount"] = (int?)Session["LoginRetryCount"] + 1 ?? 0; return(Json(new { success = false, remainingTryCount = GetRemaingTryCount(), isBanned = isBanned(lastRetry), availableTime = DateTime.Now.AddMinutes(30).ToString("yyyy/MM/dd-HH:MM:ss") })); }
private bool HasNoValidCookie() { bool isAuthenticated = false; var cookieUid = Request.Cookies.AllKeys.FirstOrDefault(x => x == "token1"); var cookiePid = Request.Cookies.AllKeys.FirstOrDefault(x => x == "token2"); //Elle Cookie Girildiğinde Kontrol if (cookiePid != null && cookieUid != null) { UserLoginInfo nonValidCookie = new UserLoginInfo(); nonValidCookie.username = new StringEncryptor().Decrypt(Request.Cookies["token1"].Value); nonValidCookie.password = new StringEncryptor().Decrypt(Request.Cookies["token2"].Value); isAuthenticated = new LdapServiceManager().isAuthenticated(nonValidCookie); } //---KONTROL BİTTİ---- if (cookieUid != null && cookiePid != null && isAuthenticated) { return(false); } return(true); }