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); } }
public User[] GetUsers(Identity identity, long[] ids) { if (!IsUserViewer(identity)) return new User[0]; using (var connection = _connectionFactory.Create()) { return _repository.Get(connection, ids); } }
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; } }
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); }); } }
private bool IsUserEditor(Identity identity) { return IsUserPrivileged(identity, 30); }
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); } }
public void LogOff() { _identity = null; Current = null; }
public void GetUsers(Identity identity, CriteriaType criteriaType, string name, int count, Action<User[]> callback) { _queue.Enqueue(service => callback(service.GetUsers(identity, criteriaType, name, count))); }
public User[] GetUsers(Identity identity, CriteriaType criteriaType, string name, int count) { if (NotValid()) return null; return _project.UsersRunner.GetUsers(identity, criteriaType, name, count); }
public UpdateUserResult UpdateUser(Identity identity, User user) { if (NotValid()) return UpdateUserResult.Fail; return _project.UsersRunner.UpdateUser(identity, user); }
public bool SetPassword(Identity identity, long id, string password) { if (NotValid()) return false; return _project.UsersRunner.SetPassword(identity, id, password); }
public void UpdateUser(Identity identity, User user, Action<UpdateUserResult> callback) { _queue.Enqueue(service => callback(service.UpdateUser(identity, user))); }
public void SetPassword(Identity identity, long userId, string password, Action<bool> callback) { _queue.Enqueue(service => callback(service.SetPassword(identity, userId, password))); }
public void InsertUser(Identity identity, User user, Action<InsertUserResult> callback) { _queue.Enqueue(service => callback(service.InsertUser(identity, user))); }
public void GetUsers(Identity identity, long[] ids, Action<User[]> callback) { _queue.Enqueue(service => callback(service.GetUsersByIds(identity, ids))); }
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; }
private bool IsUserViewer(Identity identity) { return IsUserPrivileged(identity, 31); }
public User[] GetUsersByIds(Identity identity, long[] ids) { if (NotValid()) return null; return _project.UsersRunner.GetUsers(identity, ids); }
public InsertUserResult InsertUser(Identity identity, User user) { if (NotValid()) return InsertUserResult.Fail; return _project.UsersRunner.InsertUser(identity, user); }
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); }); }
public InsertUserResult InsertUser(Identity identity, User user) { if (!IsUserEditor(identity)) return InsertUserResult.Fail; using (var connection = _connectionFactory.Create()) { return _repository.InsertUser(connection, user); } }
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); } }