Ejemplo n.º 1
0
        //method for enabling and disabling alarms menu options
        private void AssignAlarmsMenuPrevilages(AccessLevelEnum accessLevel)
        {
            _logger.Info($"Assign enables for alarm management menu. Access level: {accessLevel.ToString()}.");

            _runtimeData.SetAlarmsMenuPrevilages(accessLevel);

            CanAlarmProfileManager          = _runtimeData.CanAlarmProfileManager;
            CanMessageReceiversManager      = _runtimeData.CanMessageReceiversManager;
            CanMessageReceiverGroupsManager = _runtimeData.CanMessageReceiverGroupsManager;
            CanAlarmManagement = _runtimeData.CanAlarmManagement;
        }
Ejemplo n.º 2
0
        //method for enabling and disabling settings menu options
        private void AssignSettingsMenuPrevilages(AccessLevelEnum accessLevel)
        {
            _logger.Info($"Assign enables for settings menu. Access level: {accessLevel.ToString()}.");

            _runtimeData.SetSettingsMenuPrevilages(accessLevel);

            CanAlarmsLanguageEdition = _runtimeData.CanAlarmsLanguageEdition;
            CanPLCconnectionSetup    = _runtimeData.CanPLCconnectionSetup;
            CanSMSdeviceConnection   = _runtimeData.CanSMSdeviceConnection;
            CanNLogParametrization   = _runtimeData.CanNLogParametrization;
        }
Ejemplo n.º 3
0
        public LoggedUserData GetUserData()
        {
            _logger.Info($"Method for getin user data in case of successfull login fored.");

            if (_loginSuccessful)
            {
                try
                {
                    //read all data from DB
                    UserDefinition userData = _realm.All <UserDefinition>().Single(x => x.UserName == _userName);

                    //convert access level from number to enum
                    AccesLevelConverter converter   = new AccesLevelConverter();
                    AccessLevelEnum     accessLevel = converter.GetAccesLevelEnum(userData.AccessLevel);

                    //pass to caller only necessary data
                    return(new LoggedUserData()
                    {
                        Identity = userData.Identity,
                        UserName = userData.UserName,
                        AccessLevel = accessLevel.ToString(),
                        AccessLevelEnum = accessLevel,
                        LogoutEnabled = userData.LogoutEnabled,
                        LogoutTime = userData.LogoutTime,
                        LangEditPrevilages = userData.LanguageEditorPrevilages,
                    });
                }
                catch (Exception ex)
                {
                    _logger.Error($"Error while obtaining user data from DB: {ex.Message}.");
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
        public bool ModifyUser(int userID, AccessLevelEnum newAccessLevel, bool logOff,
                               int logOffTimeout, int newPrevilages)
        {
            _logger.Info($"Method for modifying existing user in Db fired. User ID = {userID}, Access level = {newAccessLevel.ToString()}.");

            try
            {
                UserDefinition user = _realm.All <UserDefinition>().ToList().Single(x => x.Identity == userID);

                using (var trans = _realm.BeginWrite())
                {
                    user.AccessLevel              = GetAccessLevelInt(newAccessLevel);
                    user.LogoutEnabled            = logOff;
                    user.LogoutTime               = logOffTimeout;
                    user.LanguageEditorPrevilages = newPrevilages;
                    trans.Commit();
                }

                _logger.Info($"Modifying exisng user data in DB successfull.");

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error($"Error while trying to modify existing user data: {ex.Message}.");
                return(false);
            }
        }
        public bool AddNewUser(string userName, string password, AccessLevelEnum accessLevel,
                               bool logOff, int logOffTimeout, int langPrevillages)
        {
            _logger.Info($"Method for adding new user to DB fired. User name = {userName}, Access level = {accessLevel.ToString()}.");

            try
            {
                (string hashPass, byte[] salt) = EncryptPassword(password);

                _realm.Write(() =>
                {
                    _realm.Add(new UserDefinition()
                    {
                        Identity                 = GetNewID(),
                        UserName                 = userName,
                        Password                 = hashPass,
                        AccessLevel              = GetAccessLevelInt(accessLevel),
                        Salt                     = salt,
                        LogoutEnabled            = logOff,
                        LogoutTime               = logOffTimeout,
                        LanguageEditorPrevilages = langPrevillages,
                    });
                });

                _logger.Info($"Adding new user to DB successfull.");

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error($"Error while trying to add new user to DB: {ex.Message}.");
                return(false);
            }
        }