예제 #1
0
 public void Login()
 {
     try
     {
         var authenticated = false;
         var connectionId  = CookieManager.GetConnectionId(_client);
         var username      = _packet.Args[0].ToString();
         var password      = _packet.Args[1].ToString();
         var loginInfo     = AuthUtils.AuthWindows(username, password);
         if (!loginInfo.LoggedIn)
         {
             throw new Exception(loginInfo.Message);
         }
         if (loginInfo.LoggedIn && !loginInfo.IsAdmin)
         {
             throw new Exception($"The account {username} is not a Windows administrator.");
         }
         authenticated = loginInfo.LoggedIn && loginInfo.IsAdmin;
         AuthClient authClient;
         UlteriusApiServer.AllClients.TryGetValue(connectionId, out authClient);
         if (authClient != null)
         {
             if (authClient.Authenticated)
             {
                 throw new Exception("A login session is already active for this Ulterius ID");
             }
             authClient.Authenticated = authenticated;
             UlteriusApiServer.AllClients[connectionId] = authClient;
         }
         if (authenticated)
         {
             AppEnvironment.Setting("LastUsername", username);
         }
         var authenticationData = new
         {
             authenticated,
             message = authenticated ? "Login was successful" : "Login was unsuccessful"
         };
         _builder.WriteMessage(authenticationData);
     }
     catch (Exception ex)
     {
         var authenticationData = new
         {
             authenticated = false,
             message       = ex.Message
         };
         _builder.WriteMessage(authenticationData);
     }
 }
        private bool Login(string password)
        {
            if (string.IsNullOrEmpty(password))
            {
                return(false);
            }
            if (string.IsNullOrEmpty(AppEnvironment.Setting("LastUsername")))
            {
                return(false);
            }
            var response = AuthUtils.AuthWindows(AppEnvironment.Setting("LastUsername"), password);

            return(response.IsAdmin && response.LoggedIn);
        }