public bool CanConnect(SecurityUserDto user, string password) { if (user == null || password == null) return false; if (!Session.IsOpen) throw new SessionNotOpenedException(); var foundUser = Session.Get<User>(user.Id); if (user == null) return false; var userPwd = foundUser.Password ?? string.Empty; return (password == userPwd); }
/// <summary> /// Determines whether the specified role is granted to execute the specified task. /// </summary> /// <param name="to">The level of authorisatio needed to execute the role.</param> /// <param name="assignedRole">The assigned role.</param> /// <returns> /// <c>true</c> if the specified assigned role is granted; otherwise, <c>false</c>. /// </returns> public bool IsGranted(string to, SecurityUserDto user) { if (to == To.Everyone) return true; else if (user == null) return false; else if (user.AssignedRole == null && !user.IsSuperAdmin) { return false; } else if (user.IsSuperAdmin) { return true; } else { return (from task in user.AssignedRole.Tasks where task.RefName.ToLower() == to select task).ToList().Count() >0; } }
/// <summary> /// Updates the specified user. /// </summary> /// <param name="user">The user.</param> public void Update(SecurityUserDto user) { new Updator(this.Session).Update(user); }
/// <summary> /// Removes the specified user from the repository. /// </summary> /// <param name="user">The user.</param> public void Remove(SecurityUserDto user) { var aptEntities = (from a in this.Session.Query<Appointment>() where a.User.Id == user.Id select a); foreach (var item in aptEntities) { this.Session.Delete(item); } var userEntities = (from u in this.Session.Query<User>() where u.Id == user.Id select u); foreach (var item in userEntities) { this.Session.Delete(item); } }
/// <summary> /// Determines whether this specified usr is super admin. /// </summary> /// <param name="user">The user.</param> /// <returns> /// <c>true</c> if the specified useris super admin; otherwise, <c>false</c>. /// </returns> public bool IsSuperAdmin(SecurityUserDto user) { var superadmin = (from u in this.Session.Query<User>() where u.Id == user.Id select u).FirstOrDefault(); if (superadmin == null) { throw new BusinessLogicException("The database is in a wrong state: there is no super admin.", Messages.Ex_NoSuperAdmin); } return superadmin.IsSuperAdmin; }
/// <summary> /// Gets the user from the specified security user. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> public UserDto GetUser(SecurityUserDto user) { var entity = (from u in this.Session.Query<User>() where u.Id == user.Id select u).Single(); return Mapper.Map<User, UserDto>(entity); }
public long Create(SecurityUserDto item, string password) { return new Creator(this.Session).Create(item, password); }
public void UpdatePassword(SecurityUserDto user, string password) { new Updator(this.Session).Update(user, password); }
public UserDto LoadUser(SecurityUserDto user) { var fullUser = this.Session.Get<User>(user.Id); if (fullUser == null) return null; var result = Mapper.Map<User, UserDto>(fullUser); return result; }
private void RefreshDataContext(SecurityUserDto user) { this.Dispatcher.Invoke((Action)delegate { if (this.DataContext != null && this.DataContext is MainWindowViewModel) { (this.DataContext as MainWindowViewModel).ConnectedUser = user; } else { throw new WrongDataContextException(); } }); this.OnNewUserConnected(); }
public DoorKeeper(SecurityUserDto user) { this.user = user; }
/// <summary> /// Creates the specified user. /// </summary> /// <param name="user">The user.</param> /// <param name="password">The password.</param> public long Create(SecurityUserDto item, string password) { Assert.IsNotNull(item, "item"); if (string.IsNullOrEmpty(password)) throw new EmptyPasswordException(); var found = (from p in this.Session.Query<User>() where p.Id == item.Id || (p.FirstName == item.FirstName && p.LastName == item.LastName) select p).ToList().Count() > 0; if (found) throw new ExistingItemException(); var entity = Mapper.Map<SecurityUserDto, User>(item); entity.Password = password; if (entity.IsDefault) this.RemoveDefaultUser(); if (this.IsFirstUser()) { entity.IsSuperAdmin = true; } item.Id = (long)this.Session.Save(entity); return item.Id; }