當前位置: 首頁>>代碼示例>>C#>>正文


C# UserAuth.ThrowIfNull方法代碼示例

本文整理匯總了C#中ServiceStack.ServiceInterface.Auth.UserAuth.ThrowIfNull方法的典型用法代碼示例。如果您正苦於以下問題:C# UserAuth.ThrowIfNull方法的具體用法?C# UserAuth.ThrowIfNull怎麽用?C# UserAuth.ThrowIfNull使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ServiceStack.ServiceInterface.Auth.UserAuth的用法示例。


在下文中一共展示了UserAuth.ThrowIfNull方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateUserAuth

        public UserAuth CreateUserAuth(UserAuth newUser, string password)
        {
            newUser.ThrowIfNull("newUser");
            password.ThrowIfNullOrEmpty("password");

            if (newUser.UserName.IsNullOrEmpty() && newUser.Email.IsNullOrEmpty())
                throw new ArgumentNullException("UserName or Email is required");

            if (!newUser.UserName.IsNullOrEmpty())
            {
                if (!ValidUserNameRegEx.IsMatch(newUser.UserName))
                    throw new ArgumentException("UserName contains invalid characters", "UserName");
            }

            return dbFactory.Exec(dbCmd => {
                var effectiveUserName = newUser.UserName ?? newUser.Email;
                var existingUser = GetUserAuthByUserName(dbCmd, effectiveUserName);
                if (existingUser != null)
                    throw new ArgumentException("User {0} already exists".Fmt(effectiveUserName));

                var saltedHash = new SaltedHash();
                string salt;
                string hash;
                saltedHash.GetHashAndSaltString(password, out hash, out salt);

                newUser.PasswordHash = hash;
                newUser.Salt = salt;

                dbCmd.Insert(newUser);

                newUser = dbCmd.GetById<UserAuth>(dbCmd.GetLastInsertId());
                return newUser;
            });
        }
開發者ID:austinvernsonger,項目名稱:ServiceStack,代碼行數:34,代碼來源:OrmLiteAuthRepository.cs

示例2: ValidateNewUserWithoutPassword

		private void ValidateNewUserWithoutPassword(UserAuth newUser)
		{
			newUser.ThrowIfNull("newUser");

			if (newUser.UserName.IsNullOrEmpty() && newUser.Email.IsNullOrEmpty())
				throw new ArgumentNullException("UserName or Email is required");

			if (!newUser.UserName.IsNullOrEmpty())
			{
				if (!ValidUserNameRegEx.IsMatch(newUser.UserName))
					throw new ArgumentException("UserName contains invalid characters", "UserName");
			}
		}
開發者ID:JackFong,項目名稱:ServiceStack.Contrib,代碼行數:13,代碼來源:RavenUserAuthRepository.cs

示例3: CreateUserAuth

        public UserAuth CreateUserAuth(UserAuth newUser, string password)
        {
            newUser.ThrowIfNull("newUser");
            password.ThrowIfNullOrEmpty("password");

            if (newUser.UserName.IsNullOrEmpty() && newUser.Email.IsNullOrEmpty())
                throw new ArgumentNullException("UserName or Email is required");

            if (!newUser.UserName.IsNullOrEmpty())
            {
                if (!ValidUserNameRegEx.IsMatch(newUser.UserName))
                    throw new ArgumentException("UserName contains invalid characters", "UserName");
            }

            using (var redis = factory.GetClient())
            {
                var effectiveUserName = newUser.UserName ?? newUser.Email;
                var userAuth = GetUserAuthByUserName(redis, newUser.UserName);
                if (userAuth != null)
                    throw new ArgumentException("User {0} already exists".Fmt(effectiveUserName));

                var saltedHash = new SaltedHash();
                string salt;
                string hash;
                saltedHash.GetHashAndSaltString(password, out hash, out salt);

                newUser.PasswordHash = hash;
                newUser.Salt = salt;

                newUser.Id = redis.As<UserAuth>().GetNextSequence();

                if (!newUser.UserName.IsNullOrEmpty())
                    redis.SetEntryInHash(IndexUserNameToUserId, newUser.UserName, newUser.Id.ToString());
                if (!newUser.Email.IsNullOrEmpty())
                    redis.SetEntryInHash(IndexEmailToUserId, newUser.Email, newUser.Id.ToString());

                redis.Store(newUser);

                return newUser;
            }
        }
開發者ID:austinvernsonger,項目名稱:ServiceStack,代碼行數:41,代碼來源:RedisAuthRepository.cs

示例4: ValidateNewUser

        private void ValidateNewUser(UserAuth newUser, string password)
        {
            newUser.ThrowIfNull("newUser");
            password.ThrowIfNullOrEmpty("password");

            if (newUser.UserName.IsNullOrEmpty() && newUser.Email.IsNullOrEmpty())
                throw new ArgumentNullException("UserName or Email is required");

            //Want to have username and email be the same
            //if (!newUser.UserName.IsNullOrEmpty())
            //{
            //   if (!ValidUserNameRegEx.IsMatch(newUser.UserName))
            //        throw new ArgumentException("UserName contains invalid characters", "UserName");
            // }
        }
開發者ID:paaschpa,項目名稱:myThat,代碼行數:15,代碼來源:NHibrenateUserAuthRepository.cs


注:本文中的ServiceStack.ServiceInterface.Auth.UserAuth.ThrowIfNull方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。