Exemplo n.º 1
0
 public LogonResultForm GetUserInfo(string userid)
 {
     var mapper = Common.GetMapperFromSession();
     UserDao userdao = new UserDao(mapper);
     var user = userdao.Query(new UserQueryForm { Name = userid }).FirstOrDefault();
     if (user == null) throw new Exception("用户:" + userid + "在系统中不存在!");
     if (user.Enabled == 0) throw new Exception("该用户已被禁用,请联系管理员!");
     LogonResultForm result = new LogonResultForm();
     UserInfoDao userInfoDao = new UserInfoDao(mapper);
     RoleDao roleDao = new RoleDao(mapper);
     LogonHistoryDao historyDao = new LogonHistoryDao(mapper);
     string token = Guid.NewGuid().ToString().Replace("-", "");
     var userinfo = userInfoDao.Query(new UserInfoQueryForm { ID = user.ID }).FirstOrDefault();
     UserEntireInfo u = new UserEntireInfo { User = user };
     if (userinfo != null) u.UserInfo = userinfo;
     u.Role = roleDao.QueryRoleByUserID(u.User.ID);
     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.token = token;
     result.UserInfo = userinfo;
     cache.AddItem(item, 30 * 60);
     MenuBLL menubll = new MenuBLL();
     result.Menu = menubll.GetCurrentUserMenu(result.token);
     return result;
 }
Exemplo n.º 2
0
 public UserEntireInfo GetCurrentUser(string token = null)
 {
     ISqlMapper mapper = Common.GetMapperFromSession();
     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();
         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;
 }