private object Login() { string accessKey = this.TPrm[0].StringValue; if (new GroupBundle().LiteGroups.Any(v => v.AccessKey == accessKey)) { // user } else if (accessKey == Consts.SUPERVISOR_ACCESS_KEY) { // supervisor } else { throw new Exception("不明なアクセスキー"); } SessionBundle sessionBundle = new SessionBundle(); Session session = null; if (Consts.SESSION_NUM_LMT < sessionBundle.Sessions.Count) { // HACK: 不要セッションの管理が面倒なので、セッションが増えてきたら、同じグループについては同じセッションを使い回す。 Session[] sessions = sessionBundle.Sessions.Where(v => v.AccessKey == accessKey).ToArray(); if (1 <= sessions.Length) { session = sessions[SecurityTools.CRandom.GetInt(sessions.Length)]; session.Accessed(); sessionBundle.Save(); } } if (session == null) { session = new Session() { SessionKey = SessionUtils.CreateSessionKey(), AccessKey = accessKey, SupervisorMode = accessKey == Consts.SUPERVISOR_ACCESS_KEY, LastAccessedDateTime = DateTimeToSec.Now.GetDateTime(), }; sessionBundle.Sessions.Add(session); sessionBundle.Save(); } return(new object[] { session.SessionKey, session.SupervisorMode, }); }
private void LoggedIn(bool supervisorMode = false) { string sessionKey = this.TPrm[0].StringValue; this.TPrm = this.TPrm[1]; // 本来のパラメータに置き換え SessionBundle sessionBundle = new SessionBundle(); Session session = sessionBundle.Sessions.First(v => v.SessionKey == sessionKey); if (supervisorMode && session.SupervisorMode == false) { throw new Exception("管理者権限が必要です。"); } session.Accessed(); this.Session = session; this.LiteGroup = new GroupBundle().LiteGroups.FirstOrDefault(v => v.AccessKey == session.AccessKey); }