Example #1
0
 public User[] GetUsers(Identity identity, CriteriaType criteriaType, string name, int count)
 {
     if (!IsUserViewer(identity))
         return new User[0];
     using (var connection = _connectionFactory.Create())
     {
         return _repository.Get(connection, criteriaType, name, count);
     }
 }
Example #2
0
 public User[] GetUsers(Identity identity, long[] ids)
 {
     if (!IsUserViewer(identity))
         return new User[0];
     using (var connection = _connectionFactory.Create())
     {
         return _repository.Get(connection, ids);
     }
 }
Example #3
0
        public int? GetPrivilege(Identity identity)
        {
            if (identity == null)
                return null;

            using (var connection = _connectionFactory.Create())
            {
                var pnp = _repository.GetPrivilegeAndNameAndPassword(connection, identity.UserId);
                if (pnp == null)
                    return null;

                if (!identity.Equals(new Identity(identity.UserId, pnp.Item2, pnp.Item3)))
                    return null;

                return pnp.Item1;
            }
        }
Example #4
0
 public void ChangePassword(string oldPassword, string newPassword, Action<bool> callback)
 {
     var user = Current;
     if (user == null)
     {
         callback(false);
     }
     else
     {
         var p = PasswordConverter.ConvertBack(newPassword);
         _usersRunTarget.ChangePassword(
             user.Name,
             PasswordConverter.ConvertBack(oldPassword),
             p,
             result =>
                 {
                     if (result)
                     {
                         _identity = new Identity(user.Id, user.Name, p);
                     }
                     callback(result);
                 });
     }
 }
Example #5
0
 private bool IsUserEditor(Identity identity)
 {
     return IsUserPrivileged(identity, 30);
 }
Example #6
0
 public bool SetPassword(Identity identity, long id, string password)
 {
     if (!IsUserEditor(identity))
         return false;
     using (var connection = _connectionFactory.Create())
     {
         return _repository.SetPassword(connection, id, password);
     }
 }
Example #7
0
 public void LogOff()
 {
     _identity = null;
     Current = null;
 }
Example #8
0
 public void GetUsers(Identity identity, CriteriaType criteriaType, string name, int count, Action<User[]> callback)
 {
     _queue.Enqueue(service => callback(service.GetUsers(identity, criteriaType, name, count)));
 }
Example #9
0
 public User[] GetUsers(Identity identity, CriteriaType criteriaType, string name, int count)
 {
     if (NotValid())
         return null;
     return _project.UsersRunner.GetUsers(identity, criteriaType, name, count);
 }
Example #10
0
 public UpdateUserResult UpdateUser(Identity identity, User user)
 {
     if (NotValid())
         return UpdateUserResult.Fail;
     return _project.UsersRunner.UpdateUser(identity, user);
 }
Example #11
0
 public bool SetPassword(Identity identity, long id, string password)
 {
     if (NotValid())
         return false;
     return _project.UsersRunner.SetPassword(identity, id, password);
 }
Example #12
0
 public void UpdateUser(Identity identity, User user, Action<UpdateUserResult> callback)
 {
     _queue.Enqueue(service => callback(service.UpdateUser(identity, user)));
 }
Example #13
0
 public void SetPassword(Identity identity, long userId, string password, Action<bool> callback)
 {
     _queue.Enqueue(service => callback(service.SetPassword(identity, userId, password)));
 }
Example #14
0
 public void InsertUser(Identity identity, User user, Action<InsertUserResult> callback)
 {
     _queue.Enqueue(service => callback(service.InsertUser(identity, user)));
 }
Example #15
0
 public void GetUsers(Identity identity, long[] ids, Action<User[]> callback)
 {
     _queue.Enqueue(service => callback(service.GetUsersByIds(identity, ids)));
 }
Example #16
0
 private bool IsUserPrivileged(Identity identity, int privilege)
 {
     var userPrivilege = GetPrivilege(identity);
     if (!userPrivilege.HasValue)
         return false;
     var userAdminPrivelege = Int32ToPrivilegedConverter.ConvertBack(privilege.ToString(CultureInfo.InvariantCulture));
     if (!userAdminPrivelege.HasValue)
         return false;
     return (userPrivilege.Value & userAdminPrivelege.Value) != 0;
 }
Example #17
0
 private bool IsUserViewer(Identity identity)
 {
     return IsUserPrivileged(identity, 31);
 }
Example #18
0
 public User[] GetUsersByIds(Identity identity, long[] ids)
 {
     if (NotValid())
         return null;
     return _project.UsersRunner.GetUsers(identity, ids);
 }
Example #19
0
 public InsertUserResult InsertUser(Identity identity, User user)
 {
     if (NotValid())
         return InsertUserResult.Fail;
     return _project.UsersRunner.InsertUser(identity, user);
 }
Example #20
0
 public void LogOn(string name, string password, Action<bool> callback)
 {
     var p = PasswordConverter.ConvertBack(password);
     _usersRunTarget.LogOn(name, p, user =>
         {
             if (user != null)
             {
                 Current = user;
                 _identity = new Identity(user.Id, user.Name, p);
             }
             callback.Invoke(user != null);
         });
 }
Example #21
0
 public InsertUserResult InsertUser(Identity identity, User user)
 {
     if (!IsUserEditor(identity))
         return InsertUserResult.Fail;
     using (var connection = _connectionFactory.Create())
     {
         return _repository.InsertUser(connection, user);
     }
 }
Example #22
0
 public void Acknowledge(AlarmSampleId[] alarms, Identity identity)
 {
     var privilege = _project.UsersRunner.GetPrivilege(identity);
     var alarmsToAcknowledge = (from a in alarms
                                let p = GetPrivilege(a.AlarmId)
                                where !p.HasValue || (privilege.HasValue && (p.Value & privilege.Value) != 0)
                                select a).ToArray();
     if (!alarmsToAcknowledge.Any())
         return;
     var userId = identity == null ? null : identity.UserId as long?;
     using (var connection = _connectionFactory.Create())
     {
         _repository.Update(connection, alarmsToAcknowledge, _timeService.UtcTime, userId);
     }
 }