Example #1
0
        /// <summary>
        /// Изменение пароля пользователя
        /// </summary>
        /// <param name="ARequest">Запрос в формате JSON-объекта</param>
        public void ChangePassword(string ARequest)
        {
            Thread th = new Thread(() =>
            {
                try
                {
                    ServerLib.JTypes.Client.RequestUserPasswordChangeClass Request = JsonConvert.DeserializeObject <ServerLib.JTypes.Client.RequestUserPasswordChangeClass>(ARequest);
                    DatabaseParameterValuesClass Params = new DatabaseParameterValuesClass();
                    Params.CreateParameterValue("Token", Request.Token);
                    Params.CreateParameterValue("UserId", Request.ID);
                    Params.CreateParameterValue("Password", Request.Password);
                    Params.CreateParameterValue("State");
                    Params.CreateParameterValue("ErrorText");
                    UserSession.Project.Database.Execute("UserPasswordChange", ref Params);
                    if (Params.ParameterByName("State").AsString == "ok")
                    {
                        UserSession.OutputQueueAddObject(new ServerLib.JTypes.Server.ResponseUserPasswordChangeClass
                        {
                            ID = Request.ID
                        });
                    }
                    else
                    {
                        UserSession.OutputQueueAddObject(new ServerLib.JTypes.Server.ResponseExceptionClass(Commands.user_password_change, ErrorCodes.DatabaseError, Params.ParameterByName("ErrorText").AsString));
                    }
                }
                catch (Exception ex)
                {
                    UserSession.OutputQueueAddObject(new ServerLib.JTypes.Server.ResponseExceptionClass(Commands.user_password_change, ErrorCodes.FatalError, ex.Message));
                }
            });

            th.Start();
        }
Example #2
0
        /// <summary>
        /// Обработчик добавления должности пользователя
        /// </summary>
        /// <param name="ARequest">Запрос в формате JSON-объекта</param>
        public override bool AddProcessing(string ARequest)
        {
            bool ProcessingSuccess = false;

            try
            {
                ServerLib.JTypes.Client.RequestJobAddClass Request = JsonConvert.DeserializeObject <ServerLib.JTypes.Client.RequestJobAddClass>(ARequest);
                DatabaseParameterValuesClass Params = new DatabaseParameterValuesClass();
                Params.CreateParameterValue("Token", Request.Token);
                Params.CreateParameterValue("JobName", Request.Name.Trim());
                Params.CreateParameterValue("NewId");
                Params.CreateParameterValue("State");
                Params.CreateParameterValue("ErrorText");
                UserSession.Project.Database.Execute("JobAdd", ref Params);
                if (Params.ParameterByName("State").AsString == "ok")
                {
                    UserSession.OutputQueueAddObject(new ServerLib.JTypes.Server.ResponseJobAddClass
                    {
                        ID   = Params.ParameterByName("NewId").AsInt64,
                        Name = Request.Name.Trim()
                    });
                    ProcessingSuccess = true;
                }
                else
                {
                    UserSession.OutputQueueAddObject(new ServerLib.JTypes.Server.ResponseExceptionClass(Commands.job_add, ErrorCodes.DatabaseError, Params.ParameterByName("ErrorText").AsString));
                }
            }
            catch (Exception ex)
            {
                UserSession.OutputQueueAddObject(new ServerLib.JTypes.Server.ResponseExceptionClass(Commands.job_add, ErrorCodes.FatalError, ex.Message));
            }
            return(ProcessingSuccess);
        }
        /// <summary>
        /// Обработчик удаления роли пользователя
        /// </summary>
        /// <param name="ARequest">Запрос в формате JSON-объекта</param>
        public override bool DeleteProcessing(string ARequest)
        {
            bool ProcessingSuccess = false;

            try
            {
                ServerLib.JTypes.Client.RequestUserRoleDeleteClass Request = JsonConvert.DeserializeObject <ServerLib.JTypes.Client.RequestUserRoleDeleteClass>(ARequest);
                DatabaseParameterValuesClass Params = new DatabaseParameterValuesClass();
                Params.CreateParameterValue("Token", Request.Token);
                Params.CreateParameterValue("RoleID", Request.UserRoleID);
                Params.CreateParameterValue("State");
                Params.CreateParameterValue("ErrorText");
                UserSession.Project.Database.Execute("UsersRolesDelete", ref Params);
                if (Params.ParameterByName("State").AsString == "ok")
                {
                    UserSession.OutputQueueAddObject(new ServerLib.JTypes.Server.ResponseUserRoleDeleteClass());
                    ProcessingSuccess = true;
                }
                else
                {
                    UserSession.OutputQueueAddObject(new ServerLib.JTypes.Server.ResponseExceptionClass(Commands.users_roles_delete, ErrorCodes.DatabaseError, Params.ParameterByName("ErrorText").AsString));
                }
            }
            catch (Exception ex)
            {
                UserSession.OutputQueueAddObject(new ServerLib.JTypes.Server.ResponseExceptionClass(Commands.users_roles_delete, ErrorCodes.FatalError, ex.Message));
            }
            return(ProcessingSuccess);
        }
Example #4
0
        /// <summary>
        /// Обработчик добавления пользователя
        /// </summary>
        /// <param name="ARequest">Запрос в формате JSON-объекта</param>
        public override bool AddProcessing(string ARequest)
        {
            bool ProcessingSuccess = false;

            try
            {
                ServerLib.JTypes.Client.RequestUserAddClass Request = JsonConvert.DeserializeObject <ServerLib.JTypes.Client.RequestUserAddClass>(ARequest);
                DatabaseParameterValuesClass Params = new DatabaseParameterValuesClass();
                Params.CreateParameterValue("Token", Request.Token);
                Params.CreateParameterValue("Login", Request.Login);
                Params.CreateParameterValue("Password", Request.Password);
                Params.CreateParameterValue("InFirstName", Request.FirstName);
                Params.CreateParameterValue("InLastName", Request.LastName);
                Params.CreateParameterValue("InMidleName", Request.MidleName);
                Params.CreateParameterValue("InActive", Request.Active);
                Params.CreateParameterValue("JobId", Request.JobID);
                Params.CreateParameterValue("AccessUserId");
                Params.CreateParameterValue("Job");
                Params.CreateParameterValue("State");
                Params.CreateParameterValue("ErrorText");
                UserSession.Project.Database.Execute("UserAdd", ref Params);
                if (Params.ParameterByName("State").AsString == "ok")
                {
                    UserSession.OutputQueueAddObject(new ServerLib.JTypes.Server.ResponseUserAddClass
                    {
                        ID        = Params.ParameterByName("AccessUserId").AsInt64,
                        Login     = Request.Login,
                        FirstName = Request.FirstName,
                        LastName  = Request.LastName,
                        MidleName = Request.MidleName,
                        Active    = Request.Active,
                        JobID     = Request.JobID,
                        JobName   = Params.ParameterByName("Job").AsString
                    });
                    ProcessingSuccess = true;
                }
                else
                {
                    UserSession.OutputQueueAddObject(new ServerLib.JTypes.Server.ResponseExceptionClass(Commands.user_add, ErrorCodes.DatabaseError, Params.ParameterByName("ErrorText").AsString));
                }
            }
            catch (Exception ex)
            {
                UserSession.OutputQueueAddObject(new ServerLib.JTypes.Server.ResponseExceptionClass(Commands.user_add, ErrorCodes.FatalError, ex.Message));
            }
            return(ProcessingSuccess);
        }
        /// <summary>
        /// Удаление сессии пользователя
        /// </summary>
        /// <param name="ASession">Идентификатор сессии</param>
        /// <returns></returns>
        public object KillSession(string ASession)
        {
            DatabaseParameterValuesClass Param = new DatabaseParameterValuesClass();

            Param.CreateParameterValue("Token", ASession);
            Param.CreateParameterValue("State");
            UserSession.Project.Database.Execute("Logout", ref Param);
            UserSession.Login.ID = 0;
            ServerLib.JTypes.Server.ResponseLogoutClass Response = new ServerLib.JTypes.Server.ResponseLogoutClass();
            if (Param.ParameterByName("State").AsString == "ok")
            {
                Response.State = ServerLib.JTypes.Enums.ResponseState.ok;
            }
            else
            {
                Response.State     = ServerLib.JTypes.Enums.ResponseState.error;
                Response.ErrorText = "Active session not found";
            }
            return(Response);
        }
 /// <summary>
 /// Аутентификация пользователя
 /// </summary>
 /// <param name="ARequest">Запрос в формате JSON-объекта</param>
 public void Login(string ARequest)
 {
     try
     {
         ServerLib.JTypes.Client.RequestLoginClass Request = JsonConvert.DeserializeObject <ServerLib.JTypes.Client.RequestLoginClass>(ARequest);
         Token  = null;
         ID     = 0;
         Active = 0;
         State  = ServerLib.JTypes.Enums.ResponseState.error;
         DatabaseParameterValuesClass Params = new DatabaseParameterValuesClass();
         Params.CreateParameterValue("WebSocketID", UserSession.WebSocketSessionID);
         Params.CreateParameterValue("Login", Request.UserName);
         Params.CreateParameterValue("Password", Request.Password);
         Params.CreateParameterValue("AccessToken");
         Params.CreateParameterValue("AccessUserId");
         Params.CreateParameterValue("Active");
         UserSession.Project.Database.Execute("Login", ref Params);
         long _UserId = Params.ParameterByName("AccessUserId").AsInt64;
         int  _Active = Params.ParameterByName("Active").AsInt32;
         if (_UserId > 0)
         {
             Token  = _Active == 1 ? Params.ParameterByName("AccessToken").AsString: null;
             Active = _Active == 1 ? ServerLib.JTypes.Enums.UserActive.activated : ServerLib.JTypes.Enums.UserActive.blocked;
             ID     = Active == ServerLib.JTypes.Enums.UserActive.activated ? _UserId : 0;
             State  = ServerLib.JTypes.Enums.ResponseState.ok;
             UserSession.OutputQueueAddObject(this);
             UserSession.UserInformation.SendData();
         }
         else
         {
             UserSession.OutputQueueAddObject(new ServerLib.JTypes.Server.ResponseExceptionClass(ServerLib.JTypes.Enums.Commands.login, ServerLib.JTypes.Enums.ErrorCodes.IncorrectLoginOrPassword));
         }
     }
     catch (Exception ex)
     {
         UserSession.OutputQueueAddObject(new ServerLib.JTypes.Server.ResponseExceptionClass(ServerLib.JTypes.Enums.Commands.login, ServerLib.JTypes.Enums.ErrorCodes.FatalError, ex.Message));
     }
 }
        /// <summary>
        /// Обновление данных
        /// </summary>
        public override void RefreshData()
        {
            ServerLib.JTypes.Server.ResponseRolesObjectsClass OutputList = new ServerLib.JTypes.Server.ResponseRolesObjectsClass();
            DatabaseParameterValuesClass Params = new DatabaseParameterValuesClass();

            Params.CreateParameterValue("Token", UserSession.Login.Token);
            DatabaseTableClass ReadTable = new DatabaseTableClass
            {
                Table = (System.Data.DataTable)UserSession.Project.Database.Execute("RolesObjects", ref Params)
            };

            foreach (System.Data.DataRow row in ReadTable.Table.Rows)
            {
                ServerLib.JTypes.Server.ResponseRoleObjectClass Item = new ServerLib.JTypes.Server.ResponseRoleObjectClass
                {
                    ID              = ReadTable.AsInt64(row, "ID"),
                    RoleID          = ReadTable.AsInt64(row, "ROLE_ID"),
                    ObjectID        = ReadTable.AsInt64(row, "OBJECT_ID"),
                    OperationRead   = ReadTable.AsInt64(row, "OPERATION_READ") == 1,
                    OperationAdd    = ReadTable.AsInt64(row, "OPERATION_ADD") == 1,
                    OperationEdit   = ReadTable.AsInt64(row, "OPERATION_EDIT") == 1,
                    OperationDelete = ReadTable.AsInt64(row, "OPERATION_DELETE") == 1
                };

                if (ReadCollection.TryGetValue(Item.ID, out ServerLib.JTypes.Server.ResponseRoleObjectClass ExistItem))
                {
                    if (ExistItem.Hash != Item.Hash)
                    {
                        Item.Command = ItemCommands.edit;
                        ReadCollection.TryUpdate(Item.ID, Item, ExistItem);
                        OutputList.Items.Add(Item);
                    }
                }
                else
                {
                    Item.Command = ItemCommands.add;
                    ReadCollection.TryAdd(Item.ID, Item);
                    OutputList.Items.Add(Item);
                }
            }

            foreach (System.Collections.Generic.KeyValuePair <long, ServerLib.JTypes.Server.ResponseRoleObjectClass> Item in ReadCollection)
            {
                bool IsExist = false;

                foreach (System.Data.DataRow row in ReadTable.Table.Rows)
                {
                    if (Item.Key == ReadTable.AsInt64(row, "ID"))
                    {
                        IsExist = true;
                        break;
                    }
                }

                if (!IsExist)
                {
                    Item.Value.Command = ItemCommands.delete;
                    OutputList.Items.Add(Item.Value);
                    ReadCollection.TryRemove(Item.Value.ID, out ServerLib.JTypes.Server.ResponseRoleObjectClass DeletingItem);
                }
            }

            if (OutputList.Items.Count > 0)
            {
                UserSession.OutputQueueAddObject(OutputList);
            }
        }
Example #8
0
        /// <summary>
        /// Поток обновления данных
        /// </summary>
        /// <param name="state"></param>
        private void RefreshDataProcessing(object state)
        {
            if (UserSession.IsAuthenticated && !IsRunning)
            {
                Thread th = new Thread(() =>
                {
                    try
                    {
                        IsRunning = true;
                        DatabaseParameterValuesClass Param = new DatabaseParameterValuesClass();
                        Param.CreateParameterValue("Token", UserSession.Login.Token);
                        Param.CreateParameterValue("UserId", UserSession.Login.ID);
                        Param.CreateParameterValue("FirstName");
                        Param.CreateParameterValue("LastName");
                        Param.CreateParameterValue("MidleName");
                        Param.CreateParameterValue("Job");
                        Param.CreateParameterValue("Active");
                        Param.CreateParameterValue("State");
                        Param.CreateParameterValue("ErrorText");
                        UserSession.Project.Database.Execute("UserInformation", ref Param);
                        if (Param.ParameterByName("State").AsString == "ok")
                        {
                            DatabaseParameterValuesClass Params = new DatabaseParameterValuesClass();
                            Params.CreateParameterValue("Token", UserSession.Login.Token);
                            DatabaseTableClass ReadTable = new DatabaseTableClass
                            {
                                Table = (System.Data.DataTable)UserSession.Project.Database.Execute("UserPermissions", ref Params)
                            };
                            Permissions.Clear();
                            foreach (System.Data.DataRow row in ReadTable.Table.Rows)
                            {
                                Permissions.Add(new ServerLib.JTypes.Server.ResponseUserPermissionClass
                                {
                                    ObjectName = ReadTable.AsString(row, "OBJECT"),
                                    Operation  = (ServerLib.JTypes.Enums.ObjectOperations)ReadTable.AsInt32(row, "OPERATION")
                                });
                            }

                            string OldMessage = JsonConvert.SerializeObject(this);
                            FirstName         = Param.ParameterByName("FirstName").AsString;
                            LastName          = Param.ParameterByName("LastName").AsString;
                            MidleName         = Param.ParameterByName("MidleName").AsString;
                            JobName           = Param.ParameterByName("Job").AsString;
                            Active            = Param.ParameterByName("Active").AsInt32 == 1 ? ServerLib.JTypes.Enums.UserActive.activated : ServerLib.JTypes.Enums.UserActive.blocked;
                            State             = ServerLib.JTypes.Enums.ResponseState.ok;
                            if (JsonConvert.SerializeObject(this) != OldMessage)
                            {
                                UserSession.OutputQueueAddObject(this);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        UserSession.Project.Log.Error(string.Format("UserInformation.RefreshDataProcessing {0}", ex.Message));
                    }
                    finally
                    {
                        IsRunning = false;
                    }
                });
                th.Start();
            }
            RefreshDataTimer.Change(5000, Timeout.Infinite);
        }
Example #9
0
        /// <summary>
        /// Обновление данных
        /// </summary>
        public override void RefreshData()
        {
            ServerLib.JTypes.Server.ResponseUsersClass OutputList = new ServerLib.JTypes.Server.ResponseUsersClass();
            DatabaseParameterValuesClass Params = new DatabaseParameterValuesClass();

            Params.CreateParameterValue("Token", UserSession.Login.Token);
            DatabaseTableClass ReadTable = new DatabaseTableClass
            {
                Table = (System.Data.DataTable)UserSession.Project.Database.Execute("Users", ref Params)
            };

            foreach (System.Data.DataRow row in ReadTable.Table.Rows)
            {
                ServerLib.JTypes.Server.ResponseUserClass Item = new ServerLib.JTypes.Server.ResponseUserClass
                {
                    ID        = ReadTable.AsInt64(row, "ID"),
                    Login     = ReadTable.AsString(row, "LOGIN"),
                    FirstName = ReadTable.AsString(row, "FIRST_NAME"),
                    LastName  = ReadTable.AsString(row, "LAST_NAME"),
                    MidleName = ReadTable.AsString(row, "MIDLE_NAME"),
                    JobID     = ReadTable.AsInt64(row, "POSITION_ID"),
                    JobName   = ReadTable.AsString(row, "POSITION"),
                    Active    = (UserActive)ReadTable.AsInt32(row, "ACTIVE")
                };

                if (ReadCollection.TryGetValue(Item.ID, out ServerLib.JTypes.Server.ResponseUserClass ExistItem))
                {
                    if (ExistItem.Hash != Item.Hash)
                    {
                        Item.Command = ItemCommands.edit;
                        ReadCollection.TryUpdate(Item.ID, Item, ExistItem);
                        OutputList.Items.Add(Item);
                    }
                }
                else
                {
                    Item.Command = ItemCommands.add;
                    ReadCollection.TryAdd(Item.ID, Item);
                    OutputList.Items.Add(Item);
                }
            }

            foreach (System.Collections.Generic.KeyValuePair <long, ServerLib.JTypes.Server.ResponseUserClass> Item in ReadCollection)
            {
                bool IsExist = false;

                foreach (System.Data.DataRow row in ReadTable.Table.Rows)
                {
                    if (Item.Value.ID == ReadTable.AsInt64(row, "ID"))
                    {
                        IsExist = true;
                        break;
                    }
                }

                if (!IsExist)
                {
                    Item.Value.Command = ItemCommands.delete;
                    OutputList.Items.Add(Item.Value);
                    ReadCollection.TryRemove(Item.Value.ID, out ServerLib.JTypes.Server.ResponseUserClass DeletingUser);
                }
            }

            if (OutputList.Items.Count > 0)
            {
                UserSession.OutputQueueAddObject(OutputList);
            }
        }
Example #10
0
        /// <summary>
        /// Обновление данных
        /// </summary>
        public override void RefreshData()
        {
            ServerLib.JTypes.Server.ResponseJobsClass OutputList = new ServerLib.JTypes.Server.ResponseJobsClass();
            DatabaseParameterValuesClass Params = new DatabaseParameterValuesClass();

            Params.CreateParameterValue("Token", UserSession.Login.Token);
            DatabaseTableClass ReadTable = new DatabaseTableClass
            {
                Table = (System.Data.DataTable)UserSession.Project.Database.Execute("Jobs", ref Params)
            };

            foreach (System.Data.DataRow row in ReadTable.Table.Rows)
            {
                ServerLib.JTypes.Server.ResponseJobClass Item = new ServerLib.JTypes.Server.ResponseJobClass
                {
                    ID   = ReadTable.AsInt64(row, "ID"),
                    Name = ReadTable.AsString(row, "JOB_NAME")
                };

                if (JobsCollection.TryGetValue(Item.ID, out ServerLib.JTypes.Server.ResponseJobClass ExistItem))
                {
                    if (ExistItem.Hash != Item.Hash)
                    {
                        Item.Command = ItemCommands.edit;
                        JobsCollection.TryUpdate(Item.ID, Item, ExistItem);
                        OutputList.Jobs.Add(Item);
                    }
                }
                else
                {
                    Item.Command = ItemCommands.add;
                    JobsCollection.TryAdd(Item.ID, Item);
                    OutputList.Jobs.Add(Item);
                }
            }

            foreach (System.Collections.Generic.KeyValuePair <long, ServerLib.JTypes.Server.ResponseJobClass> Item in JobsCollection)
            {
                bool IsExist = false;

                foreach (System.Data.DataRow row in ReadTable.Table.Rows)
                {
                    if (Item.Value.ID == ReadTable.AsInt64(row, "ID"))
                    {
                        IsExist = true;
                        break;
                    }
                }

                if (!IsExist)
                {
                    Item.Value.Command = ItemCommands.delete;
                    OutputList.Jobs.Add(Item.Value);
                    JobsCollection.TryRemove(Item.Value.ID, out ServerLib.JTypes.Server.ResponseJobClass DeletingItem);
                }
            }

            if (OutputList.Jobs.Count > 0)
            {
                UserSession.OutputQueueAddObject(OutputList);
            }
        }