/// <summary> /// Validates the username and password, and logs in. /// </summary> public async Task <SimpleResult> LoginAsync(string username, string password, bool rememberMe) { bool userIsValid = false; int userID = 0; int roleID = 0; string errMsg; string friendlyError; // check user by server try { userIsValid = clientAccessor.ScadaClient .ValidateUser(username, password, out userID, out roleID, out errMsg); friendlyError = errMsg; } catch (Exception ex) { errMsg = ex.Message; friendlyError = WebPhrases.ClientError; } // check user by plugins UserLoginArgs userLoginArgs = new() { Username = username, UserID = userID, RoleID = roleID, SessionID = httpContext.Session.Id, RemoteIP = httpContext.Connection.RemoteIpAddress?.ToString(), UserIsValid = userIsValid, ErrorMessage = errMsg, FriendlyError = friendlyError }; webContext.PluginHolder.OnUserLogin(userLoginArgs); // show login result if (userLoginArgs.UserIsValid) { LoginOptions loginOptions = webContext.AppConfig.LoginOptions; await DoLoginAsync(username, userID, roleID, loginOptions.AllowRememberMe&& rememberMe, loginOptions.RememberMeExpires); webContext.Log.WriteAction(Locale.IsRussian ? "Пользователь {0} вошёл в систему {0}, IP {1}" : "User {0} is logged in, IP {1}", username, userLoginArgs.RemoteIP); return(SimpleResult.Success()); } else { webContext.Log.WriteError(Locale.IsRussian ? "Неудачная попытка входа в систему пользователя {0}, IP {1}: {2}" : "Unsuccessful login attempt for user {0}, IP {1}: {2}", username, userLoginArgs.RemoteIP, userLoginArgs.ErrorMessage); return(SimpleResult.Fail(userLoginArgs.FriendlyError)); } }