Ejemplo n.º 1
0
        public static UserSession SignInTunityUser(TunityUser systemUser)
        {
            if (systemUser == null) {
                return null;
            }

            UserSession userSession = null;

            Db.Transact(() => {
                TunitySessionCookie cookie = new TunitySessionCookie();

                cookie.Created = cookie.LastUsed = DateTime.UtcNow;
                cookie.Name = CreateAuthToken(systemUser.Name);
                cookie.User = systemUser;

                userSession = AssureTunityUserSession(cookie);
                systemUser.Lastlogin = DateTime.Now;
            });

            return userSession;
        }
Ejemplo n.º 2
0
        private static void DeleteToken(TunitySessionCookie Token)
        {
            QueryResultRows<UserSession> sessions = Db.SQL<UserSession>("SELECT o FROM Concepts.Ring8.Tunity.UserSession o WHERE o.Token=?", Token);

            foreach (var session in sessions) {
                session.Delete();
            }

            Token.Delete();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sign-in user
        /// </summary>
        /// <param name="UserId"></param>
        /// <param name="Password"></param>
        private static UserSession SignInTunityUser(string userId, string password)
        {
            UserSession userSession = null;
            TunityUser systemUser = TunityDbHelper.FromName<TunityUser>(userId);

               if (systemUser != null && systemUser.Active) {
               if (PasswordHash.ValidatePassword(password, systemUser.Password))
               {
                   Db.Transact(() =>
                   {
                       TunitySessionCookie cookie = new TunitySessionCookie();
                       cookie.Created = cookie.LastUsed = DateTime.UtcNow;
                       cookie.Name = CreateAuthToken(systemUser.Name);
                       cookie.User = systemUser;

                       systemUser.Lastlogin = DateTime.Now;
                       userSession = AssureTunityUserSession(cookie);
                   });
               }
            }

            return userSession;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create system user session
        /// </summary>
        /// <param name="Token"></param>
        /// <returns></returns>
        private static UserSession AssureTunityUserSession(TunitySessionCookie cookie)
        {
            UserSession userSession = null;

            bool bSessionCreated = false;

            Db.Transact(() => {
                userSession = Db.SQL<UserSession>("SELECT o FROM Concepts.Ring8.Tunity.UserSession o WHERE o.SessionIdString=?", Session.Current.ToAsciiString()).First;

                if (userSession == null) {
                    userSession = new UserSession();
                    userSession.Created = DateTime.UtcNow;
                    userSession.SessionIdString = Session.Current.ToAsciiString();
                    bSessionCreated = true;
                }

                userSession.Token = cookie;
                userSession.Touched = DateTime.UtcNow;
            });

            if (bSessionCreated) {
                //InvokeSignInCommitHook(userSession.SessionIdString);
            }

            return userSession;
        }