Esempio n. 1
0
        public static int           createTmUser(this TM_UserData userData, NewUser newUser)
        {
            if (newUser.isNull())
            {
                return(0);
            }

            // ensure the email is lowercase (will fail validation otherwise)
            newUser.Email = newUser.Email.lower();

            //validate user against the DataContract specificed in the NewUser class
            if (newUser.validation_Failed())
            {
                return(0);
            }
            if (newUser.UserTags.notEmpty())
            {
                foreach (var userTag in newUser.UserTags)
                {
                    if (userTag.validation_Failed())
                    {
                        return(0);
                    }
                }
            }
            // if there is a groupId provided we must check if the user has the manageUsers Priviledge
            if (newUser.GroupId != 0)
            {
                UserRole.ManageUsers.demand();
            }

            // Check if there is already a user with the provided username or email
            if (newUser.Username.tmUser().notNull() || newUser.Email.tmUser_FromEmail().notNull())
            {
                userData.logTBotActivity("User Creation Fail", "Username ('{0}') or Email ('{1})already existed".format(newUser.Username, newUser.Email));
                return(0);
            }

            // Create user

            return(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));
        }
Esempio n. 2
0
        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);
        }