private static Signup_Result ValidationFailed(TMConfig config, NewUser newUser) { var sigupResponse = new Signup_Result(); var validationList = newUser.validate(); sigupResponse.Signup_Status = Signup_Result.SignupStatus.Validation_Failed; sigupResponse.UserCreated = 0; if (config.showDetailedErrorMessages()) { foreach (var validation in validationList) { var field = validation.MemberNames.FirstOrDefault(); sigupResponse.Validation_Results.Add(new Validation_Results { Field = field, Message = validation.ErrorMessage }); } } else sigupResponse.Simple_Error_Message = config.TMErrorMessages.General_SignUp_Error_Message; return sigupResponse; }
private static Signup_Result ValidateUserName(TMConfig config) { var signupResponse = new Signup_Result { Signup_Status = Signup_Result.SignupStatus.Validation_Failed, UserCreated = 0 }; if (config.showDetailedErrorMessages()) { signupResponse.Validation_Results.Add(new Validation_Results { Field = "Username", Message = TMConfig.Current.TMErrorMessages.SignUpUsernameAlreadyExist }); } else { signupResponse.Simple_Error_Message = config.TMErrorMessages.General_SignUp_Error_Message; } return signupResponse; }
private static Signup_Result GetErrorMessage(string field, string message) { var tmConfig = TMConfig.Current; var response = new Signup_Result { Signup_Status = Signup_Result.SignupStatus.Validation_Failed, UserCreated = 0 }; if (tmConfig.showDetailedErrorMessages()) response.Validation_Results.Add(new Validation_Results { Field = field, Message = message }); else response.Simple_Error_Message = tmConfig.TMErrorMessages.General_SignUp_Error_Message; return response; }
private static Signup_Result UserTags_Validation(TMConfig config, UserTag tag) { var signupResponse = new Signup_Result(); var validationList = tag.validate(); signupResponse.Signup_Status = Signup_Result.SignupStatus.Validation_Failed; signupResponse.UserCreated = 0; if (!config.showDetailedErrorMessages()) { signupResponse.Simple_Error_Message = config.TMErrorMessages.General_SignUp_Error_Message; } else { foreach (var validation in validationList) { signupResponse.Validation_Results.Add(new Validation_Results { Field = validation.ToString(), Message = validation.ErrorMessage }); } } return signupResponse; }
public static Signup_Result createTmUserResponse(this TM_UserData userData, NewUser newUser) { var sigupResponse = new Signup_Result(); var tmConfig = TMConfig.Current; // ensure the email is lowercase (will fail validation otherwise) if (newUser.isNull()) { userData.logTBotActivity("User Creation Fail", "TEAM Mentor user is null"); sigupResponse.Signup_Status = Signup_Result.SignupStatus.Signup_Error; sigupResponse.UserCreated = 0; sigupResponse.Simple_Error_Message = tmConfig.TMErrorMessages.General_SignUp_Error_Message; return sigupResponse; } newUser.Email = newUser.Email.lower(); //Validating if Username has not been already registered. if (newUser.Username.tmUser().notNull()) { userData.logTBotActivity("User Creation Fail", "Username ('{0}') already exist in TEAM Mentor".format(newUser.Username)); return GetErrorMessage("Username", tmConfig.TMErrorMessages.SignUpUsernameAlreadyExist); } //Email check (length, null, valid) if (newUser.Email.notNull() && newUser.Email.Length > 256) { userData.logTBotActivity("User Creation Fail", "Input rejected because email address ('{0}') is larger than 256 characters".format(newUser.Email)); return GetErrorMessage("Email", tmConfig.TMErrorMessages.Email_Address_Is_Invalid); } //Check email format if (newUser.valid_Email_Address().isFalse()) { userData.logTBotActivity("User Creation Fail", "Input rejected because email address ('{0}') is not valid".format(newUser.Email)); return GetErrorMessage("Email", tmConfig.TMErrorMessages.Email_Address_Is_Invalid); } if (newUser.Email.tmUser_FromEmail().notNull()) { userData.logTBotActivity("User Creation Fail", "Email ('{0}') already existed".format(newUser.Email)); return GetErrorMessage("Email",tmConfig.TMErrorMessages.SignUpEmailAlreadyExist); } //Validate Password Length. if (newUser.Password.Length < 8 || newUser.Password.Length> 256) { userData.logTBotActivity("User Creation Fail", "Password must be 8 to 256 character long but was {0}".format(newUser.Password.Length)); return GetErrorMessage("Password", tmConfig.TMErrorMessages.PasswordLengthErrorMessage); } //Password complexity if (!Regex.IsMatch(newUser.Password, ValidationRegex.PasswordComplexity)) { userData.logTBotActivity("User Creation Fail", "Password {0} does not meet complexity requirements.".format(newUser.Password)); return GetErrorMessage("Password", tmConfig.TMErrorMessages.PasswordComplexityErroMessage); } //validate user against the DataContract specificed in the NewUser class if (newUser.validation_Failed()) return ValidationFailed(tmConfig, newUser); if (newUser.UserTags.notEmpty()) foreach (var userTag in newUser.UserTags) if (userTag.validation_Failed()) { return UserTags_Validation(tmConfig, userTag); } // if there is a groupId provided we must check if the user has the manageUsers Priviledge if (newUser.GroupId != 0) UserRole.ManageUsers.demand(); var userCreated = userData.newUser(newUser.Username, newUser.Password, newUser.Email, newUser.Firstname, newUser.Lastname, newUser.Note, newUser.Title, newUser.Company, newUser.Country, newUser.State, newUser.UserTags, newUser.GroupId); if (userCreated > 0) { sigupResponse.UserCreated = userCreated; sigupResponse.Signup_Status = Signup_Result.SignupStatus.Signup_Ok; } else { userData.logTBotActivity("User Creation Fail", "Error occurred creating user".format(newUser.ToString())); sigupResponse.UserCreated = userCreated; sigupResponse.Signup_Status = Signup_Result.SignupStatus.Validation_Failed; sigupResponse.Simple_Error_Message = tmConfig.TMErrorMessages.General_SignUp_Error_Message; } return sigupResponse; }