Пример #1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="entity"></param>
 public Membership(MembershipEntity entity)
 {
     this._entity = entity;
     this.Users = new Collection<long>();
     this.Roles = new Collection<long>();
     this.Authorizations = new Collection<long>();
 }
Пример #2
0
        public ActionResult SignIn(MembershipEntity model)
        {
            if (!this.TryValidateModel(model)) { this.View(@"SignIn", model); }
            else if (!Membership.ValidateUser(model.Name, model.Password[0])) { return this.View(@"SignIn", model); }

            var user = Membership.GetUser(model.Name);
            var id = (long)user.ProviderUserKey;

            FormsAuthentication.RedirectFromLoginPage(id.ToString(CultureInfo.InvariantCulture), true);

            return new EmptyResult();
        }
Пример #3
0
        public ActionResult SignUp(MembershipEntity entity)
        {
            var status = MembershipCreateStatus.ProviderError;
            var user = Membership.CreateUser(entity.Name, entity.Password[0], entity.Email, null, null, true, null, out status);
            if (status != MembershipCreateStatus.Success) { return this.View(@"SignUp", entity); }

            var name = ((long)user.ProviderUserKey).ToString(CultureInfo.InvariantCulture);

            FormsAuthentication.RedirectFromLoginPage(name, true);

            return new EmptyResult();
        }
        public static async Task<int> UpdateAsync(MembershipEntity entity, DbConnection connection, DbTransaction transaction, CancellationToken token)
        {
            var command = _factory.CreateCommand(connection, transaction);
            command.CommandText = @"usp_UpdateMemberships";

            KandaDbDataMapper.MapToParameters(command, entity);
            var _ = KandaTableDataGateway._factory.CreateParameter(KandaTableDataGateway.RETURN_VALUE, DbType.Int32, sizeof(int), ParameterDirection.ReturnValue, null);

            var affected = await command.ExecuteNonQueryAsync(token);

            return affected;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="connection"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public static int Update(MembershipEntity entity, DbConnection connection, DbTransaction transaction)
        {
            var command = KandaTableDataGateway._factory.CreateCommand(connection, transaction);

            command.CommandText = @"usp_UpdateMemberships";

            KandaDbDataMapper.MapToParameters(command, entity);

            var result = KandaTableDataGateway._factory.CreateParameter(KandaTableDataGateway.RETURN_VALUE, DbType.Int32, sizeof(int), ParameterDirection.ReturnValue, DBNull.Value);
            command.Parameters.Add(result);

            command.ExecuteNonQuery();

            return (int)result.Value;
        }
        public static async Task<long> InsertAsync(MembershipEntity entity, DbConnection connection, DbTransaction transaction, CancellationToken token)
        {
            var command = _factory.CreateCommand(connection, transaction);

            command.CommandText = @"usp_InsertMemberships";

            KandaDbDataMapper.MapToParameters(command, entity);
            var identity = KandaTableDataGateway._factory.CreateParameter(@"identity", DbType.Decimal, sizeof(decimal), ParameterDirection.Output, DBNull.Value);
            command.Parameters.Add(identity);
            var _ = KandaTableDataGateway._factory.CreateParameter(KandaTableDataGateway.RETURN_VALUE, DbType.Int32, sizeof(int), ParameterDirection.ReturnValue, DBNull.Value);
            command.Parameters.Add(_);

            var affected = await command.ExecuteNonQueryAsync(token);

            return Convert.ToInt64(identity.Value);
        }
        /// <summary>
        /// 指定のユーザー名とパスワードがデータソースに存在しているかどうかを検証します。
        /// </summary>
        /// <returns>
        /// 指定したユーザー名とパスワードが有効な場合は true。それ以外の場合は false。
        /// </returns>
        /// <param name="username">検証対象のユーザー名。</param>
        /// <param name="password">指定したユーザーのパスワード。</param>
        public override bool ValidateUser(string username, string password)
        {
            // 文字列の保護
            var secure = new SecureString();
            secure.AppendString(password);

            // Name、Password 検証
            var entity = new MembershipEntity
                             {
                                 Name = username,
                                 Password = secure,
                             };
            var membership = new DomainModels.Membership(entity);
            membership.Find();

            return (0 < membership.ID);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="connection"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public static int Insert(MembershipEntity entity, DbConnection connection, DbTransaction transaction)
        {
            var command = KandaTableDataGateway._factory.CreateCommand(connection, transaction);

            command.CommandText = @"usp_InsertMemberships";

            KandaDbDataMapper.MapToParameters(command, entity);

            var identity = KandaTableDataGateway._factory.CreateParameter("@identity", DbType.Decimal, sizeof(decimal), ParameterDirection.Output, DBNull.Value);
            command.Parameters.Add(identity);

            var error = KandaTableDataGateway._factory.CreateParameter(KandaTableDataGateway.RETURN_VALUE, DbType.Int32, sizeof(int), ParameterDirection.ReturnValue, DBNull.Value);
            command.Parameters.Add(error);

            var affected = command.ExecuteNonQuery();

            entity.ID = Convert.ToInt64(identity.Value);

            return (int)error.Value;
        }
Пример #9
0
        public void InsertMembershipsFact()
        {
            var connection = default(DbConnection);
            var transaction = default(DbTransaction);
            var command = default(DbCommand);

            try
            {
                connection = this._factory.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction(IsolationLevel.Serializable);

                command = this._factory.CreateCommand(connection, transaction);

                command.CommandText = @"usp_InsertMemberships";

                var entity = new MembershipEntity { Name = new Random().Next().ToString(), Password = @"sadasfsa", CreatedOn = DateTime.Now, Enabled = true, };

                KandaDbDataMapper.MapToParameters(command, entity);

                var identity = this._factory.CreateParameter("@identity", DbType.Decimal, sizeof(decimal), ParameterDirection.Output, DBNull.Value);
                command.Parameters.Add(identity);

                var result = this._factory.CreateParameter(KandaTableDataGateway.RETURN_VALUE, DbType.Int32, sizeof(int), ParameterDirection.ReturnValue, DBNull.Value);
                command.Parameters.Add(result);

                var affected = command.ExecuteNonQuery();
                Assert.Equal(KandaTableDataGateway.NO_ERRORS, result.Value);
                Assert.Equal(1, affected);
            }
            finally
            {
                if (transaction != null) { transaction.Rollback(); }
                if (connection != null) { connection.Close(); }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="connection"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public bool Update(MembershipEntity entity, DbConnection connection, DbTransaction transaction)
        {
            var updated = MembershipsGateway.Update(entity, connection, transaction);

            return (updated == 1);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="connection"></param>
        /// <param name="transaction"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool Create(MembershipEntity entity, DbConnection connection, DbTransaction transaction, out MembershipCreateStatus status)
        {
            status = MembershipCreateStatus.ProviderError;

            entity.Password = KandaHashAlgorithm.ComputeHash(typeof(SHA512Managed).FullName, ((SecureString)entity.Password).GetString(), Encoding.Unicode);

            var error = MembershipsGateway.Insert(entity, connection, transaction);

            switch (error)
            {
                case KandaTableDataGateway.NO_ERRORS:
                    status = MembershipCreateStatus.Success;
                    return true;

                case KandaTableDataGateway.DUPLICATE_USER_NAME:
                    status = MembershipCreateStatus.DuplicateUserName;
                    break;

                //case KandaTableDataGateway.DUPLICATE_PROVIDER_USER_KEY:
                //    status = MembershipCreateStatus.DuplicateProviderUserKey;
                //    break;

                default:
                    break;
            }

            return false;

            //return (error == KandaTableDataGateway.NO_ERRORS);
        }
 /// <summary>
 /// コンストラクター。
 /// </summary>
 /// <param name="membership"></param>
 public KandaMembershipUser(MembershipEntity membership)
     : base(Membership.Provider.Name, membership.Name, membership.ID, membership.Email, @"", @"", membership.Enabled, false, membership.CreatedOn, default(DateTime), default(DateTime), default(DateTime), default(DateTime))
 {
     this.doNothing();
 }
        public void DeleteForeighKeyOnMembershipIDFact()
        {
            var connection = default(DbConnection);
            var transaction = default(DbTransaction);

            try
            {
                connection = this._factory.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction();

                // Memberships
                var membership = new MembershipEntity() { Name = new Random().Next().ToString(CultureInfo.InvariantCulture), Password = @"password", };
                var memberships = new MembershipsRepository();
                membership.CreatedOn = KandaRepository.GetUtcDateTime(connection, transaction);
                var status = MembershipCreateStatus.ProviderError;
                if (!memberships.Create(membership , connection, transaction, out status)) { Assert.True(!true); }

                // Users
                var user = new UserEntity() { /*ID = @"",*/ FamilyName = @"family name", GivenName = @"given name", AdditionalName = @"additional name", Description = @"description", CreatedOn = membership.CreatedOn, Enabled = true, };
                var users = new UsersRepository();
                if (!users.Create(user, connection, transaction)) { Assert.True(!true); }

                // MembershipUsers
                var entity = new MembershipUserEntity() { MembershipID = membership.ID, UserID = user.ID };
                var repository = new MembershipUsersRepository();
                if (!repository.Create(entity, connection, transaction)) { Assert.True(!true); }

                // 削除
                if (!repository.Delete(new MembershipUsersCriteria() { MembershipID = entity.MembershipID, UserID = entity.UserID, }, connection, transaction)) { Assert.True(!true); }
                if (!memberships.Delete(entity.MembershipID, connection, transaction)) { Assert.True(!true); }
                if (!users.Delete(entity.UserID, connection, transaction)) { Assert.True(!true); }

                Assert.True(true);
            }
            finally
            {
                if (transaction != null) { transaction.Rollback(); }
                if (connection != null) { connection.Close(); }
            }
        }