Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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);
                 });
     }
 }
Exemplo n.º 5
0
 private bool IsUserEditor(Identity identity)
 {
     return IsUserPrivileged(identity, 30);
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 7
0
 public void LogOff()
 {
     _identity = null;
     Current = null;
 }
Exemplo n.º 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)));
 }
Exemplo n.º 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);
 }
Exemplo n.º 10
0
 public UpdateUserResult UpdateUser(Identity identity, User user)
 {
     if (NotValid())
         return UpdateUserResult.Fail;
     return _project.UsersRunner.UpdateUser(identity, user);
 }
Exemplo n.º 11
0
 public bool SetPassword(Identity identity, long id, string password)
 {
     if (NotValid())
         return false;
     return _project.UsersRunner.SetPassword(identity, id, password);
 }
Exemplo n.º 12
0
 public void UpdateUser(Identity identity, User user, Action<UpdateUserResult> callback)
 {
     _queue.Enqueue(service => callback(service.UpdateUser(identity, user)));
 }
Exemplo n.º 13
0
 public void SetPassword(Identity identity, long userId, string password, Action<bool> callback)
 {
     _queue.Enqueue(service => callback(service.SetPassword(identity, userId, password)));
 }
Exemplo n.º 14
0
 public void InsertUser(Identity identity, User user, Action<InsertUserResult> callback)
 {
     _queue.Enqueue(service => callback(service.InsertUser(identity, user)));
 }
Exemplo n.º 15
0
 public void GetUsers(Identity identity, long[] ids, Action<User[]> callback)
 {
     _queue.Enqueue(service => callback(service.GetUsersByIds(identity, ids)));
 }
Exemplo n.º 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;
 }
Exemplo n.º 17
0
 private bool IsUserViewer(Identity identity)
 {
     return IsUserPrivileged(identity, 31);
 }
Exemplo n.º 18
0
 public User[] GetUsersByIds(Identity identity, long[] ids)
 {
     if (NotValid())
         return null;
     return _project.UsersRunner.GetUsers(identity, ids);
 }
Exemplo n.º 19
0
 public InsertUserResult InsertUser(Identity identity, User user)
 {
     if (NotValid())
         return InsertUserResult.Fail;
     return _project.UsersRunner.InsertUser(identity, user);
 }
Exemplo n.º 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);
         });
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
     }
 }