protected static bool CheckAge(RegistrationData data) { bool valid_age = false; int regMinAge = 0; int regMaxAge = 0; // if invitation is being used then get associated role; then check age range based on role if (!String.IsNullOrEmpty(data.invite_code)) { qPtl_Invitation invite = new qPtl_Invitation(data.invite_code); if (invite != null) { if (invite.RoleID > 0) { qPtl_Role role = new qPtl_Role(invite.RoleID); if (role != null) { if (role.RoleName.Contains("Teen")) // use teen age ELSE assume adult user { regMinAge = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Register_MinAge"]); regMaxAge = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Register_TeenMaxAge"]); } else { regMinAge = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Register_TeenMaxAge"]) + 1; regMaxAge = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Register_MaxAge"]); } } } } } else { regMinAge = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Register_MinAge"]); regMaxAge = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Register_MaxAge"]); } try { DateTime DOB = Convert.ToDateTime(data.dob); DateTime currDate = DateTime.Now; int numYears = 0; try { TimeSpan age = currDate.Subtract(DOB); numYears = (age.Days / 365); } catch { valid_age = false; } if (numYears >= regMinAge && numYears <= regMaxAge) { valid_age = true; } else { valid_age = false; } } catch { valid_age = false; } return(valid_age); }
protected static bool CheckAge(RegistrationData data) { bool valid_age = false; int regMinAge = 0; int regMaxAge = 0; // if invitation is being used then get associated role; then check age range based on role if (!String.IsNullOrEmpty(data.invite_code)) { qPtl_Invitation invite = new qPtl_Invitation(data.invite_code); if (invite != null) { if (invite.RoleID > 0) { qPtl_Role role = new qPtl_Role(invite.RoleID); if (role != null) { if (role.RoleName.Contains("Teen")) // use teen age ELSE assume adult user { regMinAge = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Register_MinAge"]); regMaxAge = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Register_TeenMaxAge"]); } else { regMinAge = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Register_TeenMaxAge"]) + 1; regMaxAge = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Register_MaxAge"]); } } } } } else { regMinAge = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Register_MinAge"]); regMaxAge = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Register_MaxAge"]); } try { DateTime DOB = Convert.ToDateTime(data.dob); DateTime currDate = DateTime.Now; int numYears = 0; try { TimeSpan age = currDate.Subtract(DOB); numYears = (age.Days / 365); } catch { valid_age = false; } if (numYears >= regMinAge && numYears <= regMaxAge) { valid_age = true; } else { valid_age = false; } } catch { valid_age = false; } return valid_age; }
public static qPtl_User RegisterNewUser(RegistrationData data) { int existing_user_id = 0; int new_space_id = 0; string sqlCode = string.Empty; // Redundancy check -- write Highest Level into qPtl_User table in case DB trigger not working qPtl_Role role = new qPtl_Role(data.default_role_id); // add user qPtl_User new_user = new qPtl_User(); new_user.Available = "Yes"; new_user.OrgUnitID = data.scope_id; new_user.ScopeID = data.scope_id; new_user.Created = DateTime.Now; new_user.CreatedBy = 0; new_user.LastModified = DateTime.Now; new_user.LastModifiedBy = 0; new_user.MarkAsDelete = 0; new_user.Status = ""; // used to include a default message for their status, now leave blank new_user.FirstName = data.firstname; new_user.LastName = data.lastname; new_user.Email = data.email; new_user.UserName = data.username; string password_for_storing = FormsAuthentication.HashPasswordForStoringInConfigFile(data.password, "sha1"); new_user.Password = password_for_storing; new_user.AccountStatus = "Active"; new_user.HighestRank = role.RoleRank; new_user.HighestRole = role.RoleName; new_user.Insert(); existing_user_id = new_user.UserID; DateTime DOB; try { DOB = Convert.ToDateTime(data.dob); } catch { // no valid date so use default value DOB = Convert.ToDateTime("1/1/1900"); } // add user profile qPtl_UserProfile new_profile = new qPtl_UserProfile(); new_profile.UserID = existing_user_id; new_profile.ScopeID = data.scope_id; new_profile.Available = "Yes"; new_profile.Created = DateTime.Now; new_profile.CreatedBy = existing_user_id; new_profile.LastModified = DateTime.Now; new_profile.LastModifiedBy = existing_user_id; new_profile.MarkAsDelete = 0; new_profile.Style = "default"; new_profile.Visibility = "all"; new_profile.Division = data.division; new_profile.Agency = data.agency; new_profile.Position = data.position; new_profile.Degrees = data.degrees; new_profile.Address1 = data.address; new_profile.Address2 = data.address2; new_profile.City = data.city; new_profile.StateProvince = data.state; new_profile.PostalCode = data.postal_code; new_profile.Country = data.country; new_profile.Gender = data.gender; new_profile.DOB = DOB; new_profile.Race = data.race; new_profile.EmploymentLocation = data.employment_location; new_profile.EmploymentSetting = data.employment_setting; new_profile.WorkSites = data.employment_sites; new_profile.Profession = data.profession; new_profile.Phone1 = data.work_phone; new_profile.Phone1Type = "work"; new_profile.Insert(); qPtl_User user = new qPtl_User(existing_user_id); // add user communication preference if (!String.IsNullOrEmpty(user.Email)) { qCom_UserPreference connect = new qCom_UserPreference(); connect.UserID = user.UserID; connect.Created = DateTime.Now; connect.CreatedBy = user.UserID; connect.LastModified = DateTime.Now; connect.LastModifiedBy = user.UserID; connect.Available = "Yes"; connect.ScopeID = 1; connect.MarkAsDelete = 0; connect.OkBulkEmail = "Yes"; connect.OkEmail = "Yes"; connect.OkSms = "Yes"; connect.LanguageID = 1; connect.Insert(); } // **************************************************** // STEP 5: Add User Role & Supporting Role Structures // Add role /* * qPtl_UserRole role = new qPtl_UserRole(); * role.UserID = user.UserID; * role.RoleID = role_id; * role.Insert(); */ qDbs_SQLcode sql = new qDbs_SQLcode(); sqlCode = "INSERT INTO qPtl_UserRoles ([UserID],[RoleID]) VALUES(" + user.UserID + "," + data.default_role_id + ")"; sql.ExecuteSQL(sqlCode); // Add possible role actions for the new user role AddRoleAction(data.default_role_id, data.scope_id, user); // add folder for user_data string rootLocation = HttpContext.Current.Server.MapPath("~/") + "user_data\\"; if (!Directory.Exists(rootLocation + user.UserName)) { Directory.CreateDirectory(rootLocation + user.UserName); } if (new_user.UserID > 0) { return(new_user); } else { return(null); } }
public static qPtl_User RegisterNewUser(RegistrationData data) { int existing_user_id = 0; int new_space_id = 0; string sqlCode = string.Empty; // Redundancy check -- write Highest Level into qPtl_User table in case DB trigger not working qPtl_Role role = new qPtl_Role(data.default_role_id); // add user qPtl_User new_user = new qPtl_User(); new_user.Available = "Yes"; new_user.OrgUnitID = data.scope_id; new_user.ScopeID = data.scope_id; new_user.Created = DateTime.Now; new_user.CreatedBy = 0; new_user.LastModified = DateTime.Now; new_user.LastModifiedBy = 0; new_user.MarkAsDelete = 0; new_user.Status = ""; // used to include a default message for their status, now leave blank new_user.FirstName = data.firstname; new_user.LastName = data.lastname; new_user.Email = data.email; new_user.UserName = data.username; string password_for_storing = FormsAuthentication.HashPasswordForStoringInConfigFile(data.password, "sha1"); new_user.Password = password_for_storing; new_user.AccountStatus = "Active"; new_user.HighestRank = role.RoleRank; new_user.HighestRole = role.RoleName; new_user.Insert(); existing_user_id = new_user.UserID; DateTime DOB; try { DOB = Convert.ToDateTime(data.dob); } catch { // no valid date so use default value DOB = Convert.ToDateTime("1/1/1900"); } // add user profile qPtl_UserProfile new_profile = new qPtl_UserProfile(); new_profile.UserID = existing_user_id; new_profile.ScopeID = data.scope_id; new_profile.Available = "Yes"; new_profile.Created = DateTime.Now; new_profile.CreatedBy = existing_user_id; new_profile.LastModified = DateTime.Now; new_profile.LastModifiedBy = existing_user_id; new_profile.MarkAsDelete = 0; new_profile.Style = "default"; new_profile.Visibility = "all"; new_profile.Division = data.division; new_profile.Agency = data.agency; new_profile.Position = data.position; new_profile.Degrees = data.degrees; new_profile.Address1 = data.address; new_profile.Address2 = data.address2; new_profile.City = data.city; new_profile.StateProvince = data.state; new_profile.PostalCode = data.postal_code; new_profile.Country = data.country; new_profile.Gender = data.gender; new_profile.DOB = DOB; new_profile.Race = data.race; new_profile.EmploymentLocation = data.employment_location; new_profile.EmploymentSetting = data.employment_setting; new_profile.WorkSites = data.employment_sites; new_profile.Profession = data.profession; new_profile.Phone1 = data.work_phone; new_profile.Phone1Type = "work"; new_profile.Insert(); qPtl_User user = new qPtl_User(existing_user_id); // add user communication preference if (!String.IsNullOrEmpty(user.Email)) { qCom_UserPreference connect = new qCom_UserPreference(); connect.UserID = user.UserID; connect.Created = DateTime.Now; connect.CreatedBy = user.UserID; connect.LastModified = DateTime.Now; connect.LastModifiedBy = user.UserID; connect.Available = "Yes"; connect.ScopeID = 1; connect.MarkAsDelete = 0; connect.OkBulkEmail = "Yes"; connect.OkEmail = "Yes"; connect.OkSms = "Yes"; connect.LanguageID = 1; connect.Insert(); } // **************************************************** // STEP 5: Add User Role & Supporting Role Structures // Add role /* qPtl_UserRole role = new qPtl_UserRole(); role.UserID = user.UserID; role.RoleID = role_id; role.Insert(); */ qDbs_SQLcode sql = new qDbs_SQLcode(); sqlCode = "INSERT INTO qPtl_UserRoles ([UserID],[RoleID]) VALUES(" + user.UserID + "," + data.default_role_id + ")"; sql.ExecuteSQL(sqlCode); // Add possible role actions for the new user role AddRoleAction(data.default_role_id, data.scope_id, user); // add folder for user_data string rootLocation = HttpContext.Current.Server.MapPath("~/") + "user_data\\"; if (!Directory.Exists(rootLocation + user.UserName)) Directory.CreateDirectory(rootLocation + user.UserName); if (new_user.UserID > 0) return new_user; else return null; }