//============================================================ public JsonResult ExistEmail(string Email) { try { Data.User tmpUser = RepUsers.GetAllWhere(u => u.Email == Email).First(); } catch (Exception) { return(Json(true, JsonRequestBehavior.AllowGet)); } return(Json("Адрес занят", JsonRequestBehavior.AllowGet)); }
public static bool ExecuteIn(Data.LoginUser logUser, Implementation.UsersRepository RepUsers, HttpContextBase MyHttpContext) { try { string HPas = GetHash(logUser.Password); try { Data.User tmpUser = RepUsers.GetAllWhere(u => u.Email == logUser.Email && u.Password == HPas && u.IsConfirm == true).First(); HttpCookie cookie = new HttpCookie("Test Site"); cookie["id"] = tmpUser.Id.ToString(); cookie["password"] = HPas; MyHttpContext.Response.Cookies.Add(cookie); return(true); } catch (Exception ex) { return(false); } } catch (Exception ex) { //MyHttpContext.Response.Redirect("/Test/auth/?er=1"); return(false); } }
public static bool IsOut(HttpContextBase MyHttpContext, Implementation.UsersRepository RepUser) { bool result = true; try { string id = MyHttpContext.Request.Cookies["Test Site"].Values["id"]; string password = MyHttpContext.Request.Cookies["Test Site"].Values["password"]; if (id == "" || password == "") { return(true); } try { Data.User tmpUser = RepUser.GetAllWhere(u => u.Id.ToString() == id && u.Password == password).First(); if (tmpUser != null) { result = false; } } catch (Exception ex) { return(true); } } catch (Exception ex) { } return(result); }
public static void Confirm(string id, Implementation.UsersRepository RepUsers) { var Users = RepUsers.GetAllWhere(u => u.IsConfirm == false && u.Password == id); if (Users != null) { foreach (Data.User item in Users) // всех пользователей с этим хешем подтверждаем o_O )))) { item.IsConfirm = true; } RepUsers.SaveChange(); } }
public static bool IsExist(string email, Implementation.UsersRepository RepUsers) { IEnumerable <Data.User> ListUsers = RepUsers.GetAllWhere(); if (ListUsers.Count() == 0) { return(false); } try { Data.User tmpUser = ListUsers.Single(u => u.Email == email); } catch (Exception ex) { return(false); } return(true); }
public static void GetNewPass(string email, Implementation.UsersRepository RepUsers, HttpContextBase MyHttpContext) { char[] data = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'A', 'B', 'C', 'D', 'E', 'F', 'G', '0', '1', '2', '3', '4', '5', '6','7','8', '9' }; Random rnd = new Random(); StringBuilder SB = new StringBuilder(); for (int i = 0; i < 6; i++) { int index = rnd.Next(data.Count() - 1); SB.Append(data[index]); } string NewPass = SB.ToString(); //пароль string HPass = GetHash(NewPass); // хеш пароля HttpCookie cookie = new HttpCookie("Test Site"); cookie["email"] = email; MyHttpContext.Response.Cookies.Add(cookie); try { SendMail(new Data.LoginUser { Email = email, Password = NewPass }, WebConfigurationManager.AppSettings.GetValues("SubjectMailNewPass")[0], WebConfigurationManager.AppSettings.GetValues("BodyMailNewPass")[0] + NewPass); Data.User tmpUser = RepUsers.GetAllWhere(u => u.Email == email).First(); tmpUser.Password = HPass; RepUsers.SaveChange(); } catch (Exception ex) { throw new Exception(ex.Message, ex); } }