Example #1
0
        public ActionResult GetAccountsByDisplayNames([AccessTokenBinder]AccessToken token, string displayNames)
        {
            var result = new List<VAccount>();
            var names = displayNames.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var displayName in names)
            {
                var nameDescs = displayName.Split('_');
                var temp = new Account();
                temp.Department = nameDescs[0];
                if (nameDescs.Length > 1)
                {
                    temp.Rank = nameDescs[1];
                }
                if (nameDescs.Length > 2)
                {
                    temp.TrueName = nameDescs[2];
                }

                result.AddRange(Core.AccountManager.Search(temp));
            }

            return Json(result.Select(e => new
            {
                e.TrueName,
                e.Department,
                e.Rank,
                e.AccountId,
                e.Username
            }), JsonRequestBehavior.AllowGet);
        }
Example #2
0
        public static void UserLogin(this HttpContextBase context, Account account)
        {
            var ticketName = account.AccountId + "|" + (int)account.Role + "|" + (account.Agent == null ? 0 : account.Agent.AccountId) + "|" + account.Username;

            var ticket = new FormsAuthenticationTicket(ticketName, false, 30);

            context.Response.Cookies.Set(new HttpCookie(CookieName, FormsAuthentication.Encrypt(ticket)));
        }
Example #3
0
 public string GetAppendedCodeReturnUrl(Client client, Account account, string returnUrl)
 {
     var code = GenerateCode(client, account);
     if (!returnUrl.Contains("?"))
     {
         returnUrl += "?";
     }
     returnUrl += "&code=" + code;
     return returnUrl;
 }
Example #4
0
 public string GenerateCode(Client client, Account account)
 {
     var code = DateTime.Now.Ticks.ToString().MD5();
     Cache.HSet(codeHashId, code, new AuthorizeCode
     {
         ClientId = client.ClientId,
         AccountId = account.AccountId,
         AgentId = account.AgentId
     });
     return code;
 }
Example #5
0
        public void CreateTest()
        {
            Account account = new Account
            {
                Username = "******",
                Password = "******",
                Role = (short)Role.Administrator,
                TrueName = "Admin",
            };
            target.Create(account);

            var expect = target.GetAccount(account.Username, "123");

            Assert.AreNotEqual(0, expect.AccountId);
        }
Example #6
0
        public void Create(Account account)
        {
            using (var db = GetDataContext())
            {
                var existUser = db.Account.Count(e => e.Username.ToLower() == account.Username.ToLower()) > 0;
                if (existUser)
                {
                    throw new ArgumentException("用户名已被占用!");
                }

                if (string.IsNullOrEmpty(account.Password))
                {
                    throw new ArgumentNullException("密码没有填写!");
                }

                var password = account.Password;
                account.Password = Account.GetEncyptPassword(password, account.CreateTime);

                db.Account.Add(account);

                db.SaveChanges();
                account.Password = password;
            }
        }
Example #7
0
 private void UpdateCache(Account account)
 {
     var department = Core.DepartmentManager.GetModel(account.DepartmentId);
     var rank = Core.RankManager.GetModel(account.RankId);
     var vAccount = new VAccount
     {
         AccountId = account.AccountId,
         CreateTime = account.CreateTime,
         Username = account.Username,
         Deleted = account.Deleted,
         Department = department == null ? null : department.Name,
         Rank = rank == null ? null : rank.Name,
         TrueName = account.TrueName,
         Status = account.Status
     };
     UpdateCache(vAccount);
 }
Example #8
0
 public List<VAccount> Search(Account temp)
 {
     return Dao.Search(temp);
 }
Example #9
0
        public void Save(Account account)
        {
            if (string.IsNullOrEmpty(account.Username))
            {
                throw new ArgumentException("用户名不能为空!");
            }

            if (account.AccountId > 0)
            {
                var tmp = Dao.GetAccount(account.AccountId);
                if (tmp != null && tmp.AccountId != account.AccountId)
                {
                    throw new ArgumentException("用户名已被使用!");
                }

                Dao.Update(account);
            }
            else
            {
                if (string.IsNullOrEmpty(account.Password))
                {
                    throw new ArgumentException("密码不能为空!");
                }
                Dao.Create(account);
            }

            UpdateCache(account);
        }
Example #10
0
        public void Update(Account account)
        {
            using (var db = GetDataContext())
            {
                var entity = db.Account.Where(e => e.AccountId == account.AccountId).FirstOrDefault();
                if (entity == null)
                {
                    throw new ArgumentException("参数错误,没找到这个帐号");
                }
                account.CreateTime = entity.CreateTime;
                if (string.IsNullOrEmpty(account.Password))
                {
                    account.Password = entity.Password;
                }
                else
                {
                    account.Password = Account.GetEncyptPassword(account.Password, entity.CreateTime);
                }

                db.Entry(entity).CurrentValues.SetValues(account);

                db.SaveChanges();
            }
        }
Example #11
0
        public List<VAccount> Search(Account temp)
        {
            using (var db = GetDataContext())
            {
                var query = db.VAccount.AsQueryable();
                if (!string.IsNullOrEmpty(temp.Department))
                {
                    query = query.Where(e => e.Department == temp.Department);
                }

                if (!string.IsNullOrEmpty(temp.Rank))
                {
                    query = query.Where(e => e.Rank == temp.Rank);
                }

                if (!string.IsNullOrEmpty(temp.TrueName))
                {
                    query = query.Where(e => e.TrueName == temp.TrueName);
                }

                return query.ToList();
            }
        }