public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { using (var context = new DbMifEF()) { List <User> users = context.Users.Where(u => u.UserEmail == model.Email).ToList(); if (users.Count > 0) { if (users[0].UserPass == model.Password.GetHashCode().ToString()) { Session["isLogIn"] = true; Session["userName"] = users[0].UserEmail; Session["userID"] = users[0].UserID; return(RedirectToAction("Index", "Home")); } else { ViewBag.LoginError = "Не верный пароль."; return(View()); } } else { ViewBag.LoginError = "Не верный email."; return(View()); } } } else { return(View()); } }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { using (var context = new DbMifEF()) { List <User> users = context.Users.Where(u => u.UserEmail == model.Email).ToList(); if (users.Count > 0) { ViewBag.AlreadyUsed = "Пользователь с таким адресом уже зарегистрирован."; return(View()); } else { User newUser = new User(); newUser.RoleID = 1; newUser.UserEmail = model.Email; newUser.UserPass = model.Password.GetHashCode().ToString(); context.Users.Add(newUser); context.SaveChanges(); TempData["registerSuccess"] = "Регистрация прошла успешно."; } } return(RedirectToAction("Index", "Home")); } else { return(View()); } }
public ActionResult Index() { using (var context = new DbMifEF()) { SongsModel model = new SongsModel(); model.Songs = context.Songs.ToList(); WriteToLog(); return(View(model)); } }
public ActionResult GetSong(int id = 0) { using (var context = new DbMifEF()) { TextOrAccordLineList model = new TextOrAccordLineList(); model.List = new List <TextOrAccord>(); Song song = null; if (id != 0) { song = context.Songs.Where(s => s.SongID == id).First(); if (song != null) { string path = Path.Combine(Server.MapPath(song.PathToText)); path = path.Replace("\\Home", ""); if (System.IO.File.Exists(path)) { const int BufferSize = 128; using (var fileStream = System.IO.File.OpenRead(path)) using (var streamReader = new StreamReader(fileStream, Encoding.UTF8, true, BufferSize)) { string line; while ((line = streamReader.ReadLine()) != null) { TextOrAccord textOrAcc = new TextOrAccord(); if (line.Length > 0) { if (line[0] == '@') { line = line.Remove(0, 1); textOrAcc.IsText = false; } else { textOrAcc.IsText = true; } } textOrAcc.Str = line; model.List.Add(textOrAcc); } } } } } return(PartialView(model)); } }
public ActionResult AboutUser() { if (Session["userID"] != null) { using (var context = new DbMifEF()) { int id; if (Int32.TryParse(Session["userID"].ToString(), out id)) { var user = context.Users.Where(u => u.UserID == id).First(); LoginModel model = new LoginModel { Email = user.UserEmail }; return(View(model)); } } } return(RedirectToAction("Index", "Home")); }
public ActionResult ChangePassword(ChangePasswordModel model) { if (Session["userID"] != null) { using (var context = new DbMifEF()) { int id; if (Int32.TryParse(Session["userID"].ToString(), out id)) { var user = context.Users.Where(u => u.UserID == id).First(); if (model.OldPassword.GetHashCode().ToString() == user.UserPass) { user.UserPass = model.Password.GetHashCode().ToString(); context.SaveChanges(); TempData["passwordChange"] = "Пароль успешно изменен."; return(RedirectToAction("Index", "Home")); } else { ViewBag.ChangeError = "Не верный старый пароль."; return(View()); } } else { ViewBag.ChangeError = "Не удалось изменить пароль."; return(View()); } } } else { ViewBag.ChangeError = "Не удалось изменить пароль."; return(View()); } }