コード例 #1
0
ファイル: AccountDaoTest.cs プロジェクト: Lincoln007/Passport
        public void GetAccountTest()
        {
            using (var db = DbHelper.GetDataContext())
            {
                var data = db.Account.Where(e => e.Username.Contains("maddemon")).FirstOrDefault();

                var account = target.GetAccount(data.Username);

                Assert.AreEqual(data.Username, account.Username);
            }
        }
コード例 #2
0
        public ActionResult Login(LoginModel model, string ReturnUrl)
        {
            var dao = new AccountDao();

            if (ModelState.IsValid)
            {
                var result = dao.Login(model.Email, model.Password);
                if (result)
                {
                    var ac   = dao.GetAccount(model.Email);
                    var user = new UserLogin();
                    user.AccountID = ac.AccID;
                    user.UserID    = long.Parse(ac.UserID.ToString());
                    user.UserName  = ac.UserName;
                    user.Email     = ac.Email;
                    Session.Add(UserSession, user);
                    return(Redirect(ReturnUrl));
                }
                else
                {
                    ModelState.AddModelError("", "The account or password does not exist");
                }
            }
            return(Redirect(ReturnUrl));
        }
コード例 #3
0
        public User Login(string username, string password, string checkcode, out string errorcode)
        {
            errorcode = null;
            var account = _accountDao.GetAccount(username);

            if (account == null)
            {
                errorcode = LoginCode.UserNameNotExist;
            }

            if (account.Password != password)
            {
                errorcode = LoginCode.AccountNotMatch;
            }

            User user = null;

            if (string.IsNullOrEmpty(errorcode))
            {
                if (account.User != null)
                {
                    user = account.User.ToBusinessObject();
                }
            }
            return(user);
        }
コード例 #4
0
        public ActionResult Login(LoginModel loginModel)
        {
            if (ModelState.IsValid)
            {
                var acc = new AccountDao();
                var kq  = acc.Login(loginModel.userName, MaHoa.Instance.Encrypt(loginModel.passWord));
                if (kq == 1)
                {
                    var user       = acc.GetAccount(loginModel.userName);
                    var accSession = new AccLogin();
                    accSession.UserName     = user.Username;
                    accSession.AccID        = user.ID;
                    accSession.Dissplayname = user.Dissplayname;



                    Session.Add(CommonConstants.Admin_Session, accSession);

                    return(RedirectToAction("AdminIndex", "Index"));
                }
                else if (kq == 0)
                {
                    ModelState.AddModelError("", "Tài khoản không tồn tại");
                }
                else
                {
                    ModelState.AddModelError("", "Sai tài khoản hoặc mật khẩu");
                }
            }
            return(View("LoginAcc"));
        }
コード例 #5
0
ファイル: AccountManager.cs プロジェクト: Lincoln007/Passport
        //public PagingResult<Account> GetAccounts(AccountFilter filter, int page = 1, int pageSize = 20)
        //{
        //    var paging = new Paging
        //    {
        //        PageSize = pageSize,
        //        CurrentPage = page,
        //    };
        //    var data = Dao.GetAccounts(filter, paging);
        //    return new PagingResult<Account>(paging, data);
        //}

        public Account GetAccount(string username, string password, string agentUsername = null)
        {
            var account = Dao.GetAccount(username, password);

            if (account == null || account.Deleted == 1)
            {
                throw new ArgumentException("用户名或密码不正确!");
            }

            if ((Status)account.Status == Status.Disabled)
            {
                throw new ArgumentException("该用户登录功能已被关闭!");
            }

            if (!string.IsNullOrEmpty(agentUsername))
            {
                var agent = Dao.GetAccount(agentUsername);
                if (agent == null || agent.Deleted == 1)
                {
                    throw new ArgumentException("代理的用户名不存在!");
                }

                if (!Dao.HasAgent(account.AccountId, agent.AccountId))
                {
                    throw new ArgumentException("你没有被授权代理这个用户!");
                }

                account.Agent = agent;
            }

            return(account);
        }
コード例 #6
0
        public Result <string, Account> AddNew(long accountTypeId, long providerId, string name, string number)
        {
            try
            {
                var accountHolder = _accountDao.GetAccount(accountTypeId, providerId, number);

                if (accountHolder != null)
                {
                    return(Result <string, Account> .ForFailure("Looks like the account already exists"));
                }

                var id = _accountDao.CreateAccount(accountTypeId, providerId, name, number);

                var createdAccount = _accountDao.GetById(id);
                return(Result <string, Account> .ForSuccess(createdAccount));
            }
            catch (Exception ex)
            {
                _logger.LogError("Can't create a new account: ", ex);
                return(Result <string, Account> .ForFailure("Can't create new account"));
            }
        }
コード例 #7
0
 public void UserNameOfAccountIsNullThenThrowArgumentNullException()
 {
     accountDao = new AccountDao();
     Assert.Throws <ArgumentNullException>(() => accountDao.GetAccount(null));
 }