Exemplo n.º 1
0
        public void AccountDAO_Test()
        {
            /*Context*/
            AccountDAO target = new AccountDAO();
            /*Insert*/
            AccountDTO acc = new AccountDTO();
            acc.userName = "******";
            acc.password = "******";
            acc.accountType = "administrator";
            acc.status = "active";

            string userName = "******"; // TODO: Initialize to an appropriate value
            Assert.AreEqual(false, target.isFound(userName));
            Assert.AreEqual(true,target.presist(acc));

            Assert.AreEqual(true, target.isFound(userName));//

            /*Update*/
            acc.status = "inactive";
            target.merge(acc);

            string expectedUpdate = "inactive";
            AccountDTO upd =  target.find("griddy");
            Assert.AreEqual(expectedUpdate, upd.status);

            /*Delete*/
            Assert.AreEqual(false, target.removeByUserId("griddy"));
        }
        /*
         * 1 Successfull
         * 2 Invalid User
         * 3 E-mail Address not found
         * 4 Unable to send E-mail - contact administrator
         * 5 E-mail successfully sent
         */
        public int forgotPassword(string userName,string message)
        {
            string newPassword = System.Web.Security.Membership.GeneratePassword(8, 2);
            int flag = 2;//Invalid user

            AccountDAO acc_context = new AccountDAO();
            ContactInfoDAO con_context = new ContactInfoDAO();

            if (acc_context.isFound(userName))
            {
                if (con_context.isFound(userName, "e-mail"))
                {
                    ContactInfoDTO email = con_context.find(userName, "e-mail");
                    AccountDTO account = acc_context.find(userName);
                    account.password = newPassword;
                    acc_context.merge(account);

                    message.Replace("PASSWORD", newPassword);
                    flag = sendMail(email.data, message);

                }
                else
                {
                    flag = 3; //Email Address not found
                }

            }
            return flag;
        }
        public void setUserRole(String username, AccountType accountType)
        {
            AccountDAO accountDao = new AccountDAO();
            AccountDTO accountDto = accountDao.find(username);

            accountDto.accountType = accountType.ToString();
            accountDao.merge(accountDto);
        }
        public void setAccountActive(String username)
        {
            AccountDAO accountDao = new AccountDAO();
            AccountDTO accountDto = accountDao.find(username);

            accountDto.status = AccountStatus.ACTIVE.ToString();
            accountDao.merge(accountDto);
        }
        public void requestAccountUnlock(String username)
        {
            AccountDAO accountDao = new AccountDAO();
            AccountDTO accountDto = accountDao.find(username);

            accountDto.status = AccountStatus.UNLOCKED.ToString();
            accountDao.merge(accountDto);
        }
        public void lockAccount(String username)
        {
            AccountDAO accountDao = new AccountDAO();
            AccountDTO accountDto = accountDao.find(username);

            accountDto.status = AccountStatus.LOCKED.ToString();
            accountDao.merge(accountDto);
        }