コード例 #1
0
        }         //

        public static int GetCurrentUserId()
        {
            AppUser user = AccountServices.GetUserFromSession();

            if (user == null || user.Id == 0)
            {
                return(0);
            }
            else
            {
                return(user.Id);
            }
        }         //
コード例 #2
0
        ///// <summary>
        ///// User is authenticated, either get from session or via the Identity name
        ///// </summary>
        ///// <param name="identityName"></param>
        ///// <returns></returns>
        public static AppUser GetCurrentUser(string identityName = "")
        {
            AppUser user = AccountServices.GetUserFromSession();

            //if ( ( user == null || user.Id == 0 ) && !string.IsNullOrWhiteSpace( identityName ) )
            //{
            //	//NOTE identityName is related to the UserName
            //	//TODO - need to add code to prevent dups between google register and direct register
            //	user = GetUserByUserName( identityName );
            //	if ( user != null && user.Id > 0 )
            //		AddUserToSession( HttpContext.Current.Session, user );
            //}

            return(user);
        } //
コード例 #3
0
        }         //

        /// <summary>
        /// set the current user via an identity name at session start
        /// </summary>
        /// <param name="identityName"></param>
        /// <returns></returns>
        public static AppUser SetCurrentUser(string identityName)
        {
            AppUser user = AccountServices.GetUserFromSession();

            if (!string.IsNullOrWhiteSpace(identityName))
            {
                //assume identityName is email
                //TODO - need to add code to prevent dups between google register and direct register
                user = GetUserByEmail(identityName);
                if (user != null && user.Id > 0)
                {
                    AddUserToSession(HttpContext.Current.Session, user);
                }
            }

            return(user);
        }         //