public ActionResult LogOn(string login, string password) { using (var session = MvcApplication.Store.OpenSession()) { var account = session.Query <Account>().SingleOrDefault(x => x.Login == login); if (account != null && account.PasswordHash == PasswordHasher.Get(password)) { SingIn(account); return(RedirectToAction("List", "Task")); } ViewBag.Error = "Неверный логин или пароль"; return(View()); } }
/* * http://localhost:48850/Developer/CreateAccount?name=Василий&surname=Иванов&login=Министр&role=Ministr&password=123 * http://localhost:48850/Developer/CreateAccount?name=Людмила&surname=Сидирова&login=Секретарь&role=Referent&password=123 */ public string CreateAccount(string name, string surname, string login, AccountRole role, string password) { using (var session = MvcApplication.Store.OpenSession()) { var account = new Account { Name = name, Surname = surname, Login = login, Role = role, PasswordHash = PasswordHasher.Get(password) }; session.Store(account); session.SaveChanges(); return("Пользователь создан"); } }
public IActionResult Login(string email, string password) { bool isRight = true; if (email == null) { isRight = false; ModelState.AddModelError("errors", "ელ-ფოსტის ველი ცარიელია"); } if (password == null) { isRight = false; ModelState.AddModelError("errors", "პაროლის ველი ცარიელია"); } if (!isRight) { return(View()); } var user = usersRepository.getAll() .Where(x => x.Email == email & x.Password == PasswordHasher.Get(password)) .FirstOrDefault(); if (user == null) { ModelState.AddModelError("errors", "პაროლი ან ელფოსტა არასწორია"); return(View()); } if (user.UserRoleId == 1) { HttpContext.Session.Set <User>("login-user", user); return(RedirectToAction("Index", "User")); } HttpContext.Session.Set <User>("login-admin", user); return(RedirectToAction("Index", "Genre")); }
public IActionResult Index(CreateUserViewModel vm) { if (!ModelState.IsValid) { return(View()); } var users = userRepository.getAll(); bool AddUser = true; if (users.FirstOrDefault(x => x.FullName == vm.Fullname) != null) { ModelState.AddModelError("errors", "ასეთი სრული სახელი უკვე არსებობს"); AddUser = false; } if (users.FirstOrDefault(x => x.Email == vm.Email) != null) { AddUser = false; ModelState.AddModelError("errors", "ასეთი ფოსტა უკვე არსებობს"); } if (!AddUser) { return(View()); } User user = new User() { FullName = vm.Fullname, IsActive = 1, UserRoleId = 1, Password = PasswordHasher.Get(vm.Password), Email = vm.Email }; userRepository.Add(user); return(RedirectToAction("Welcome", "Register")); }