public string SignIn(AuthDataViewModel authData) { var adminEmail = _authData.GetAll().Select(x => x.Email).First(); var adminPass = _authData.GetAll().Select(x => x.Password).First(); string role = ""; if (authData.Email == adminEmail && authData.Password == adminPass) { CurrentUserId = _authData.GetAll().Select(x => x.EmployeeId).First(); role = "admin"; } else { foreach (var item in _authData.GetAll()) { if (item.Email == authData.Email && item.Password == authData.Password) { CurrentUserId = item.EmployeeId; role = "user"; break; } } } return(role); }
public IActionResult Registration(EmployeeViewModel employee, AuthDataViewModel authData) { if (ModelState.IsValid) { AuthenticationLogic.IsAuthenticated = true; _authentication.SetAuthentication(AuthenticationLogic.IsAuthenticated); _authentication.Register(employee, authData); return(RedirectToAction("Index", "Home")); } else { return(View("Registration")); } }
public void Register(EmployeeViewModel employee, AuthDataViewModel authData) { var newEmployee = _mapperEmployee.Map(employee); _employee.Insert(newEmployee); int id = _employee.GetAll().Select(x => x.EmployeeId).Last(); authData.Roles = "User"; authData.EmployeeId = id; CurrentUserId = id; var newAuthData = _mapperAuthData.Map(authData); _authData.Insert(newAuthData); }
public IActionResult Login(AuthDataViewModel data) { string role = _authentication.SignIn(data); if (role == "admin") { AuthenticationLogic.IsAuthenticated = true; _authentication.SetAuthentication(AuthenticationLogic.IsAuthenticated); return(RedirectToAction("Admin")); } else { if (role == "user") { AuthenticationLogic.IsAuthenticated = true; _authentication.SetAuthentication(AuthenticationLogic.IsAuthenticated); return(RedirectToAction("Index", "Home")); } ViewBag.ErrMsg = "invalid email or password"; return(View("Login")); } }