private void LogInB_Click(object sender, EventArgs e) { Library.ConfigurationManager.IsLocalConnection = localRB.Checked; Library.ConfigurationManager.FTPServerName = "192.168.1.35"; Library.ConfigurationManager.FTPServerUserName = "******"; Library.ConfigurationManager.FTPServerPassword = "******"; manager = new UsersManager(); user.Username = UserNameTB.Text.Trim(); user.Password = PasswordTB.Text; UsersManager.AuthenticationResult result = manager.Authenticate(user); if (result == UsersManager.AuthenticationResult.WRONG_PASSWORD || result == UsersManager.AuthenticationResult.WRONG_USER_NAME || result == UsersManager.AuthenticationResult.NO_USERS_IN_DB) { Error("اسم المستخدم أو كلمة المرور غير صحيحة"); } else if (result == UsersManager.AuthenticationResult.NOT_ACTIVE) { Error("حساب المستخدم غير مفعل"); } else if (result == UsersManager.AuthenticationResult.SUCCESSFUL) { Library.ConfigurationManager.currUser = user; Log(OperationsManager.LOGIN_LOGOUT, "قام المستخدم بتسجيل الدخول"); UserNameTB.Text = ""; PasswordTB.Text = ""; //Message("تم تسجيل الدخول بنجاح"); MainForm form = new MainForm(); form.Owner = this; Hide(); form.Show(); return; } else if (result == UsersManager.AuthenticationResult.CONNECTION_ERROR) { Error("تعذر الاتصال بقاعدة البيانات"); } else { Error("المستخدم لا يمتلك سماحيات للدخول"); } Library.ConfigurationManager.currUser = null; }
private void Intialize() { Library.ConfigurationManager.IsLocalConnection = false; Library.ConfigurationManager.DBServerName = serverIp; usersManager = new Library.BLL.UsersManager(); //Library.ConfigurationManager.IsLocalConnection = false; messageManager = new MessagesManager(); UserVO user = new UserVO(); //user.Username = userName; //user.Password = password; user.Username = "******"; user.Password = "******"; usersManager.Authenticate(user); Library.ConfigurationManager.currUser = user; AddUsers(); }
public async Task <IActionResult> LoginAsync(RestaurantLoginModelView authView) { TempData["RestaurantName"] = null; if (authView.Type == 0) { var user = UsersManager.Authenticate(authView.Username, authView.Password); if (user == null) { TempData["Message"] = null; TempData["ErrorMessage"] = "Login Error!!!.Try Again. Don't forget to Register first!!"; return(RedirectToAction("Login", "Account")); } var custId = CustomersManager.GetCustomerIdByUserId(user.UserId); var empId = EmployeesManager.GetEmployeeIdByUserId(user.UserId); var ownId = OwnersManager.GetOwnerIdByUserId(user.UserId); var claims = new List <Claim>() { new Claim(ClaimTypes.Name, user.Authentication.Username), new Claim("FullName", $"{user.FirstName} {user.LastName}"), new Claim("AuthID", user.AuthenticationId.ToString()), new Claim("UserID", user.UserId.ToString()), new Claim("CustomerID", custId.ToString()), new Claim("EmployeeID", empId.ToString()), new Claim("OwnerID", ownId.ToString()), }; var claimsIdentity = new ClaimsIdentity(claims, "Cookies"); await HttpContext.SignInAsync("Cookies", new ClaimsPrincipal(claimsIdentity)); } else { var user = RestaurantsManager.AuthenticateRestaurant(authView.Username, authView.Password, authView.RestaurantId); if (user.UserId <= 0) { TempData["Message"] = null; TempData["ErrorMessage"] = "Login Error!!!.Try Again.Don't forget to Register first!!"; return(RedirectToAction("Login", "Account")); } var custId = CustomersManager.GetCustomerIdByUserId(user.UserId); var empId = EmployeesManager.GetEmployeeIdByUserId(user.UserId); var ownId = OwnersManager.GetOwnerIdByUserId(user.UserId); var claims = new List <Claim>() { new Claim(ClaimTypes.Name, user.Authentication.Username), new Claim("FullName", $"{user.FirstName} {user.LastName}"), new Claim("AuthID", user.AuthenticationId.ToString()), new Claim("UserID", user.UserId.ToString()), new Claim("CustomerID", custId.ToString()), new Claim("EmployeeID", empId.ToString()), new Claim("OwnerID", ownId.ToString()), }; if (user.Authentication.AuthenticationMatrix.Count() > 0) { foreach (AuthenticationMatrix a in user.Authentication.AuthenticationMatrix) { if (a.RestaurantId == authView.RestaurantId) { claims.Add(new Claim("RestaurantID", a.RestaurantId.ToString())); claims.Add(new Claim(ClaimTypes.Role, a.Role)); TempData["RestaurantName"] = RestaurantsManager.GetRestaurantIdByNameByRestauranID(a.RestaurantId); } } } var claimsIdentity = new ClaimsIdentity(claims, "Cookies"); await HttpContext.SignInAsync("Cookies", new ClaimsPrincipal(claimsIdentity)); } if (TempData["returnUrl"] == null) { return(Redirect("~/Account/Profile")); } else { return(Redirect(TempData["returnUrl"].ToString())); } }