Ejemplo n.º 1
0
        public Response<dynamic> CloseSession()
        {
            JsonWebClient web;
            Response<bool> result;
            string url;
            Response<dynamic> resp;
            AuthPackage authPackage;

            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");

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

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

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

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

            if (result == null)
            {
                if (Globals.ThisAddIn.CanLog)
                    LogManager.GetCurrentClassLogger().Info("Error closing session.");

                resp.RequestReceived = result.RequestReceived;
                resp.ResponseSent = result.ResponseSent;
                resp.Successful = result.Successful;
                resp.Package = new
                {
                    Error = web.GetResult<bool>().Error,
                    Server = Globals.ThisAddIn.Settings.ServerUrl.Trim()
                };
            }
            else
            {
                resp.RequestReceived = result.RequestReceived;
                resp.ResponseSent = result.ResponseSent;
                resp.Successful = result.Successful;
                resp.Package = null;

                _isConnected = false;
                Token = null;

                if (Globals.ThisAddIn.CanLog)
                    LogManager.GetCurrentClassLogger().Debug("Session closed successfully.");
            }

            return resp;
        }
        public ActionResult List(string contactFilter, string titleFilter, string caseNumberFilter,
            int? courtTypeFilter, int? courtGeographicalJurisdictionFilter, bool activeFilter = true)
        {
            Guid? token;
            Common.Net.Response<List<Common.Models.Matters.Matter>> response
                = new Common.Net.Response<List<Common.Models.Matters.Matter>>();

            response.RequestReceived = DateTime.Now;

            token = Request.GetToken();
            if (token == null || !token.HasValue)
            {
                response.Successful = false;
                response.Error = "Invalid Auth Token";
                response.ResponseSent = DateTime.Now;
                return Json(response, JsonRequestBehavior.AllowGet);
            }

            using (Data.Transaction trans = Data.Transaction.Create(true))
            {
                try
                {
                    response.Package = Data.Matters.Matter.List(trans, activeFilter, contactFilter, titleFilter,
                        caseNumberFilter, courtTypeFilter, courtGeographicalJurisdictionFilter);
                    response.Successful = true;
                }
                catch
                {
                    trans.Rollback();
                    response.Successful = false;
                    response.Package = null;
                    response.Error = "Unexpected server error.";
                }
            }

            response.ResponseSent = DateTime.Now;
            return Json(response, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 3
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: " + authPackage.Username);

                resp.Successful = false;
                try
                {
                    error = web.GetResult<Guid>().Error;
                }
                catch
                {
                    error = null;
                }

                resp.Package = new
                {
                    Error = error,
                    Username = authPackage.Username,
                    Server = Globals.ThisAddIn.Settings.ServerUrl.Trim()
                };

                Token = null;
            }
            else
            {
                resp.RequestReceived = result.RequestReceived;
                resp.ResponseSent = result.ResponseSent;
                resp.Successful = result.Successful;
                if (string.IsNullOrEmpty(result.Error))
                {
                    resp.Package = new
                    {
                        Token = result.Package,
                        Username = authPackage.Username,
                        Server = Globals.ThisAddIn.Settings.ServerUrl.Trim()
                    };
                }
                else
                {
                    resp.Package = new
                    {
                        Error = result.Error,
                        Token = result.Package,
                        Username = authPackage.Username,
                        Server = Globals.ThisAddIn.Settings.ServerUrl.Trim()
                    };
                }

                _isConnected = true;

                if (result.Package != null && result.Package != Guid.Empty)
                    Token = result.Package;

                if (Globals.ThisAddIn.CanLog)
                {
                    if (resp.Successful)
                        LogManager.GetCurrentClassLogger().Debug("User logged in successfully: " + authPackage.Username);
                    else
                        LogManager.GetCurrentClassLogger().Debug("Failed login for: " + authPackage.Username);
                }
            }

            return resp;
        }
        public ActionResult Authenticate()
        {
            dynamic profile;
            Common.Net.Request<Common.Net.AuthPackage> request;
            Common.Net.Response<Guid> response = new Common.Net.Response<Guid>();

            request = Request.InputStream.JsonDeserialize<Common.Net.Request<Common.Net.AuthPackage>>();

            response.RequestReceived = DateTime.Now;

            Common.Models.Account.Users user = Data.Account.Users.Get(request.Package.Username);
            profile = ProfileBase.Create(user.Username);

            // decrypt password
            Common.Encryption enc = new Common.Encryption();
            Common.Encryption.Package package;
            enc.IV = request.Package.IV;
            if (profile != null && profile.ExternalAppKey != null
                && !string.IsNullOrEmpty(profile.ExternalAppKey))
                enc.Key = profile.ExternalAppKey;
            else
            {
                response.Successful = false;
                response.Package = Guid.Empty;
            }
            package = enc.Decrypt(new Common.Encryption.Package()
                {
                    Input = request.Package.Password
                });
            if (string.IsNullOrEmpty(package.Output))
            {
                response.Successful = false;
                response.Package = Guid.Empty;
            }
            request.Package.Password = package.Output;

            string hashFromDb = Security.ClientHashPassword(user.Password);
            string hashFromWeb = Security.ClientHashPassword(request.Package.Password);
            
            if (MembershipService.ValidateUser(request.Package.Username, request.Package.Password))
            {
                Common.Models.External.ExternalSession session =
                    Data.External.ExternalSession.Get(request.Package.AppName, request.Package.MachineId, request.Package.Username);
                user = Data.Account.Users.Get(request.Package.Username);

                if (session == null)
                { // create
                    session = Data.External.ExternalSession.Create(new Common.Models.External.ExternalSession()
                    {
                        MachineId = request.Package.MachineId,
                        User = user,
                        AppName = request.Package.AppName
                    });
                }
                else
                { // update
                    session = Data.External.ExternalSession.Update(new Common.Models.External.ExternalSession()
                    {
                        Id = session.Id,
                        MachineId = request.Package.MachineId,
                        User = user,
                        AppName = request.Package.AppName
                    });
                }

                response.Successful = true;
                response.Package = session.Id.Value;
            }
            else
            {
                response.Successful = false;
                response.Package = Guid.Empty;
                response.Error = "Invalid security credentials.";
            }

            response.ResponseSent = DateTime.Now;

            return Json(response, JsonRequestBehavior.AllowGet);
        }
        public ActionResult GetFormDataForMatter(Guid id)
        {
            Guid token;
            Common.Net.Response<List<Common.Models.Forms.FormFieldMatter>> response
                = new Common.Net.Response<List<Common.Models.Forms.FormFieldMatter>>();

            response.RequestReceived = DateTime.Now;

            if ((token = GetToken(Request)) == Guid.Empty)
            {
                response.Successful = false;
                response.Error = "Invalid Token";
                response.ResponseSent = DateTime.Now;
                return Json(response, JsonRequestBehavior.AllowGet);
            }

            if (!VerifyToken(token))
            {
                response.Successful = false;
                response.Error = "Invalid Token";
                response.ResponseSent = DateTime.Now;
                return Json(response, JsonRequestBehavior.AllowGet);
            }

            response.Successful = true;
            response.Package = Data.Forms.FormFieldMatter.ListForMatter(id);
            response.ResponseSent = DateTime.Now;
            return Json(response, JsonRequestBehavior.AllowGet);
        }
        public ActionResult Matters(string contactFilter, string titleFilter, string caseNumberFilter, string jurisdictionFilter, bool activeFilter = true)
        {
            Guid token;
            Common.Net.Response<List<Common.Models.Matters.Matter>> response 
                = new Common.Net.Response<List<Common.Models.Matters.Matter>>();

            response.RequestReceived = DateTime.Now;

            if ((token = GetToken(Request)) == Guid.Empty)
            {
                response.Successful = false;
                response.Error = "Invalid Token";
                response.ResponseSent = DateTime.Now;
                return Json(response, JsonRequestBehavior.AllowGet);
            }

            if (!VerifyToken(token))
            {
                response.Successful = false;
                response.Error = "Invalid Token";
                response.ResponseSent = DateTime.Now;
                return Json(response, JsonRequestBehavior.AllowGet);
            }

            response.Successful = true;
            response.Package = Data.Matters.Matter.List(activeFilter, contactFilter, titleFilter, caseNumberFilter, jurisdictionFilter);
            response.ResponseSent = DateTime.Now;
            return Json(response, JsonRequestBehavior.AllowGet);
        }
        public ActionResult CloseSession()
        {
            Guid token;
            Common.Net.Request<Common.Net.AuthPackage> request;
            Common.Models.External.ExternalSession session;
            Common.Net.Response<bool> response = new Common.Net.Response<bool>();
            
            request = Request.InputStream.JsonDeserialize<Common.Net.Request<Common.Net.AuthPackage>>();
            
            response.RequestReceived = DateTime.Now;

            if ((token = GetToken(Request)) == Guid.Empty)
            {
                response.Successful = false;
                response.Error = "Invalid Token";
                response.Package = false;
                return Json(response, JsonRequestBehavior.AllowGet);
            }

            if (!VerifyToken(token))
            {
                response.Successful = false;
                response.Error = "Invalid Token";
                response.Package = false;
                return Json(response, JsonRequestBehavior.AllowGet);
            }

            // Close the session here
            session = Data.External.ExternalSession.Get(request.Package.AppName, request.Package.MachineId, request.Package.Username);
            session = Data.External.ExternalSession.Delete(session);

            response.Successful = true;
            response.ResponseSent = DateTime.Now;
            response.Package = true;
            return Json(response, JsonRequestBehavior.AllowGet);
        }
        public ActionResult ListFormsForMatter(Guid matterId)
        {
            Guid token;
            Common.Net.Response<List<Common.Models.Forms.Form>> response
                = new Common.Net.Response<List<Common.Models.Forms.Form>>();

            response.RequestReceived = DateTime.Now;

            if ((token = GetToken(Request)) == Guid.Empty)
            {
                response.Successful = false;
                response.Error = "Invalid Token";
                response.ResponseSent = DateTime.Now;
                return Json(response, JsonRequestBehavior.AllowGet);
            }

            using (Data.Transaction trans = Data.Transaction.Create(true))
            {
                try
                {
                    if (!VerifyToken(trans, token))
                    {
                        response.Successful = false;
                        response.Error = "Invalid Token";
                        response.ResponseSent = DateTime.Now;
                        return Json(response, JsonRequestBehavior.AllowGet);
                    }

                    response.Successful = true;
                    response.Package = Data.Forms.Form.ListForMatter(matterId);
                }
                catch
                {
                    trans.Rollback();
                    response.Successful = false;
                    response.Package = null;
                    response.Error = "Unexpected server error.";
                }
            }

            response.ResponseSent = DateTime.Now;
            return Json(response, JsonRequestBehavior.AllowGet);
        }
        public ActionResult CloseSession()
        {
            Guid token;
            Common.Net.Request<Common.Net.AuthPackage> request;
            Common.Models.External.ExternalSession session;
            Common.Net.Response<bool> response = new Common.Net.Response<bool>();
            
            request = Request.InputStream.JsonDeserialize<Common.Net.Request<Common.Net.AuthPackage>>();
            
            response.RequestReceived = DateTime.Now;

            if ((token = GetToken(Request)) == Guid.Empty)
            {
                response.Successful = false;
                response.Error = "Invalid Token";
                response.Package = false;
                return Json(response, JsonRequestBehavior.AllowGet);
            }

            using (Data.Transaction trans = Data.Transaction.Create(true))
            {
                try
                {
                    if (!VerifyToken(trans, token))
                    {
                        response.Successful = false;
                        response.Error = "Invalid Token";
                        response.Package = false;
                        return Json(response, JsonRequestBehavior.AllowGet);
                    }

                    // Close the session here
                    session = Data.External.ExternalSession.Get(trans, request.Package.AppName, request.Package.MachineId, request.Package.Username);
                    session = Data.External.ExternalSession.Delete(trans, session);

                    trans.Commit();

                    response.Successful = true;
                    response.Package = true;
                }
                catch
                {
                    trans.Rollback();
                    response.Successful = false;
                    response.Package = false;
                    response.Error = "Unexpected server error.";
                }
            }

            response.ResponseSent = DateTime.Now;

            return Json(response, JsonRequestBehavior.AllowGet);
        }