Ejemplo n.º 1
0
        public IClientApplication GetClientApplication(string id)
        {
            Guard.NotNullOrEmpty(() => id, id);

            // Get the app
            IClientApplication app = Storage.Get(id);

            if (app == null)
            {
                throw LogicErrorThrower.ResourceNotFound();
            }

            return(app);
        }
Ejemplo n.º 2
0
        public IUserAccount GetUserAccount(string currentUsername, string id)
        {
            Guard.NotNull(() => currentUsername, currentUsername);
            Guard.NotNull(() => id, id);

            // Get the account
            IUserAccount account = Storage.Get(id);

            if (account == null)
            {
                throw LogicErrorThrower.ResourceNotFound();
            }

            return(account);
        }
Ejemplo n.º 3
0
        public IClientApplication GetClientApplicationByClientIdentifier(string clientIdentifier)
        {
            Guard.NotNullOrEmpty(() => clientIdentifier, clientIdentifier);

            // Get the app
            IEnumerable <IClientApplication> apps = Storage.Find(Storage.BuildQuery(
                                                                     Reflector <ClientApplication> .GetPropertyName(x => x.ClientIdentifier),
                                                                     QueryOperator.EQ, clientIdentifier));

            if (!apps.Any())
            {
                throw LogicErrorThrower.ResourceNotFound();
            }

            return(apps.FirstOrDefault());
        }
Ejemplo n.º 4
0
        internal void DeleteClientApplication(string id)
        {
            Guard.NotNullOrEmpty(() => id, id);

            // Get the app
            IClientApplication app = Storage.Get(id);

            if (app == null)
            {
                throw LogicErrorThrower.ResourceNotFound();
            }

            Storage.Delete(id);

            //TODO: Audit the deletion of the client application
        }
Ejemplo n.º 5
0
        internal void DeleteUserAccount(string currentUsername, string id)
        {
            Guard.NotNull(() => currentUsername, currentUsername);
            Guard.NotNull(() => id, id);

            // Get the account
            IUserAccount account = Storage.Get(id);

            if (account == null)
            {
                throw LogicErrorThrower.ResourceNotFound();
            }

            // Delete the account
            Storage.Delete(id);

            //TODO: Audit the deletion of the user account
        }
Ejemplo n.º 6
0
        internal IUserAccount UpdateUserAccount(string currentUsername, string id, string oldPasswordHash,
                                                string newPasswordHash,
                                                string forename, string surname, string email, string mobilePhone, Address address)
        {
            Guard.NotNull(() => currentUsername, currentUsername);
            Guard.NotNull(() => id, id);

            // Get the account
            IUserAccount accountToUpdate = Storage.Get(id);

            if (accountToUpdate == null)
            {
                throw LogicErrorThrower.ResourceNotFound();
            }
            accountToUpdate.Address = accountToUpdate.Address ?? new Address();

            //Verify password hashes
            if (newPasswordHash.HasValue())
            {
                if (!accountToUpdate.PasswordHash.EqualsOrdinal(oldPasswordHash))
                {
                    throw LogicErrorThrower.RuleViolation(Resources.UserAccountsManager_PasswordsDontMatch);
                }

                accountToUpdate.PasswordHash = newPasswordHash;
            }

            //Update (allowable) account properties
            accountToUpdate.Forenames   = forename;
            accountToUpdate.Surname     = surname;
            accountToUpdate.Email       = email;
            accountToUpdate.MobilePhone = mobilePhone;
            if (address != null)
            {
                accountToUpdate.Address.PopulateWithNonDefaultValues(address);
            }

            IUserAccount newAccount = Storage.Update(id, accountToUpdate);

            // TODO: Audit the update of the account

            return(newAccount);
        }