示例#1
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));
        }
示例#2
0
 public Server()
 {
     InitializeComponent();
     config = ConfigContainer.GetConfig();
     checkBoxAllowRegister.Checked      = config.AllowRegistrationRequests;
     checkBoxAllowStudRegister.Checked  = config.AllowStudentsRegistration;
     checkBoxAllowTeachRegister.Checked = config.AllowTeacherRegistration;
     checkBoxAllowSubjectAdd.Checked    = config.AllowSubjectsAdding;
     checkBoxAllowGroupAdd.Checked      = config.AllowGroupsAdding;
 }
示例#3
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);
            }
        }
示例#4
0
 private void Menu_FormClosed(object sender, FormClosedEventArgs e)
 {
     ConfigContainer.Save();
 }