コード例 #1
0
ファイル: LoginBLL.cs プロジェクト: franknew/AnjuManager
        public LoginResultForm Login(string username, string password)
        {
            LoginResultForm result = new LoginResultForm();
            ISqlMapper mapper = MapperHelper.GetMapper();
            UserDao userdao = new UserDao(mapper);
            UserInfoDao userInfoDao = new UserInfoDao(mapper);
            RoleDao roleDao = new RoleDao(mapper);
            User_RoleDao urdao = new User_RoleDao(mapper);
            LogonHistoryDao historyDao = new LogonHistoryDao(mapper);
            MenuDao menudao = new MenuDao(mapper);
            Menu_RoleDao mrdao = new Menu_RoleDao(mapper);
            var user = userdao.Query(new UserQueryForm { Name = username, Password = password }).FirstOrDefault();
            if (user != null)
            {
                if (user.Enabled == 0) throw new Exception("该用户已被禁用,请联系管理员!");
                string token = Guid.NewGuid().ToString().Replace("-", "");
                var userinfo = userInfoDao.Query(new UserInfoQueryForm { ID = user.ID }).FirstOrDefault();
                var ur = urdao.Query(new User_RoleQueryForm { UserID = user.ID });
                List<string> roleidlist = new List<string>();
                ur.ForEach(t =>
                {
                    roleidlist.Add(t.RoleID);
                });
                var roles = roleDao.Query(new RoleQueryForm { IDs = roleidlist });

                var mrs = mrdao.Query(new Menu_RoleQueryForm { RoleIDs = roleidlist });
                var menuids = (from mr in mrs select mr.MenuID).Distinct().ToList();

                result.Menu = menudao.Query(new MenuQueryForm { IDs = menuids, Enabled = 1 });

                UserEntireInfo u = new UserEntireInfo
                {
                    User = user,
                    UserInfo = userinfo,
                    Role = roles,
                };

                CacheItem item = new CacheItem(token, u);
                LogonHistory history = new LogonHistory
                {
                    LogonTime = DateTime.Now,
                    Token = token,
                    UserID = user.ID,
                    ActiveTime = DateTime.Now,
                };
                historyDao.Add(history);
                result.User = u;
                result.token = token;
                cache.AddItem(item, 1800);
                //MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "login user:"******",token:" + token }, SOAFramework.Library.CacheEnum.FormMonitor);
                return result;
            }
            else
            {
                throw new Exception("用户名或者密码错误!请输入正确的用户名和密码!");
            }
        }
コード例 #2
0
ファイル: UserBLL.cs プロジェクト: franknew/AnjuManager
 public UserEntireInfo GetCurrentUser(string token = null)
 {
     ISqlMapper mapper = MapperHelper.GetMapper();
     if (string.IsNullOrEmpty(token)) token = ServiceSession.Current.Context.Parameters["token"].ToString();
     var u = GetUserEntireInfoFromCache(token);
     if (u == null)
     {
         MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "user is null" }, SOAFramework.Library.CacheEnum.FormMonitor);
         UserDao userdao = new UserDao(mapper);
         RoleDao roledao = new RoleDao(mapper);
         UserInfoDao uidao = new UserInfoDao(mapper);
         LogonHistoryDao lhdao = new LogonHistoryDao(mapper);
         var logonhistory = lhdao.Query(new LogonHistoryQueryForm { Token = token }).FirstOrDefault();
         if (logonhistory == null) throw new Exception("获取当前用户信息时发生错误,用户不存在");
         string userid = logonhistory.UserID;
         var user = userdao.Query(new UserQueryForm { ID = userid }).FirstOrDefault();
         var userinfo = uidao.Query(new UserInfoQueryForm { ID = userid }).FirstOrDefault();
         var roles = roledao.QueryRoleByUserID(userid);
         u = new UserEntireInfo
         {
             User = user,
             Role = roles,
             UserInfo = userinfo,
         };
     }
     return u;
 }