示例#1
0
文件: Users.cs 项目: robgray/Tucana
 public static void ChangePassword(User user, string password)
 {
     MembershipUser aspUser = Membership.GetUser(user.Username);
     if (aspUser != null)
     {
         aspUser.ChangePassword(aspUser.GetPassword(), password);
     }
 }
示例#2
0
        public void Search_for_contract_using_phone_nummber()
        {
            // Setup mock behaviour
            IList<Contract> contracts = new List<Contract>();
            contracts.Add(new Contract(1, DateTime.Now) { AccountId = 1, ContractNumber = "CT9999", ContractStatus = ContractStatus.Active, PhoneNumber1 = "093233904", PhoneNumber2 = "0339430449" });
            _contractRepository
                .Expect(c => c.FindByPhoneNumber("0339430449"))
                .Returns(contracts);

            _accountRepository
                .Expect(a => a.GetAccount(1))
                .Returns(new MasterAccount(1) { AccountName = "Test Account", AccountNumber = "TST0001", ContactId = 1, CompanyId = 1 });

            _contactRepository
                .Expect(c => c.GetContactEntity(1))
                .Returns(new Contact(1) { Name = "Test Contact" });

            _companyRepository
                .Expect(c => c.GetCompany(1))
                .Returns(new Company(1) { CompanyName = "Test Company" });

            User user = new User() { Username = "******", IsActive = true, Email = "*****@*****.**", IsAuthenticated = true, Name = "Test" };
            ContractSearchRequest request = new ContractSearchRequest()
            {
                SearchValue = "0339430449",
                SearchType = ContractSearchField.PhoneNumber,
                SearchStatus = ContractStatus.Active,
                SearchContractStatusType = SearchContractStatusType.UseStatus,
                User = user
            };
            ContractSearchResponse response = _service.FindContracts(request);

            Assert.IsNotNull(response, "Response is null");
            Assert.IsTrue(response.IsSuccessful, "Response is not successful");
            Assert.IsNotNull(response.Contracts, "Contracts is null");
            Assert.AreEqual(1, response.Contracts.Count, "Contacts count");
            Assert.AreEqual("0339430449", response.Contracts[0].PhoneNumber, "Phone Number");
        }
示例#3
0
        protected void ApproveInvoicing(object sender, EventArgs e)
        {
            if (Account.AccountId != null)
            {
                bool approval = ((Control)sender).ID == "ApproveInvoicingButton" ? true : false;
                var service = ServiceFactory.GetService<IContractService>();
                var user = new User { Username = User.Identity.Name, IsAuthenticated = User.Identity.IsAuthenticated };
                var request = new ApproveInvoicingRequest { AccountId = Account.AccountId.Value, IsApprovalGranted = approval, User = user };
                var response = service.ApproveInvoicing(request);
                if (response.IsSuccessful)
                {
                    pnlInvoicingApproval.Visible = false;
                    Account.BillingMethod = BillingMethod.Invoice;

                    // Enable controls.
                    SetControlReadOnly(false);
                }
                else
                {
                    UserMessage.SetFailure(response.Message);
                }
            }
            else
            {
                UserMessage.SetFailure("No account associated with this contact.  Cannot approve");
            }
        }
示例#4
0
文件: Users.cs 项目: robgray/Tucana
        public static User GetUser(string username)
        {
            if (username == "robgray")
                return new SupportUser
                           {
                               Email = "*****@*****.**",
                               IsActive = true,
                               IsAuthenticated = true,
                               Name = "Rob Gray",
                               Username = "******"
                           };

            var aspUser = Membership.GetUser(username);
            if (aspUser == null) return null;

            var profile = WebProfile.GetProfile(username);
            var agentId = profile.AgentId;
            var contactId = profile.ContactId;

            profile.Save();

            if (agentId > 0)
            {
                // It's an agent entity
                var user = new AgentUser()
                {
                    AgentId = agentId,
                    Email = aspUser.Email,
                    IsAuthenticated = true,
                    Name = aspUser.UserName,
                    Username = aspUser.UserName,
                    IsActive = aspUser.IsApproved && !aspUser.IsLockedOut,
                };
                return user;
            }
            if (contactId > 0)
            {
                var user = new ContactUser()
                {
                    ContactId = contactId,
                    Email = aspUser.Email,
                    IsAuthenticated = true,
                    IsActive = aspUser.IsApproved && !aspUser.IsLockedOut,
                    Name = aspUser.UserName,
                    Username = aspUser.UserName
                };

                return user;
            }
            else
            {
                User user = new User()
                {
                    Email = aspUser.Email,
                    Username = aspUser.UserName,
                    Name = aspUser.UserName,
                    IsActive = aspUser.IsApproved && !aspUser.IsLockedOut,
                    IsAuthenticated = true
                };

                return user;
            }
        }
示例#5
0
文件: Users.cs 项目: robgray/Tucana
        public static void Update(User user)
        {
            MembershipUser aspUser = Membership.GetUser(user.Username);
            if (aspUser == null) return;
            WebProfile profile = WebProfile.GetProfile(user.Username);
            if (profile == null)
            {
                profile = new WebProfile();
            }

            if (user is AgentUser)
            {
                AgentUser agent = (AgentUser)user;
                profile.AgentId = agent.AgentId;
            }
            else
            {
                profile.AgentId = 0;
            }

            if (user is ContactUser)
            {
                ContactUser contact = (ContactUser)user;
                profile.ContactId = contact.ContactId;
            }
            else
            {
                profile.ContactId = 0;
            }

            aspUser.IsApproved = user.IsActive;
            if (user.IsActive)
            {
                aspUser.UnlockUser();
            }

            profile.Save();
            Membership.UpdateUser(aspUser);
        }
示例#6
0
文件: Users.cs 项目: robgray/Tucana
        public static bool IsInRole(User user, Roles role)
        {
            if (user == null) return false;

            if (user is AgentUser) {
                return role == Roles.Agent;
            }
            if (user is ContactUser) {
                return role == Roles.Customer;
            }
            if (user is SupportUser) {
                if (role == Roles.BackOffice || role == Roles.Support)
                    return true;
                return false;
            }
            return role == Roles.BackOffice;
        }