Пример #1
0
        public void RemoveUser(User userToRemove)
        {
            User performingUser = SystemContext.SystemContext.CurrentUser;

            if (performingUser.PrivilegeLevel >= userToRemove.PrivilegeLevel)
            {
                throw new AccessDeniedException(string.Format(MSG_PRIVILEGE_VIOLATED, performingUser.Name, userToRemove.PrivilegeLevel));
            }

            SystemUserDAO.GetInstance().Delete(User2SystemUserTO.Map(userToRemove));
        }
Пример #2
0
        public override void ShowCustomMessage()
        {
            var user = new User();

            user.Name           = Helpers.PageHelper.GetValidInput <string>("Imie:");
            user.Password       = Helpers.PageHelper.GetValidInput <string>("Hasło:");
            user.PhoneNumber    = Helpers.PageHelper.GetValidInput <string>("Nr telefonu:");
            user.PrivilegeLevel = DefaultPrivileges.User;

            var userTO = User2SystemUserTO.Map(user);

            SystemUserDAO.GetInstance().Insert(userTO);
        }
Пример #3
0
        public void RegisterUser(User registeredUser)
        {
            User registratingUser = SystemContext.SystemContext.CurrentUser;

            if (registratingUser.PrivilegeLevel >= registeredUser.PrivilegeLevel)
            {
                throw new AccessDeniedException(string.Format(MSG_PRIVILEGE_VIOLATED, registratingUser.Name, registeredUser.PrivilegeLevel));
            }

            var registeredUserTO = User2SystemUserTO.Map(registeredUser);

            SystemUserDAO.GetInstance().Insert(registeredUserTO);
        }
Пример #4
0
        public void PromoteUser(User userToPromote, int newPrivilegeLevel)
        {
            User performingUser = SystemContext.SystemContext.CurrentUser;

            if (performingUser.PrivilegeLevel >= newPrivilegeLevel)
            {
                throw new AccessDeniedException(string.Format(MSG_PRIVILEGE_VIOLATED, performingUser.Name, newPrivilegeLevel - 1));
            }

            if (userToPromote.PrivilegeLevel >= newPrivilegeLevel)
            {
                throw new ArgumentOutOfRangeException("newPrivilegeLevel", string.Format("New privilege level ({0}) should be greater than current ({1})", newPrivilegeLevel, userToPromote.PrivilegeLevel));
            }

            userToPromote.PrivilegeLevel = newPrivilegeLevel;
            SystemUserDAO.GetInstance().Update(User2SystemUserTO.Map(userToPromote));
        }
        public static void SignOut(string login)
        {
            if (login == null)
            {
                throw new ArgumentNullException(nameof(login));
            }

            var userTO = SystemUserDAO.GetInstance().GetByName(login);

            if (userTO == null)
            {
                throw new ArgumentException(string.Format("unknown login: {0}", login));
            }

            var user = SystemUserTO2UserMapper.Map(userTO);

            SystemContext.LogoutUser(user);
        }
        public static void SignIn(string login, string password)
        {
            var userTO = SystemUserDAO.GetInstance().GetByName(login);

            if (userTO == null)
            {
                throw new AccessDeniedException("Niewłaściwy login");
            }

            var user = SystemUserTO2UserMapper.Map(userTO);

            if (user.Password != password)
            {
                throw new AccessDeniedException("Niewłaściwe hasło");
            }

            SystemContext.LoginUser(user, password);
        }
        private void _NotifyUsers()
        {
            var msg = SystemContext.SystemContext.SMSService.NewMessage();

            msg.Message = "Alarm został włączony!";
            msg.Title   = "Alarm";

            var recipients = SystemUserDAO.GetInstance().GetAll().Select(SystemUserTO2UserMapper.Map).Select(user => new SMSRecipient {
                PhoneNumber = user.PhoneNumber
            });

            foreach (var recipient in recipients)
            {
                msg.Recipients.Add(recipient);
            }

            SystemContext.SystemContext.SMSService.SendMessage(msg);
        }
Пример #8
0
 public IEnumerable <User> GetRegisteredUsers()
 {
     return(SystemUserTO2UserMapper.Map(SystemUserDAO.GetInstance().GetAll()));
 }