Пример #1
0
        public LInst.User CreateNewUser(Person personInstance,
                                        string userName,
                                        string password)
        {
            LInst.User output = new LInst.User();
            output.FullName       = "";
            output.UserName       = userName;
            output.HashedPassword = CalculateHash(password, userName);
            using (LInstContext context = _contextFactory.CreateDbContext(new string[] { }))
            {
                output.Person = context.People.First(per => per.ID == personInstance.ID);
                foreach (UserRole role in context.UserRoles)
                {
                    UserRoleMapping tempMapping = new UserRoleMapping();
                    tempMapping.UserRole   = role;
                    tempMapping.IsSelected = false;

                    output.RoleMappings.Add(tempMapping);
                }
                context.Users.Add(output);
                context.SaveChanges();
            }

            return(output);
        }
Пример #2
0
 public void Execute(LInstContext context)
 {
     LInst.User authenticated = context.Users.Include(usr => usr.RoleMappings).ThenInclude(urm => urm.UserRole)
                                .AsNoTracking()
                                .FirstOrDefault(usr => usr.UserName == _toAuthenticate.UserName &&
                                                usr.HashedPassword == _toAuthenticate.HashedPassword);
     _callBack(authenticated);
 }
Пример #3
0
 /// <summary>
 /// Base Constructor for the command
 /// </summary>
 /// <param name="userToAuthenticate">A mocked user instance containing the username and password to authenticate</param>
 /// <param name="callBack">The method that will be called when the authentication is done, returns a connected authenticated user entry
 /// corresponding to the provided data, or null if none exists</param>
 public AuthenticateUserCommand(LInst.User userToAuthenticate,
                                Action <LInst.User> callBack)
 {
     _toAuthenticate = userToAuthenticate;
     _callBack       = callBack;
 }