Exemple #1
0
        public async Task <ExecutionResult> CreateCompanyUser(CompanyUserEntity companyUser)
        {
            var collection = this.mongoDataProvider.CompanyDb.GetCollection <CompanyUserEntity>(CompanyUserCollection);
            var c          = await collection.CountAsync(x => x.UserIdentifier == companyUser.UserIdentifier && x.CompanyIdentifier == companyUser.CompanyIdentifier);

            if (c > 0)
            {
                return(new ExecutionResult <CompanyUserEntity>(ErrorInfoFacory.CreateOne("The user already exist")));
            }

            await collection.InsertOneAsync(companyUser);

            return(new ExecutionResult());
        }
Exemple #2
0
        public async Task <ExecutionResult <CompanyUserEntity> > SignInUserToCompany(string userIdentifier, string companyIdentifier, string password)
        {
            var companyUser = await companyUserService.GetCompanyUser(userIdentifier, companyIdentifier);

            if (companyUser == null)
            {
                throw new EntityNotFoundException("No company user");
            }

            var hash = GetHashString(password, Convert.FromBase64String(companyUser.Value.Salt));

            if (hash != companyUser.Value.PasswordHash)
            {
                return(new ExecutionResult <CompanyUserEntity>(ErrorInfoFacory.CreateOne("403", "Password incorrect")));
            }

            return(companyUser);
        }