Exemple #1
0
 /// <summary>
 /// Constructor. Construct a user DAL object based on a mailAudit DB object.
 /// </summary>
 public LogonUserDal(logonuser user)
 {
     if (user.Id==0) {
         throw new ArgumentException("This constructor may only be used with existing 'logonuser' argument, which was retrieved from the database.");
     }
     _user = user;
 }
Exemple #2
0
 /// <summary>
 /// Return the address.
 /// </summary>
 public static string GetAddress(logonuser user)
 {
     if (user.PrimaryAddressId!=null && user.PrimaryAddressId!=0) {
         address primaryAddress = DB.address.Where(a => a.Id == user.PrimaryAddressId).FirstOrDefault();
         string address = "";
         if (!string.IsNullOrEmpty(primaryAddress.CompanyName)) {
             address += primaryAddress.CompanyName + "\n" + "T.a.v. ";
         }
         address += (user.Gender.HasValue ? (user.Gender.Value ? "Dhr." : "Mw.") : "")
             + " " + primaryAddress.Firstname + " " + primaryAddress.Insertion + " " + primaryAddress.Lastname + "\n"
             + primaryAddress.Street + " " + primaryAddress.Housenumber + " " + primaryAddress.HouseNumberAddition + "\n"
             + primaryAddress.PostalCode + " " + primaryAddress.City;
         return address;
     } else {
         return "Adres onbekend";
     }
 }
Exemple #3
0
        /// <summary>
        /// Creates a new logonuser, that is not active and with a random password stored in the comments.
        /// </summary>
        /// <param name="emailAddressAndUsername"></param>
        /// <param name="password"></param>
        /// <param name="externalSubscriptionIdentifier"></param>
        /// <returns></returns>
        public static LogonUserDal CreateOrRetrieveUser(string emailAddressAndUsername, string password="", string externalSubscriptionIdentifier = null)
        {
            // If an non 'HRE' external identifier (meaning a real ext. id) was given, then try to retrieve the user via this.
            if (!string.IsNullOrEmpty(externalSubscriptionIdentifier) && externalSubscriptionIdentifier!="HRE0" /* && !externalSubscriptionIdentifier.StartsWith("HRE") */) {
                int? userId = (from p in DB.sportseventparticipation where p.ExternalIdentifier == externalSubscriptionIdentifier select p.UserId).FirstOrDefault();
                if (userId.HasValue) {
                    logonuser u = (from logonUser in DB.logonuser where logonUser.Id==userId.Value select logonUser).FirstOrDefault();
                    if (u!=null) {
                        return new LogonUserDal(u);
                    }
                }
            }

            // Create the user for ASP.NET membership.
            MembershipUser membershipUser;

            string userName = Membership.GetUserNameByEmail(emailAddressAndUsername);
            if (!string.IsNullOrEmpty(userName)) {
                if (!string.IsNullOrEmpty(password)) {
                    throw new ArgumentException(string.Format("Supplying a password ({0}) for an already existing user ({1}) is NOT allowed!", password,emailAddressAndUsername));
                }
                membershipUser = Membership.GetUser(userName);
            } else {
                // If no password was supplied then use a temporary keyword.
                bool useTemporaryPassword = string.IsNullOrEmpty(password);
                if (useTemporaryPassword) {
                    password = Guid.NewGuid().ToString().Substring(0,7);
                }

                // Create a new user with a the password.
                MembershipCreateStatus createStatus;
                membershipUser = Membership.CreateUser(emailAddressAndUsername, password, emailAddressAndUsername, null, null, false, null, out createStatus);

                // Create the profile if the user was succesfully made.
                if (createStatus != MembershipCreateStatus.Success) {
                    throw new Exception(string.Format("Error while creating new user for {0}, createStatus: {1}", emailAddressAndUsername, createStatus));
                }

                membershipUser.IsApproved = !useTemporaryPassword;

                if (useTemporaryPassword) {
                    membershipUser.Comment = password;
                }
                Membership.UpdateUser(membershipUser);
            }

            // Create the logonuser.
            logonuser user = (from logonUser in DB.logonuser where logonUser.EmailAddress==membershipUser.Email select logonUser).FirstOrDefault();
            if (user==null) {
                user = new logonuser();
                user.UserName = emailAddressAndUsername;
                user.EmailAddress = emailAddressAndUsername;
                user.DateCreated = DateTime.Now;
                user.DateUpdated = user.DateCreated;
                DB.AddTologonuser(user);
            } else {
                user.DateUpdated = DateTime.Now;
            }
            user.ExternalId = membershipUser.ProviderUserKey.ToString();
            DB.SaveChanges();

            return new LogonUserDal(user);
        }
Exemple #4
0
 /// <summary>
 /// Constructor. Construct a user DAL object based on a mailAudit DB object.
 /// </summary>
 public LogonUserDal()
 {
     _user = new logonuser();
 }
Exemple #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the logonuser EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTologonuser(logonuser logonuser)
 {
     base.AddObject("logonuser", logonuser);
 }
Exemple #6
0
 /// <summary>
 /// Create a new logonuser object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="dateCreated">Initial value of the DateCreated property.</param>
 /// <param name="dateUpdated">Initial value of the DateUpdated property.</param>
 /// <param name="userName">Initial value of the UserName property.</param>
 public static logonuser Createlogonuser(global::System.Int32 id, global::System.DateTime dateCreated, global::System.DateTime dateUpdated, global::System.String userName)
 {
     logonuser logonuser = new logonuser();
     logonuser.Id = id;
     logonuser.DateCreated = dateCreated;
     logonuser.DateUpdated = dateUpdated;
     logonuser.UserName = userName;
     return logonuser;
 }