コード例 #1
0
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            var args = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (this.RequiresUniqueEmail &&
                !this.GetUserNameByEmail(email).IsEmpty())
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            var membershipUser = this.GetUser(username, false);

            if (membershipUser == null)
            {
                User user = new User
                {
                    Name = username
                };

                string token = null;
                object dbtoken = DBNull.Value;

                if (this.RequireConfirmationToken)
                {
                    token = SecurityHelper.GenerateToken();
                    dbtoken = token;
                }

                Membership membership = new Membership
                {
                    Email = email,
                    IsApproved = isApproved,
                    Password = SecurityHelper.EncodePassword(password),
                    PasswordQuestion = passwordQuestion,
                    PasswordAnswer = passwordAnswer,
                    ConfirmationToken = dbtoken.ToString()
                };

                int createdResult = this.DbProvider.CreateUser(user, membership);
                
                status = createdResult > 0 ? MembershipCreateStatus.Success : MembershipCreateStatus.UserRejected;

                return this.GetUser(username, false);
            }

            status = MembershipCreateStatus.DuplicateUserName;

            return null;
        }
コード例 #2
0
        public virtual MembershipUser CreateUser(string username, string password, string cellPhoneNo, out MembershipCreateStatus status)
        {
            var args = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);
            
            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (this.RequiresUniqueCellPhoneNo &&
                !this.GetUserNameByCellPhoneNo(cellPhoneNo).IsEmpty())
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            var membershipUser = this.GetUser(username, false);

            if (membershipUser == null)
            {
                User user = new User
                {
                    Name = username
                };

                string token = null;
                object dbtoken = DBNull.Value;

                if (this.RequireConfirmationToken)
                {
                    token = SecurityHelper.GenerateToken();
                    dbtoken = token;
                }

                Membership membership = new Membership
                {
                    CellPhoneNo = cellPhoneNo,
                    IsApproved = true,
                    Password = SecurityHelper.EncodePassword(password),
                    ConfirmationToken = dbtoken.ToString()
                };

                int createdResult = this.DbProvider.CreateUser(user, membership);

                status = createdResult > 0 ? MembershipCreateStatus.Success : MembershipCreateStatus.UserRejected;

                return this.GetUser(username, false);
            }

            status = MembershipCreateStatus.DuplicateUserName;

            return null;
        }
コード例 #3
0
ファイル: AccountDbProvider.cs プロジェクト: tu226/Eagle
        /// <summary>
        /// Add a new account in membership
        /// </summary>
        public virtual int CreateUser(User user, Membership membership)
        {
            using (IDbConnection dbConnection = this.CreateDbConnection())
            {
                dbConnection.Open();

                using (IDbTransaction dbTransaction = dbConnection.BeginTransaction())
                {
                    try
                    {
                        IEnumerable<dynamic> insertedUserIds = dbConnection.Query(this.UserInsertSql, new { user.Name }, dbTransaction);

                        var newUserIdEntity = insertedUserIds.SingleOrDefault();

                        if (newUserIdEntity != null)
                        {
                            int newUserId = Convert.ToInt32(newUserIdEntity.NewUserId);

                            int insertedMembership = dbConnection.Execute(this.MembershipInsertSql,
                                                                                new
                                                                                {
                                                                                    UserId = newUserId,
                                                                                    Email = membership.Email,
                                                                                    CellPhoneNo = membership.CellPhoneNo,
                                                                                    Password = membership.Password,
                                                                                    PasswordQuestion = membership.PasswordQuestion,
                                                                                    PasswordAnswer = membership.PasswordAnswer,
                                                                                    ConfirmationToken = membership.ConfirmationToken,
                                                                                    IsApproved = membership.IsApproved
                                                                                },
                                                                                dbTransaction);
                        }

                        dbTransaction.Commit();

                        return 1;
                    }
                    catch
                    {
                        dbTransaction.Rollback();

                        return -1;
                    }
                    finally
                    {
                        if (dbConnection.State != ConnectionState.Closed)
                        {
                            dbConnection.Close();
                        }
                    }
                }
            }
        }