示例#1
0
 /// <summary>
 /// default cast for Membership.GetUser method
 /// use to manage MembershipProvider that not returns PgnUser
 /// </summary>
 /// <param name="username"></param>
 /// <returns>PgnUser or null if not exists</returns>
 public static PgnUser GetUser(string username)
 {
     PgnUser user = null;
     var member = Membership.GetUser(username);
     if (member is PgnUser)
         user = (PgnUser)member;
     else
     {
         user = new PgnUser("PgnUserProvider",
             0, username, "", "", "", "", true, false,
             DateTime.MinValue, DateTime.MinValue, DateTime.MinValue,
             DateTime.MinValue, DateTime.MinValue);
     }
     return user;
 }
示例#2
0
        public PgnUser CreateUser(
                        PgnUser newUser,
                        string username,
                        string password,
                        string email,
                        string passwordQuestion,
                        string passwordAnswer,
                        bool isApproved,
                        object providerUserKey,
                        out MembershipCreateStatus status)
        {
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);
            OnValidatingPassword(args);
            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

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

            MembershipUser u = GetUser(username, false);

            if (u == null)
            {
                DateTime createDate = DateTime.Now;

                //use identity as pkey
                //if (providerUserKey == null)
                //{
                //    providerUserKey = Guid.NewGuid();
                //}
                //else
                //{
                //    if (!(providerUserKey is Guid))
                //    {
                //        status = MembershipCreateStatus.InvalidProviderUserKey;
                //        return null;
                //    }
                //}

                DbProviderFactory myProv = Database.ProviderFactory;
                DbConnection myConn = myProv.CreateConnection();
                DbCommand myCmd = myConn.CreateCommand();
                string sSql = "";

                try
                {
                    myConn.ConnectionString = connectionString;
                    myConn.Open();
                    myCmd.Connection = myConn;

                    //PKID
                    sSql = "INSERT INTO " + tableName + " "
                    + " (/*[Id],*/ Username, ApplicationName, Email, Comment, "
                    + " Password, PasswordQuestion, PasswordAnswer, IsApproved, "
                    + " LastActivityDate, LastPasswordChangedDate, CreationDate, "
                    + " IsLockedOut, LastLockedOutDate,"
                    + " FailedPasswordAttemptCount, FailedPasswordAttemptWindowStart, "
                    + " FailedPasswordAnswerAttemptCount, FailedPasswordAnswerAttemptWindowStart, "
                    + " Enabled, AccessCode, AccessLevel, "
                    + " Sex, CompanyName, Vat, Ssn, FirstName, SecondName, "
                    + " Address1, Address2, City, [State], ZipCode, "
                    + " Nation, Tel1, Mobile1, Website1, AllowMessages, AllowEmails, ValidationCode) "
                    + " Values(@Username, @ApplicationName, @Email, @Comment, "
                    + " @Password, @PasswordQuestion, @PasswordAnswer, @IsApproved, "
                    + " @LastActivityDate, @LastPasswordChangedDate, @CreationDate, "
                    + " @IsLockedOut, @LastLockedOutDate,"
                    + " @FailedPasswordAttemptCount, @FailedPasswordAttemptWindowStart, "
                    + " @FailedPasswordAnswerAttemptCount, @FailedPasswordAnswerAttemptWindowStart, "
                    + " @Enabled, @AccessCode, @AccessLevel, "
                    + " @Sex, @CompanyName, @Vat, @Ssn, @FirstName, @SecondName, "
                    + " @Address1, @Address2, @City, @State, @ZipCode, "
                    + " @Nation, @Tel1, @Mobile1, @Website1, @AllowMessages, @AllowEmails, @ValidationCode) ";
                    myCmd.CommandText = Database.ParseSql(sSql);

                    if (string.IsNullOrEmpty(username)) username = "";
                    if (string.IsNullOrEmpty(pApplicationName)) pApplicationName = "";
                    if (string.IsNullOrEmpty(email)) email = "";
                    if (string.IsNullOrEmpty(password)) password = "";
                    if (string.IsNullOrEmpty(passwordQuestion)) passwordQuestion = "";
                    if (string.IsNullOrEmpty(passwordAnswer)) passwordAnswer = "";

                    //cmd.Parameters.Add("@PKID", OdbcType.UniqueIdentifier).Value = providerUserKey;
                    myCmd.Parameters.Add(Database.Parameter(myProv, "Username", username));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "ApplicationName", pApplicationName));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "Email", email));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "Comment", ""));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "Password", encodePassword(password)));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "PasswordQuestion", passwordQuestion));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "PasswordAnswer", encodePassword(passwordAnswer)));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "IsApproved", isApproved));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "LastActivityDate", createDate));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "LastPasswordChangedDate", createDate));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "CreationDate", createDate));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "IsLockedOut", false));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "LastLockedOutDate", createDate));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "FailedPasswordAttemptCount", 0));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "FailedPasswordAttemptWindowStart", createDate));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "FailedPasswordAnswerAttemptCount", 0));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "FailedPasswordAnswerAttemptWindowStart", createDate));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "Enabled", newUser.Enabled));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "AccessCode", newUser.AccessCode));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "AccessLevel", newUser.AccessLevel));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "Sex", newUser.Sex));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "CompanyName", newUser.CompanyName));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "Vat", newUser.Vat));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "Ssn", newUser.Ssn));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "FirstName", newUser.FirstName));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "SecondName", newUser.SecondName));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "Address1", newUser.Address1));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "Address2", newUser.Address2));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "City", newUser.City));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "State", newUser.State));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "ZipCode", newUser.ZipCode));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "Nation", newUser.Nation));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "Tel1", newUser.Tel1));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "Mobile1", newUser.Mobile1));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "Website1", newUser.Website1));

                    myCmd.Parameters.Add(Database.Parameter(myProv, "AllowMessages", newUser.AllowMessages));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "AllowEmails", newUser.AllowEmails));
                    myCmd.Parameters.Add(Database.Parameter(myProv, "ValidationCode", newUser.ValidationCode));

                    int recAdded = myCmd.ExecuteNonQuery();
                    if (recAdded > 0)
                    {
                        status = MembershipCreateStatus.Success;
                    }
                    else
                    {
                        status = MembershipCreateStatus.UserRejected;
                    }
                }
                catch (Exception e)
                {
                    if (WriteExceptionsToEventLog)
                    {
                        writeToEventLog(e, "CreateUser");
                    }

                    status = MembershipCreateStatus.ProviderError;
                }
                finally
                {
                    myConn.Dispose();
                }

                return (PgnUser)GetUser(username, false);
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return null;
        }
示例#3
0
        public override MembershipUser CreateUser(string username,
                                          string password,
                                          string email,
                                          string passwordQuestion,
                                          string passwordAnswer,
                                          bool isApproved,
                                          object providerUserKey,
                                          out MembershipCreateStatus status)
        {
            var newUser = new PgnUser();

            return this.CreateUser(
                newUser,
                username,
                password,
                email,
                passwordQuestion,
                passwordAnswer,
                true,
                "",
                out status);
        }
示例#4
0
        protected PgnUser GetUserFromReader(DbDataReader myRd)
        {
            object providerUserKey = null; //= myRd.GetValue(0);
            int id = 0;
            string username = "";
            string email = "";
            string passwordQuestion = "";
            string comment = "";
            bool isApproved = false;
            bool isLockedOut = false;
            DateTime creationDate = new DateTime();
            DateTime lastLoginDate = new DateTime();
            DateTime lastActivityDate = new DateTime();
            DateTime lastPasswordChangedDate = new DateTime();
            DateTime lastLockedOutDate = new DateTime();
            bool enabled = false;
            string accessCode = "";
            int accessLevel = 0;
            bool isCore = false;
            //20111118
            string sex = "";
            string companyName = "";
            string vat = "";
            string ssn = "";
            string firstName = "";
            string secondName = "";
            string address1 = "";
            string address2 = "";
            string city = "";
            string state = "";
            string zipCode = "";
            string nation = "";
            string tel1 = "";
            string mobile1 = "";
            string website1 = "";
            //20120306
            bool allowMessages = false;
            bool allowEmails = false;
            //20150403
            string validationCode = "";

            if (!Convert.IsDBNull(myRd["Id"]))
                id = (int)myRd["Id"];
            if (!Convert.IsDBNull(myRd["Username"]))
                username = (string)myRd["Username"];
            if (!Convert.IsDBNull(myRd["Email"]))
                email = (string)myRd["Email"];
            if (!Convert.IsDBNull(myRd["PasswordQuestion"]))
                passwordQuestion = (string)myRd["PasswordQuestion"];
            if (!Convert.IsDBNull(myRd["Comment"]))
                comment = (string)myRd["Comment"];
            if (!Convert.IsDBNull(myRd["IsApproved"]))
                isApproved = (bool)myRd["IsApproved"];
            if (!Convert.IsDBNull(myRd["IsLockedOut"]))
                isLockedOut = (bool)myRd["IsLockedOut"];
            if (!Convert.IsDBNull(myRd["creationDate"]))
                creationDate = (DateTime)myRd["creationDate"];
            if (!Convert.IsDBNull(myRd["lastLoginDate"]))
                lastLoginDate = (DateTime)myRd["lastLoginDate"];
            if (!Convert.IsDBNull(myRd["lastActivityDate"]))
                lastActivityDate = (DateTime)myRd["lastActivityDate"];
            if (!Convert.IsDBNull(myRd["lastPasswordChangedDate"]))
                lastPasswordChangedDate = (DateTime)myRd["lastPasswordChangedDate"];
            if (!Convert.IsDBNull(myRd["lastLockedOutDate"]))
                lastLockedOutDate = (DateTime)myRd["lastLockedOutDate"];
            if (!Convert.IsDBNull(myRd["enabled"]))
                enabled = (bool)myRd["enabled"];
            if (!Convert.IsDBNull(myRd["accessCode"]))
                accessCode = (string)myRd["accessCode"];
            if (!Convert.IsDBNull(myRd["AccessLevel"]))
                accessLevel = (int)myRd["AccessLevel"];
            if (!Convert.IsDBNull(myRd["isCore"]))
                isCore = (bool)myRd["isCore"];
            if (!Convert.IsDBNull(myRd["allowMessages"]))
                allowMessages = (bool)myRd["allowMessages"];
            if (!Convert.IsDBNull(myRd["allowEmails"]))
                allowEmails = (bool)myRd["allowEmails"];

            if (!Convert.IsDBNull(myRd["sex"]))
                sex = (string)myRd["sex"];
            if (!Convert.IsDBNull(myRd["companyName"]))
                companyName = (string)myRd["companyName"];
            if (!Convert.IsDBNull(myRd["vat"]))
                vat = (string)myRd["vat"];
            if (!Convert.IsDBNull(myRd["ssn"]))
                ssn = (string)myRd["ssn"];
            if (!Convert.IsDBNull(myRd["firstName"]))
                firstName = (string)myRd["firstName"];
            if (!Convert.IsDBNull(myRd["secondName"]))
                secondName = (string)myRd["secondName"];
            if (!Convert.IsDBNull(myRd["address1"]))
                address1 = (string)myRd["address1"];
            if (!Convert.IsDBNull(myRd["address2"]))
                address2 = (string)myRd["address2"];
            if (!Convert.IsDBNull(myRd["city"]))
                city = (string)myRd["city"];
            if (!Convert.IsDBNull(myRd["state"]))
                state = (string)myRd["state"];
            if (!Convert.IsDBNull(myRd["zipCode"]))
                zipCode = (string)myRd["zipCode"];
            if (!Convert.IsDBNull(myRd["nation"]))
                nation = (string)myRd["nation"];
            if (!Convert.IsDBNull(myRd["tel1"]))
                tel1 = (string)myRd["tel1"];
            if (!Convert.IsDBNull(myRd["mobile1"]))
                mobile1 = (string)myRd["mobile1"];
            if (!Convert.IsDBNull(myRd["website1"]))
                website1 = (string)myRd["website1"];
            if (!Convert.IsDBNull(myRd["validationCode"]))
                validationCode = (string)myRd["validationCode"];

            string name = "PgnUserProvider";
            if (this.Name != null) name = this.Name;

            PgnUser u = new PgnUser(name,
                                  id,
                                  username,
                                  providerUserKey,
                                  email,
                                  passwordQuestion,
                                  comment,
                                  isApproved,
                                  isLockedOut,
                                  creationDate,
                                  lastLoginDate,
                                  lastActivityDate,
                                  lastPasswordChangedDate,
                                  lastLockedOutDate);
            u.Enabled = enabled;
            u.AccessCode = accessCode;
            u.AccessLevel = accessLevel;
            u.IsCore = isCore;
            u.AllowMessages = allowMessages;
            u.AllowEmails = allowEmails;

            u.Sex = sex;
            u.CompanyName = companyName;
            u.Vat = vat;
            u.Ssn = ssn;
            u.FirstName = firstName;
            u.SecondName = secondName;
            u.Address1 = address1;
            u.Address2 = address2;
            u.City = city;
            u.State = state;
            u.ZipCode = zipCode;
            u.Nation = nation;
            u.Tel1 = tel1;
            u.Mobile1 = mobile1;
            u.Website1 = website1;
            u.ValidationCode = validationCode;

            return u;
        }
    public void Obj2form()
    {
        PgnUser obj = null;
        obj = (PgnUser)Membership.GetUser(CurrentUser);
        if (obj == null)
            obj = new PgnUser();

        //insview

        //update
        LitUpdUserName.Text = obj.UserName;
        ChkUpdEnabled.Checked = obj.Enabled;
        ChkUpdApproved.Checked = obj.IsApproved;
        TxtUpdEmail.Text = obj.Email;
        TxtUpdComment.Text = obj.Comment;
        TxtUpdAccessCode.Text = obj.AccessCode;
        TxtUpdAccessLevel.Text = obj.AccessLevel.ToString();
        TxtUpdCompanyName.Text = obj.CompanyName;
        TxtUpdVat.Text = obj.Vat;
        TxtUpdSsn.Text = obj.Ssn;
        TxtUpdFirstName.Text = obj.FirstName;
        TxtUpdSecondName.Text = obj.SecondName;
        TxtUpdAddress1.Text = obj.Address1;
        TxtUpdAddress2.Text = obj.Address2;
        TxtUpdCity.Text = obj.City;
        TxtUpdState.Text = obj.State;
        TxtUpdZipCode.Text = obj.ZipCode;
        Utility.SetDropByValue(DropUpdNation, obj.Nation);
        TxtUpdTel1.Text = obj.Tel1;
        TxtUpdMobile1.Text = obj.Mobile1;
        TxtUpdWebsite1.Text = obj.Website1;
        ChkUpdAllowMessages.Checked = obj.AllowMessages;
        ChkUpdAllowEmails.Checked = obj.AllowEmails;

        LitPwdUsername.Text = obj.UserName;

        PgnUserHelper.LoadListRolesInUser(ListRolesInUser, CurrentUser);
        PgnUserHelper.LoadListRolesNotInUser(ListRolesNotInUser, CurrentUser);
        //load hidden field with current users in rol
        HiddenRolesInUser.Value = "";
        foreach (ListItem item in ListRolesInUser.Items)
        {
            HiddenRolesInUser.Value += item.Value + "|";
        }
        if (HiddenRolesInUser.Value.Length > 0)
            HiddenRolesInUser.Value =
                HiddenRolesInUser.Value.Remove(HiddenRolesInUser.Value.Length - 1);
    }
 //CHECK
 public override MembershipUser GetUser(string username, bool userIsOnline)
 {
     var res = new PgnUser(providerName, 0, username, "", "", "", "", true, false,
         DateTime.MinValue, DateTime.MinValue, DateTime.MinValue,
         DateTime.MinValue, DateTime.MinValue);
     return res;
 }