/// <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>();
 }
Beispiel #2
0
        private bool CheckPassword(MembershipEntity membership, string password)
        {
            if (!Crypto.VerifyHashedPassword(membership.Password, password))
            {
                membership.LastPasswordFailureDateUtc = DateTime.UtcNow;
                membership.PasswordFailuresSinceLastSuccess++;

                if (membership.PasswordFailuresSinceLastSuccess > MaxInvalidPasswordAttempts && membership.LastPasswordFailureDateUtc.GetValueOrDefault().Add(TimeSpan.FromSeconds(PasswordAttemptWindow)) > DateTime.UtcNow)
                {
                    membership.IsLocked = true;
                }

                _membershipService.Save(membership, false);

                return(false);
            }

            if (membership.IsLocked.GetValueOrDefault() && membership.LastPasswordFailureDateUtc.GetValueOrDefault().Add(TimeSpan.FromSeconds(PasswordAttemptWindow)) <= DateTime.UtcNow)
            {
                membership.IsLocked = false;
            }

            membership.PasswordFailuresSinceLastSuccess = 0;

            _membershipService.Save(membership, false);

            return(true);
        }
Beispiel #3
0
        public AppMembershipModel GetAppMembership(Guid userId)
        {
            MembershipEntity   membershipEntity = membershipRepository.GetMembershipEntity(userId);
            AppMembershipModel membershipModel  = mapper.Map <AppMembershipModel>(membershipEntity);

            return(membershipModel);
        }
        private void LoadData()
        {
            if (IsLoad)
            {
                if (!string.IsNullOrEmpty(Width))
                {
                    GridDiv.Style.Add("width", Width);
                }

                MembershipEntity member = (MembershipEntity)Session["Member"];

                NameTextBox.Text = member.UserName;
                if (member.StoreInformation != null)
                {
                    AuthorizedNameTextBox.Text = member.StoreInformation.AuthorizedName;
                    TelephoneTextBox.Text      = member.StoreInformation.Telephone;
                    post.Text              = member.StoreInformation.Address;//Post = Address
                    EmailTextBox.Text      = member.StoreInformation.Email;
                    WebAddressTextBox.Text = member.StoreInformation.WebAddress;
                }


                CitiesDropDownList.DataSource     = new CityAdapter().GetCities();
                CitiesDropDownList.DataTextField  = "Name";
                CitiesDropDownList.DataValueField = "Id";
                CitiesDropDownList.DataBind();
                if (member.StoreInformation != null)
                {
                    CitiesDropDownList.SelectedValue = member.StoreInformation.CityId.ToString();
                }
            }
        }
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            MembershipEntity member = (MembershipEntity)Session["Member"];

            member.UserName = NameTextBox.Text;
            if (member.StoreInformation != null)
            {
                member.StoreInformation.AuthorizedName = AuthorizedNameTextBox.Text;
                member.StoreInformation.CityId         = Convert.ToInt32(CitiesDropDownList.SelectedValue);
                member.StoreInformation.Address        = post.Text;
                member.StoreInformation.WebAddress     = WebAddressTextBox.Text;
                member.StoreInformation.Email          = EmailTextBox.Text;
                member.StoreInformation.Telephone      = TelephoneTextBox.Text;
                member.StoreInformationId = member.StoreInformation.Id;
            }
            else
            {
                member.StoreInformation = new StoreInformationEntity();
                member.StoreInformation.AuthorizedName = AuthorizedNameTextBox.Text;
                member.StoreInformation.CityId         = Convert.ToInt32(CitiesDropDownList.SelectedValue);
                member.StoreInformation.Address        = post.Text;
                member.StoreInformation.WebAddress     = WebAddressTextBox.Text;
                member.StoreInformation.Email          = EmailTextBox.Text;
                member.StoreInformation.Telephone      = TelephoneTextBox.Text;

                member.StoreInformation.Save();
            }

            Session["Member"] = new MemberShipAdapter().UpdateMember(member);
        }
Beispiel #6
0
        /// <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);
        }
Beispiel #7
0
        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,
                };
        public void ChangeStoreStatus(int id, bool status)
        {
            MembershipEntity membership = new MembershipEntity(id);

            membership.Status = status;

            membership.Save();
        }
        //return membership records by id
        public MembershipEntity GetMembershipEntity(Guid UserId)
        {
            AspnetMembership MembershipModel   = checkNetDbContext.AspnetMembership.Find(UserId);
            MembershipEntity MembershiprEntity = MembershipFactory.Create(MembershipModel.ApplicationId, MembershipModel.UserId, MembershipModel.Password, MembershipModel.PasswordSalt, MembershipModel.Email
                                                                          , MembershipModel.PasswordQuestion, MembershipModel.PasswordAnswer, MembershipModel.CreateDate, MembershipModel.LastLoginDate, MembershipModel.Comment);

            return(MembershiprEntity);
        }
        /// <summary>Creates a new, empty MembershipEntity object.</summary>
        /// <returns>A new, empty MembershipEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new MembershipEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewMembership
            // __LLBLGENPRO_USER_CODE_REGION_END
            return(toReturn);
        }
Beispiel #11
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            MembershipEntity member = (MembershipEntity)Session["Member"];

            member.UserName = UserNameTextBox.Text;
            member.Password = ProductSearchEngine.Business.Encryption.SHA1Encryption.EncryptMessage(ConfirmPasswordTextBox.Text);
            new ProductSearchEngine.Business.Adapters.MemberShipAdapter().UpdateMember(member);
        }
Beispiel #12
0
        public async Task SelectAsyncFact()
        {
            var connection  = this.Factory.CreateConnection();
            var transaction = default(DbTransaction);
            var token       = CancellationToken.None;

            try
            {
                connection.Open();
                transaction = connection.BeginTransaction(IsolationLevel.Serializable);

                // 登録
                var entity = new MembershipEntity()
                {
                    ID        = 0,
                    Name      = string.Format("MembershipsGatewayFacts.FindAsyncFact(new MembershipEntity {{ Name={0} }}) ", new Random().Next()),
                    Password  = @"password",
                    Enabled   = true,
                    Email     = @"*****@*****.**",
                    CreatedOn = DateTime.Now,
                    // UpdatedOn = CreatedOn,
                };
                var inserted = await MembershipsGateway.InsertAsync(entity, connection, transaction, token);

                Assert.True(0 < inserted);

                // 取得
                var criteria = new MembershipsCriteria()
                {
                    ID = inserted,
                };
                var selected = await MembershipsGateway.SelectAsync(criteria, connection, transaction, token);

                Assert.True(selected.Read());
                selected.Close();

                // 削除
                var deleted = await MembershipsGateway.DeleteAsync(inserted, connection, transaction, token);

                Assert.True(deleted == 1);

                transaction.Commit();
            }
            catch
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
Beispiel #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MembershipEntity member = (MembershipEntity)Session["Member"];

                UserNameTextBox.Text = member.UserName;
            }
        }
        public MembershipEntity MakeMembershipResult(SqlDataReader reader)
        {
            var model = new MembershipEntity();

            if (reader.ColumnExists(MemberShipParameters.Id))
            {
                model.ID = reader[MemberShipParameters.Id] is DBNull
                ? 0
                : Convert.ToInt32(reader[MemberShipParameters.Id], CultureInfo.CurrentCulture);
            }

            if (reader.ColumnExists(MemberShipParameters.Name))
            {
                model.Name = reader[MemberShipParameters.Name] is DBNull
                ? string.Empty
                : reader[MemberShipParameters.Name].ToString();
            }

            if (reader.ColumnExists(MemberShipParameters.MaxbookAmount))
            {
                model.MaxbookAmount = reader[MemberShipParameters.MaxbookAmount] is DBNull
                ? 0
                : Convert.ToInt32(reader[MemberShipParameters.MaxbookAmount], CultureInfo.CurrentCulture);
            }

            if (reader.ColumnExists(MemberShipParameters.MonthPlan))
            {
                model.MonthPlan = reader[MemberShipParameters.MonthPlan] is DBNull
                ? 0
                : Convert.ToInt32(reader[MemberShipParameters.MonthPlan], CultureInfo.CurrentCulture);
            }

            if (reader.ColumnExists(MemberShipParameters.PricePerMonth))
            {
                model.PricePerMonth = reader[MemberShipParameters.PricePerMonth] is DBNull
                ? 0
                : Convert.ToDecimal(reader[MemberShipParameters.PricePerMonth], CultureInfo.CurrentCulture);
            }

            if (reader.ColumnExists(MemberShipParameters.OverdueDayLimit))
            {
                model.OverdueDayLimit = reader[MemberShipParameters.OverdueDayLimit] is DBNull
                ? 0
                : Convert.ToInt32(reader[MemberShipParameters.OverdueDayLimit], CultureInfo.CurrentCulture);
            }

            if (reader.ColumnExists(MemberShipParameters.OverdueFees))
            {
                model.OverdueFees = reader[MemberShipParameters.OverdueFees] is DBNull
                ? 0
                : Convert.ToDecimal(reader[MemberShipParameters.OverdueFees], CultureInfo.CurrentCulture);
            }

            return(model);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="connection"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public bool Create(MembershipEntity entity, DbConnection connection, DbTransaction transaction)
        {
            if (entity.ID <= 0)
            {
                entity.ID = MembershipsGateway.SelectNextID(connection, transaction);
            }

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

            return(created == 1);
        }
        // membership //////////////////////////////////////////////////////

        public virtual void CreateMembership(string userId, string groupId)
        {
            CheckAuthorization(Permissions.Create, Resources.GroupMembership, groupId);
            IUser            user       = FindUserById(userId);
            IGroup           group      = FindGroupById(groupId);
            MembershipEntity membership = new MembershipEntity();

            membership.UserId  = user.Id;
            membership.GroupId = group.Id;
            CommandContext.GetDbEntityManager <MembershipEntity>().Add(membership);
            CreateDefaultMembershipAuthorizations(userId, groupId);
        }
        // return all membership records
        public List <MembershipEntity> GetMembershipEntities()
        {
            List <AspnetMembership> MembershipEntitiesModels = checkNetDbContext.AspnetMembership.ToList();
            List <MembershipEntity> MembershipEntities       = new List <MembershipEntity>();

            foreach (AspnetMembership appmember in MembershipEntitiesModels)
            {
                MembershipEntity membershipEntity = MembershipFactory.Create(appmember.ApplicationId, appmember.UserId, appmember.Password, appmember.PasswordSalt, appmember.Email
                                                                             , appmember.PasswordQuestion, appmember.PasswordAnswer, appmember.CreateDate, appmember.LastLoginDate, appmember.Comment);
                MembershipEntities.Add(membershipEntity);
            }
            return(MembershipEntities);
        }
        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);
        }
Beispiel #19
0
        public Boolean checkPasswordQuestion(Guid UserId, string answer)
        {
            MembershipEntity membershipEntity       = membershipRepository.GetMembershipEntity(UserId);
            string           passwordQuestionAnswer = membershipEntity.PasswordAnswer;
            HashAlgorithm    algorithm          = HashAlgorithm.Create("SHA1");
            string           passwordAnswerHash = Convert.ToBase64String(algorithm.ComputeHash(Encoding.Unicode.GetBytes(answer)));

            if (passwordAnswerHash.Equals(passwordQuestionAnswer))
            {
                return(true);
            }
            return(false);
        }
Beispiel #20
0
        // membership //////////////////////////////////////////////////////

        public virtual IdentityOperationResult createMembership(string userId, string groupId)
        {
            checkAuthorization(Permissions.CREATE, Resources.GROUP_MEMBERSHIP, groupId);
            UserEntity       user       = findUserById(userId);
            GroupEntity      group      = findGroupById(groupId);
            MembershipEntity membership = new MembershipEntity();

            membership.User  = user;
            membership.Group = group;
            DbEntityManager.insert(membership);
            createDefaultMembershipAuthorizations(userId, groupId);
            return(new IdentityOperationResult(null, IdentityOperationResult.OPERATION_CREATE));
        }
        public void SetRole(Panel AdminPanel, Panel StorePanel, object m)
        {
            MembershipEntity member = (MembershipEntity)m;

            if (member.RoleId == (int)Enums.MembershipRoles.Admin)
            {
                AdminPanel.Visible = true;
                StorePanel.Visible = false;
            }
            else
            {
                AdminPanel.Visible = false;
                StorePanel.Visible = true;
            }
        }
Beispiel #22
0
        /// <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);
        }
Beispiel #23
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());
        }
Beispiel #24
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();
                }
            }
        }
        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));
        }
Beispiel #26
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());
        }
        public static MembershipEntity Create(Guid AppId, Guid UserId, string Password, string PasswordSalt, string Email, string PasswordQuestion, string PasswordAnswer, DateTime createDate, DateTime LastLoginDate, string Comment)
        {
            MembershipEntity membership = new MembershipEntity()
            {
                ApplicationId    = AppId,
                UserId           = UserId,
                Password         = Password,
                PasswordSalt     = PasswordSalt,
                Email            = Email,
                PasswordQuestion = PasswordQuestion,
                PasswordAnswer   = PasswordAnswer,
                CreateDate       = createDate,
                LastLoginDate    = LastLoginDate,
                Comment          = Comment,
                //AppUser = AppUser
            };

            return(membership);
        }
        /// <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);
        }
Beispiel #29
0
        /// <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);
        }
Beispiel #30
0
        //public ProductCollection SortProductsByRate(ProductCollection productList, bool isAscending)
        //{

        //}

        public ProductCollection GetLast5AddedProducts(object m)
        {
            MembershipEntity   member    = new MembershipEntity(3);
            ProductCollection  products  = new ProductCollection();
            RelationCollection relations = new RelationCollection();

            relations.Add(ProductEntity.Relations.StoreEntityUsingStoreId);
            relations.Add(StoreEntity.Relations.MembershipEntityUsingMembershipId);

            IPrefetchPath prefatchPath = new PrefetchPath((int)EntityType.ProductEntity);

            prefatchPath.Add(ProductEntity.PrefetchPathStore).SubPath.Add(StoreEntity.PrefetchPathMembership);

            PredicateExpression filter = new PredicateExpression();

            filter.Add(MembershipFields.Id == member.Id);

            SortExpression sorter = new SortExpression();

            sorter.Add(ProductFields.AddedDate | SortOperator.Descending);
            products.GetMulti(filter, 5, sorter, relations, prefatchPath);

            return(products);
        }