コード例 #1
0
        public LoginMessage AuthenticateAccount(string site, string device, string deviceId, string sessionId, string account, string password)
        {
            LoginMessage msg  = new LoginMessage();
            var          user = repoUser.Query(o => o.Account == account && o.Status == DataStatus.Normal).FirstOrDefault();

            if (user == null)
            {
                msg.Status = LoginStatus.AccountNotExists;
                return(msg);
            }
            password = pwdEncrypt.Encrypt(password);
            if (user.Password != password)
            {
                msg.Status = LoginStatus.PasswordNotCorrect;
                return(msg);
            }

            var siteInfo = host.GetSites().GetSiteByName(site);

            if (siteInfo == null)
            {
                msg.Status  = LoginStatus.Exception;
                msg.Message = string.Format("Site {0} is not found.", site);
                return(msg);
            }
            string token   = generator.Generate(RandomChars, AccessTokenLength);
            var    session = repoSession.Query(o => o.SessionId == sessionId).FirstOrDefault();

            if (session == null)
            {
                session = new ServerSession()
                {
                    SessionId             = sessionId,
                    SiteName              = site,
                    UserId                = user.UserId,
                    Device                = device,
                    DeviceId              = deviceId,
                    AccessToken           = token,
                    AccessTokenExpiryTime = DateTime.Now.AddMinutes(SessionTimeOutMinutes),
                    LastAccessTime        = DateTime.Now
                };

                repoSession.Insert(session);
            }
            else
            {
                session.AccessToken           = token;
                session.UserId                = user.UserId;
                session.AccessTokenExpiryTime = DateTime.Now.AddMinutes(SessionTimeOutMinutes);
                session.LastAccessTime        = DateTime.Now;

                repoSession.Update(session);
            }

            msg.Status           = LoginStatus.Success;
            msg.EncryptedSession = GetEncryptedLocalSession(siteInfo, user, session);
            return(msg);
        }
コード例 #2
0
ファイル: DefaultAuthProvider.cs プロジェクト: cairabbit/daf
        public LoginMessage AuthenticateAccount(string site, string device, string deviceId, string sessionId, string account, string password)
        {
            LoginMessage msg = new LoginMessage();
            var user = repoUser.Query(o => o.Account == account && o.Status == DataStatus.Normal).FirstOrDefault();
            if (user == null)
            {
                msg.Status = LoginStatus.AccountNotExists;
                return msg;
            }
            password = pwdEncrypt.Encrypt(password);
            if (user.Password != password)
            {
                msg.Status = LoginStatus.PasswordNotCorrect;
                return msg;
            }

            var siteInfo = host.GetSites().GetSiteByName(site);
            if (siteInfo == null)
            {
                msg.Status = LoginStatus.Exception;
                msg.Message = string.Format("Site {0} is not found.", site);
                return msg;
            }
            string token = generator.Generate(RandomChars, AccessTokenLength);
            var session = repoSession.Query(o => o.SessionId == sessionId).FirstOrDefault();
            if (session == null)
            {
                session = new ServerSession()
                {
                    SessionId = sessionId,
                    SiteName = site,
                    UserId = user.UserId,
                    Device = device,
                    DeviceId = deviceId,
                    AccessToken = token,
                    AccessTokenExpiryTime = DateTime.Now.AddMinutes(SessionTimeOutMinutes),
                    LastAccessTime = DateTime.Now
                };

                repoSession.Insert(session);
            }
            else
            {
                session.AccessToken = token;
                session.UserId = user.UserId;
                session.AccessTokenExpiryTime = DateTime.Now.AddMinutes(SessionTimeOutMinutes);
                session.LastAccessTime = DateTime.Now;

                repoSession.Update(session);
            }

            msg.Status = LoginStatus.Success;
            msg.EncryptedSession = GetEncryptedLocalSession(siteInfo, user, session);
            return msg;
        }
コード例 #3
0
        public LoginMessage GetSession(string site, string sessionId)
        {
            LoginMessage msg      = new LoginMessage();
            var          siteInfo = host.GetSites().GetSiteByName(site);

            if (siteInfo == null)
            {
                msg.Status  = LoginStatus.Exception;
                msg.Message = string.Format("Site {0} is not found.", site);
                return(msg);
            }
            var session = repoSession.Query(o => o.SessionId == sessionId).FirstOrDefault();

            if (session == null)
            {
                msg.Status  = LoginStatus.Exception;
                msg.Message = string.Format("Session with Id {0} not found! Please login again.", sessionId);
                return(msg);
            }
            if (session.LastAccessTime > DateTime.Now.AddMinutes(SessionTimeOutMinutes))
            {
                msg.Status  = LoginStatus.Exception;
                msg.Message = string.Format("Session with Id {0} expired! Please login again.", sessionId);
                return(msg);
            }
            var user = repoUser.Query(o => o.UserId == session.UserId && o.Status == DataStatus.Normal).FirstOrDefault();

            if (user == null)
            {
                msg.Status = LoginStatus.AccountNotExists;
                return(msg);
            }
            msg.Status           = LoginStatus.Success;
            msg.EncryptedSession = GetEncryptedLocalSession(siteInfo, user, session);
            return(msg);
        }
コード例 #4
0
ファイル: DefaultAuthProvider.cs プロジェクト: cairabbit/daf
 public LoginMessage GetSession(string site, string sessionId)
 {
     LoginMessage msg = new LoginMessage();
     var siteInfo = host.GetSites().GetSiteByName(site);
     if (siteInfo == null)
     {
         msg.Status = LoginStatus.Exception;
         msg.Message = string.Format("Site {0} is not found.", site);
         return msg;
     }
     var session = repoSession.Query(o => o.SessionId == sessionId).FirstOrDefault();
     if (session == null)
     {
         msg.Status = LoginStatus.Exception;
         msg.Message = string.Format("Session with Id {0} not found! Please login again.", sessionId);
         return msg;
     }
     if (session.LastAccessTime > DateTime.Now.AddMinutes(SessionTimeOutMinutes))
     {
         msg.Status = LoginStatus.Exception;
         msg.Message = string.Format("Session with Id {0} expired! Please login again.", sessionId);
         return msg;
     }
     var user = repoUser.Query(o => o.UserId == session.UserId && o.Status == DataStatus.Normal).FirstOrDefault();
     if (user == null)
     {
         msg.Status = LoginStatus.AccountNotExists;
         return msg;
     }
     msg.Status = LoginStatus.Success;
     msg.EncryptedSession = GetEncryptedLocalSession(siteInfo, user, session);
     return msg;
 }