Esempio n. 1
0
        public Response<dynamic> Authenticate(string password)
        {
            JsonWebClient web;
            AuthPackage authPackage;
            Response<Guid> result;
            string authUrl;
            Response<dynamic> resp;
            Common.Encryption enc;
            Common.Encryption.Package encPackage;

            enc = new Common.Encryption();
            enc.Key = Globals.ThisAddIn.Settings.Key;
            enc.GenerateIV();
            encPackage = new Common.Encryption.Package()
            {
                Input = password.Trim()
            };
            encPackage = enc.Encrypt(encPackage);

            authPackage = new AuthPackage()
            {
                AppName = "OpenLawOffice.Word",
                MachineId = Globals.ThisAddIn.Settings.MachineId,
                Username = Globals.ThisAddIn.Settings.Username.Trim(),
                IV = enc.IV,
                Password = encPackage.Output
            };

            if (string.IsNullOrEmpty(Globals.ThisAddIn.Settings.ServerUrl))
                throw new InvalidOperationException("Invalid Server URL");
            if (string.IsNullOrEmpty(Globals.ThisAddIn.Settings.Username))
                throw new InvalidOperationException("Invalid Username");

            web = new JsonWebClient();
            authUrl = Globals.ThisAddIn.Settings.ServerUrl + "JsonInterface/Authenticate";

            if (Globals.ThisAddIn.CanLog)
                LogManager.GetCurrentClassLogger().Debug("Sending authentication request to: " + authUrl);

            result = web.Request<AuthPackage, Guid>(authUrl, "POST", authPackage);
            resp = new Common.Net.Response<dynamic>();

            if (result == null)
            {
                string error;

                if (Globals.ThisAddIn.CanLog)
                    LogManager.GetCurrentClassLogger().Info("Login error for user: "******"User logged in successfully: " + authPackage.Username);
                    else
                        LogManager.GetCurrentClassLogger().Debug("Failed login for: " + authPackage.Username);
                }
            }

            return resp;
        }
Esempio n. 2
0
        public Response <dynamic> Authenticate(string password)
        {
            JsonWebClient      web;
            AuthPackage        authPackage;
            Response <Guid>    result;
            string             authUrl;
            Response <dynamic> resp;

            Common.Encryption         enc;
            Common.Encryption.Package encPackage;

            enc     = new Common.Encryption();
            enc.Key = Globals.ThisAddIn.Settings.Key;
            enc.GenerateIV();
            encPackage = new Common.Encryption.Package()
            {
                Input = password.Trim()
            };
            encPackage = enc.Encrypt(encPackage);

            authPackage = new AuthPackage()
            {
                AppName   = "OpenLawOffice.Word",
                MachineId = Globals.ThisAddIn.Settings.MachineId,
                Username  = Globals.ThisAddIn.Settings.Username.Trim(),
                IV        = enc.IV,
                Password  = encPackage.Output
            };

            if (string.IsNullOrEmpty(Globals.ThisAddIn.Settings.ServerUrl))
            {
                throw new InvalidOperationException("Invalid Server URL");
            }
            if (string.IsNullOrEmpty(Globals.ThisAddIn.Settings.Username))
            {
                throw new InvalidOperationException("Invalid Username");
            }

            web     = new JsonWebClient();
            authUrl = Globals.ThisAddIn.Settings.ServerUrl + "JsonInterface/Authenticate";

            if (Globals.ThisAddIn.CanLog)
            {
                LogManager.GetCurrentClassLogger().Debug("Sending authentication request to: " + authUrl);
            }

            result = web.Request <AuthPackage, Guid>(authUrl, "POST", authPackage);
            resp   = new Common.Net.Response <dynamic>();

            if (result == null)
            {
                string error;

                if (Globals.ThisAddIn.CanLog)
                {
                    LogManager.GetCurrentClassLogger().Info("Login error for user: "******"User logged in successfully: " + authPackage.Username);
                    }
                    else
                    {
                        LogManager.GetCurrentClassLogger().Debug("Failed login for: " + authPackage.Username);
                    }
                }
            }

            return(resp);
        }