Esempio n. 1
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var loginData    = LoginData.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));
            var passwordHash = SequrityUtils.GetHash(loginData.Password);
            var result       = DBConnection.PrepareExecProcedureCommand("CheckLoginInfo", loginData.Login, passwordHash).ExecuteReader();

            if (result.Read())
            {
                client.UserId = result.GetInt32(0);
                client.Role   = (UserRoles)(result.GetInt32(4) - 1);
                var info = new AccountInfo(client.UserId, result.GetString(1), result.GetString(2), client.Role.Value, result.IsDBNull(5) ? null : result.GetString(5));

                client.UpdateExpiredTime();

                result.Close();
                error = CommandError.None;
                return(SequrityUtils.Encrypt(info.ToJson(), client.SecretDFKey));
            }
            else
            {
                result.Close();
                error = CommandError.BadLoginOrPassword;
                return(null);
            }
        }
Esempio n. 2
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            if (client.Role != UserRoles.Student)
            {
                error = CommandError.UserNotStudent;
                return(null);
            }

            if (client.CurrentPassTestId == null)
            {
                error = CommandError.NoCurrentTest;
                return(null);
            }

            var testResult = TestResult.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));

            var command = DBConnection.GetCommand();

            command.CommandText = "call AddTestResult(@param0, @param1, @param2, @param3, @param4)";
            command.Parameters.Add(new MySqlParameter("@param0", client.CurrentPassTestId));
            command.Parameters.Add(new MySqlParameter("@param1", client.UserId));
            command.Parameters.Add(new MySqlParameter("@param2", testResult.Mark));
            command.Parameters.Add(new MySqlParameter("@param3", testResult.PassingTime));
            command.Parameters.Add(new MySqlParameter("@param4", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(testResult.Answers))));
            command.ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
Esempio n. 3
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var config = ConfigContainer.GetConfig();

            if (client.Role == UserRoles.Teacher && !config.AllowSubjectsAdding)
            {
                error = CommandError.SubjectAddNotAllowed;
                return(null);
            }

            if (client.Role != UserRoles.Teacher && client.Role != UserRoles.Admin)
            {
                error = CommandError.NoPermissions;
                return(null);
            }

            var subjectName = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);

            var result = DBConnection.PrepareExecProcedureCommand("CheckSubject", subjectName).ExecuteReader();

            if (result.Read())
            {
                error = CommandError.SubjectExists;
                return(null);
            }
            result.Close();

            DBConnection.PrepareExecProcedureCommand("AddSubject", subjectName).ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
Esempio n. 4
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            client.UpdateExpiredTime();
            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
Esempio n. 5
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var sheetParams = TestSheetGetParams.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));

            if (client.Role != UserRoles.Teacher && sheetParams.isCreatorTests)
            {
                error = CommandError.NoPermissions;
                return(null);
            }
            bool   useNameFilter    = false;
            bool   useSubjectFilter = false;
            int    subject          = -1;
            string name             = "";

            if (sheetParams.Name != null && sheetParams.Name != "")
            {
                name          = sheetParams.Name;
                useNameFilter = true;
            }
            if (sheetParams.Subject != null && sheetParams.Subject > 0)
            {
                subject          = sheetParams.Subject.Value;
                useSubjectFilter = true;
            }

            MySqlDataReader result;

            if (sheetParams.isCreatorTests)
            {
                result = DBConnection.PrepareExecProcedureCommand("GetTestsCreatorSheet", client.UserId.ToString(), name, subject.ToString(), Convert.ToInt32(useNameFilter).ToString(), Convert.ToInt32(useSubjectFilter).ToString()).ExecuteReader();
            }
            else
            {
                result = DBConnection.PrepareExecProcedureCommand("GetTestsSheet", name, subject.ToString(), Convert.ToInt32(useNameFilter).ToString(), Convert.ToInt32(useSubjectFilter).ToString()).ExecuteReader();
            }

            var testList = new List <TestSheetItem>();

            while (result.Read())
            {
                testList.Add(
                    new TestSheetItem(
                        result.GetInt32(0),
                        result.GetString(1),
                        result.GetString(2),
                        result.GetDateTime(3),
                        result.GetInt32(4),
                        result.GetBoolean(5)
                        ));
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(testList), client.SecretDFKey));
        }
Esempio n. 6
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var config = ConfigContainer.GetConfig();

            if (client.Role == null && !config.AllowRegistrationRequests)
            {
                error = CommandError.SelfRegistrationNotAllowed;
                return(null);
            }
            if (client.Role == UserRoles.Teacher && !config.AllowStudentsRegistration)
            {
                error = CommandError.StudentRegistrationNotAllowed;
                return(null);
            }

            var registerData = RegisterData.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));
            var passwordHash = SequrityUtils.GetHash(registerData.Password);

            var DBReader = DBConnection.PrepareExecProcedureCommand("GetStudentGroup", registerData.Group).ExecuteReader();

            if (DBReader.Read())
            {
                var studentGroup = DBReader.GetInt32(0);
                DBReader.Close();

                DBReader = DBConnection.PrepareExecProcedureCommand("CheckUserLogin", registerData.Login).ExecuteReader();
                if (DBReader.Read())
                {
                    if (DBReader.GetInt32(0) > 0)
                    {
                        DBReader.Close();
                        error = CommandError.LoginExists;
                        return(null);
                    }
                }
                DBReader.Close();
                DBConnection.PrepareExecProcedureCommand("RegisterStudent", registerData.Firstname, registerData.Lastname, registerData.Login, passwordHash, studentGroup.ToString()).ExecuteNonQuery();

                error = CommandError.None;
                return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
            }
            else
            {
                DBReader.Close();
                error = CommandError.BadStudentGroup;
                return(null);
            }
        }
Esempio n. 7
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var result      = DBConnection.PrepareExecProcedureCommand("GetSubjectList").ExecuteReader();
            var subjectList = new Dictionary <int, string>();

            while (result.Read())
            {
                subjectList.Add(result.GetInt32(0), result.GetString(1));
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(subjectList), client.SecretDFKey));
        }
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var resultParams = ServerTestResultGetParams.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));


            bool     useSurnameFilter = false;
            bool     useDateFilter    = false;
            DateTime date             = DateTime.Now;
            string   surname          = "";

            if (resultParams.StudentSurname != null && resultParams.StudentSurname != "")
            {
                surname          = resultParams.StudentSurname;
                useSurnameFilter = true;
            }
            if (resultParams.PassDate != null)
            {
                date          = resultParams.PassDate.Value;
                useDateFilter = true;
            }

            var result = DBConnection.PrepareExecProcedureCommand("GetTestResultSheet", surname, date.ToString("yyyy-MM-dd"), Convert.ToInt32(useSurnameFilter).ToString(), Convert.ToInt32(useDateFilter).ToString()).ExecuteReader();

            var resultList = new List <ResultSheetItem>();

            while (result.Read())
            {
                var tmpDateTime = result.GetString(3).Split(':');
                var passingTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Convert.ToInt32(tmpDateTime[0]), Convert.ToInt32(tmpDateTime[1]), Convert.ToInt32(tmpDateTime[2]));
                resultList.Add(
                    new ResultSheetItem(
                        result.GetInt32(0),
                        result.GetString(1),
                        result.GetInt32(2),
                        passingTime,
                        result.GetDateTime(4)
                        ));
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(resultList), client.SecretDFKey));
        }
Esempio n. 9
0
        public byte[] Execute(out CommandError error)
        {
            if (requestData.UserToken == null)
            {
                error = CommandError.NullToken;
                return(null);
            }
            var client = ClientManager.GetClient(requestData.UserToken);

            if (client == null)
            {
                error = CommandError.ClientNotFound;
                return(null);
            }
            client.SecretDFKey = SequrityUtils.DiffieHellmanGetSecretKey(Encoding.UTF8.GetString(requestData.Data), client.GeneratedDFKey);
            error = CommandError.None;
            return(SequrityUtils.Encrypt("CONNECTION_STARTED", client.SecretDFKey));
        }
Esempio n. 10
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var    sheetParams      = UserSheetGetParams.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));
            bool   useSurnameFilter = false;
            bool   useRoleFilter    = false;
            int    role             = -1;
            string surname          = "";

            if (sheetParams.Surname != null && sheetParams.Surname != "")
            {
                surname          = sheetParams.Surname;
                useSurnameFilter = true;
            }
            if (sheetParams.Role != null && sheetParams.Role > 0)
            {
                role          = sheetParams.Role.Value;
                useRoleFilter = true;
            }

            var result   = DBConnection.PrepareExecProcedureCommand("GetUsersSheet", surname, role.ToString(), Convert.ToInt32(useSurnameFilter).ToString(), Convert.ToInt32(useRoleFilter).ToString()).ExecuteReader();
            var userList = new List <UserSheetItem>();

            while (result.Read())
            {
                userList.Add(
                    new UserSheetItem(
                        result.GetInt32(0),
                        result.GetString(1),
                        result.GetString(2),
                        result.GetString(3),
                        result.GetInt32(4),
                        result.IsDBNull(5) ? null : result.GetString(5)
                        ));
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(userList), client.SecretDFKey));
        }