Ejemplo n.º 1
0
        public HttpResponse Register(RegisterInputModel input)
        {
            if (string.IsNullOrEmpty(input.Username) || input.Username.Length < 5 || input.Username.Length > 20)
            {
                return(this.Error("Username is required and should be between 5 and 20 characters."));
            }

            if (!this.usersService.IsUsernameAvailable(input.Username))
            {
                return(this.Error("Username already taken."));
            }

            if (string.IsNullOrEmpty(input.Email))
            {
                return(this.Error("Invalid email address."));
            }

            if (!this.usersService.IsEmailAvailable(input.Email))
            {
                return(this.Error("Email already taken."));
            }

            if (string.IsNullOrEmpty(input.Password) || input.Password.Length < 6 || input.Password.Length > 20)
            {
                return(this.Error("Password should be between 6 and 20 charaters."));
            }

            if (input.Password != input.ConfirmPassword)
            {
                return(this.Error("Passwords do not match."));
            }

            this.usersService.CreateUser(input.Username, input.Email, input.Password);
            return(this.Redirect("/Users/Login"));
        }
Ejemplo n.º 2
0
        public HttpResponse Register(RegisterInputModel inputModel)
        {
            if (this.IsUserSignedIn())
            {
                return(this.Redirect("/Repositories/All"));
            }
            if (inputModel.Password != inputModel.ConfirmPassword)
            {
                return(this.Redirect("/Users/Register"));
            }
            if (inputModel.Username.Length < 5 || inputModel.Username.Length > 20)
            {
                return(this.Redirect("/Users/Register"));
            }
            if (inputModel.Password.Length < 6 || inputModel.Password.Length > 20)
            {
                return(this.Redirect("/Users/Register"));
            }
            if (!this.usersService.IsEmailAvailable(inputModel.Email) ||
                !this.usersService.IsUsernameAvailable(inputModel.Username))
            {
                return(this.Redirect("/Users/Register"));
            }

            this.usersService.CreateUser(inputModel);

            return(this.Redirect("/Users/Login"));
        }
Ejemplo n.º 3
0
        public HttpResponse Register(RegisterInputModel input)
        {
            if (this.IsUserSignedIn())
            {
                return(this.Redirect("/Repositories/All"));
            }

            //username validation:
            if (string.IsNullOrWhiteSpace(input.Username) || input.Username.Length < 5 || input.Username.Length > 20)
            {
                return(this.Error("Username should be between 5 and 20 characters long."));
            }

            if (!this.usersService.IsUsernameAvailable(input.Username))
            {
                return(this.Error("Username is already taken."));
            }

            if (!Regex.IsMatch(input.Username, @"^[a-zA-Z0-9\._-]+$"))
            {
                return(this.Error("Invalid username. Only alphanumeric characters, dashes and dots are allowed."));
            }

            //password validation:
            if (string.IsNullOrWhiteSpace(input.Password) || input.Password.Length < 6 || input.Password.Length > 20)
            {
                return(this.Error("Password should be between 6 and 20 characters long."));
            }

            if (input.Password != input.ConfirmPassword)
            {
                return(this.Error("Passwords do not match."));
            }

            //password validation:
            if (string.IsNullOrWhiteSpace(input.Email) || !new EmailAddressAttribute().IsValid(input.Email))
            {
                return(this.Error("Invalid email address."));
            }

            if (!this.usersService.IsEmailAvailable(input.Email))
            {
                return(this.Error("Email is already taken."));
            }

            this.usersService.CreateUser(input.Username, input.Email, input.Password);

            return(this.Redirect("/Users/Login"));
        }
Ejemplo n.º 4
0
        public HttpResponse Register(RegisterInputModel model)
        {
            if (this.IsUserSignedIn())
            {
                return(this.Redirect(RedirectConst.AllRepositories));
            }

            if (string.IsNullOrEmpty(model.Username) || model.Username.Length < 5 || model.Username.Length > 20)
            {
                return(this.Error(ErrorConst.InvalidUsernameLength));
            }

            if (string.IsNullOrEmpty(model.Email) || !new EmailAddressAttribute().IsValid(model.Email))
            {
                return(this.Error(ErrorConst.InvalidEmail));
            }

            if (string.IsNullOrEmpty(model.Password) || model.Password.Length < 6 || model.Password.Length > 20)
            {
                return(this.Error(ErrorConst.RequiredPassword));
            }

            if (model.ConfirmPassword != model.Password)
            {
                return(this.Error(ErrorConst.PasswordMismatch));
            }

            if (!this.usersService.IsEmailAvailable(model.Email))
            {
                return(this.Error(ErrorConst.EmailTaken));
            }

            if (!this.usersService.IsUsernameAvailable(model.Username))
            {
                return(this.Error(ErrorConst.UsernameTaken));
            }

            string createdUser = this.usersService.CreateUser(model.Username, model.Email, model.Password);

            if (createdUser == string.Empty)
            {
                return(this.Error(ErrorConst.UnableToCreateAccount));
            }
            else
            {
                return(this.Redirect(RedirectConst.LoginPage));
            }
        }
        public HttpResponse Register(RegisterInputModel input)
        {
            if (this.IsUserSignedIn())
            {
                return(this.Redirect("/"));
            }

            if (input.Username == null || input.Username.Length < 5 || input.Username.Length > 20)
            {
                return(this.Error("Invalid username. The username should be between 5 and 20 characters."));
            }

            if (!Regex.IsMatch(input.Username, @"^[a-zA-Z0-9\.]+$"))
            {
                return(this.Error("Invalid username. Only alphanumeric characters are allowed."));
            }

            if (string.IsNullOrWhiteSpace(input.Email) || !new EmailAddressAttribute().IsValid(input.Email))
            {
                return(this.Error("Invalid email."));
            }

            if (input.Password == null || input.Password.Length < 6 || input.Password.Length > 20)
            {
                return(this.Error("Invalid password. The password should be between 6 and 20 characters."));
            }

            if (input.Password != input.ConfirmPassword)
            {
                return(this.Error("Passwords should be the same."));
            }

            if (!this.usersService.IsUsernameAvailable(input.Username))
            {
                return(this.Error("Username already taken."));
            }

            if (!this.usersService.IsEmailAvailable(input.Email))
            {
                return(this.Error("Email already taken."));
            }

            this.usersService.CreateUser(input.Username, input.Email, input.Password);
            return(this.Redirect("/Users/Login"));
        }
Ejemplo n.º 6
0
        public HttpResponse Register(RegisterInputModel input)
        {
            if (this.IsUserSignedIn())
            {
                return(this.Redirect("/"));
            }

            if (string.IsNullOrWhiteSpace(input.Username) || input.Username.Length < 5 || input.Username.Length > 20)
            {
                return(this.Error("Username should be between 5 and 20 characters"));
            }

            if (string.IsNullOrWhiteSpace(input.Email) || !new EmailAddressAttribute().IsValid(input.Email))
            {
                return(this.Error("Email is required."));
            }

            if (input.Password == null)
            {
                return(this.Error("Invalid password. The password should be between 6 and 20 characters."));
            }

            if (input.Password != input.ConfirmPassword)
            {
                return(this.Error("Passwords do not match."));
            }

            if (!this.usersService.IsUsernameAvailable(input.Username))
            {
                return(this.Error("Username already taken."));
            }

            if (!this.usersService.IsEmailAvailable(input.Email))
            {
                return(this.Error("Email already taken."));
            }

            this.usersService.CreateUser(input.Username, input.Email, input.Password);

            return(this.Redirect("/Users/Login"));
        }
Ejemplo n.º 7
0
        public HttpResponse Register(RegisterInputModel model)
        {
            if (IsUserSignedIn())
            {
                return(Redirect("/Repositories/All"));
            }

            if (string.IsNullOrWhiteSpace(model.Username) || model.Username.Length < 5 || model.Username.Length > 20)
            {
                return(Error("Username should be between 5 and 20 characters."));
            }

            if (!usersService.IsUsernameAvailable(model.Username))
            {
                return(Error("Username already in use."));
            }

            if (!Regex.IsMatch(model.Email, @"\b[\w\.-]+@[\w\.-]+\.\w{2,4}\b"))
            {
                return(Error("Invalid email address."));
            }

            if (!usersService.IsEmailAvailable(model.Email))
            {
                return(Error("Email already in use."));
            }

            if (model.Password.Length < 6 || model.Password.Length > 20)
            {
                return(Error("Password should be between 6 and 20 characters."));
            }

            if (model.Password != model.ConfirmPassword)
            {
                return(Error("Passwords should be the same."));
            }

            usersService.CreateUser(model.Username, model.Email, model.Password);

            return(Redirect("/Users/Login"));
        }
Ejemplo n.º 8
0
        public HttpResponse Register(RegisterInputModel inputModel)
        {
            if (this.IsUserSignedIn())
            {
                return(this.Redirect("/"));
            }

            if (string.IsNullOrWhiteSpace(inputModel.Username) || inputModel.Username.Length < 5 || inputModel.Username.Length > 20)
            {
                return(this.Error("Username should be between 5 and 20 characters long."));
            }

            if (string.IsNullOrWhiteSpace(inputModel.Email) || !new EmailAddressAttribute().IsValid(inputModel.Email))
            {
                return(this.Error("Invalid e-mail address."));
            }

            if (string.IsNullOrWhiteSpace(inputModel.Password) || inputModel.Password.Length < 6 || inputModel.Password.Length > 20)
            {
                return(this.Error("Password should be between 6 and 20 characters long."));
            }

            if (inputModel.Password != inputModel.ConfirmPassword)
            {
                return(this.Error("Passwords do not match. Please check for typos!"));
            }

            if (!this.usersService.IsEmailAvailable(inputModel.Email))
            {
                return(this.Error("This email is already taken"));
            }

            if (!this.usersService.IsUsernameAvailable(inputModel.Username))
            {
                return(this.Error("This Username is already taken by another user."));
            }

            this.usersService.CreateUser(inputModel);
            return(Redirect("/users/login"));
        }
Ejemplo n.º 9
0
        public HttpResponse Register(RegisterInputModel input)
        {
            if (IsUserSignedIn())
            {
                return(this.Redirect("/"));
            }

            if (string.IsNullOrEmpty(input.Username) || input.Username.Length < 5 || input.Username.Length > 20)
            {
                return(this.Error("Username is requred and should be between 5 and 20 characters long."));
            }

            if (string.IsNullOrEmpty(input.Email) || !new EmailAddressAttribute().IsValid(input.Email))
            {
                return(this.Error("Invalid email address."));
            }

            if (string.IsNullOrEmpty(input.Password) || input.Password.Length < 6 || input.Password.Length > 20)
            {
                return(this.Error("Password is requred and should be between 6 and 20 characters long."));
            }

            if (input.Password != input.ConfirmPassword)
            {
                return(this.Error("Both passwords do not match ."));
            }

            if (!this.usersService.IsUsernameAvailable(input.Username))
            {
                return(this.Error("This username is not available."));
            }

            if (!this.usersService.IsEmailAvailable(input.Email))
            {
                return(this.Error("This email address is not available."));
            }

            this.usersService.CreateUser(input.Username, input.Email, input.Password);
            return(this.Redirect("/Users/Login"));
        }
Ejemplo n.º 10
0
        public HttpResponse Register(RegisterInputModel input)
        {
            if (string.IsNullOrEmpty(input.Username) || input.Username.Length < 5 || input.Username.Length > 20)
            {
                return(this.Error("Username has to be between 5 and 20 characters"));
            }
            if (string.IsNullOrEmpty(input.Email) || !new EmailAddressAttribute().IsValid(input.Email))
            {
                return(this.Error("Email is invalid"));
            }
            if (string.IsNullOrEmpty(input.Password) || input.Password.Length < 6 || input.Password.Length > 20)
            {
                return(this.Error("Password has to be between 6 and 20 characters "));
            }
            if (input.ConfirmPassword != input.Password)
            {
                return(this.Error("Passwords do not match"));
            }

            this.usersService.CreateUser(input.Username, input.Email, input.Password);
            return(this.Redirect("/Users/Login"));
        }
Ejemplo n.º 11
0
        public HttpResponse Register(RegisterInputModel register)
        {
            if (register.Username.Length < 5 || register.Username.Length > 20 || String.IsNullOrEmpty(register.Username))
            {
                return(this.Error("Username must be minimum 5 characers and maximum 20 characters long!"));
            }

            if (register.Password.Length < 6 || register.Password.Length > 20 || String.IsNullOrEmpty(register.Password))
            {
                return(this.Error("Password must be minimum 6 characers and maximum 20 characters long!"));
            }

            if (String.IsNullOrEmpty(register.Email) || !new EmailAddressAttribute().IsValid(register.Email))
            {
                return(this.Error("Invalid Email Address"));
            }

            if (String.IsNullOrEmpty(register.ConfirmPassword) || register.Password != register.ConfirmPassword)
            {
                return(this.Error("Confirm Password field must match Password field!"));
            }

            if (this.usersService.IsEmailAvailable(register.Email))
            {
                return(this.Error("The Email is already taken"));
            }

            if (this.usersService.IsUsernameAvailable(register.Username))
            {
                return(this.Error("The Username is already taken"));
            }

            this.usersService.CreateUser(register.Username, register.Email, register.Password);

            return(this.Redirect("/Users/Login"));
        }
Ejemplo n.º 12
0
        public HttpResponse Register(RegisterInputModel input)
        {
            if (this.IsUserSignedIn())
            {
                return(this.Redirect("/"));
            }

            if (string.IsNullOrEmpty(input.Username) || input.Username.Length < 5 || input.Username.Length > 20)
            {
                return(this.Error("Username should be between 5 and 20 characters."));
            }
            if (!this.usersService.IsUsernameAvailable(input.Username))
            {
                return(this.Error("Username already taken."));
            }
            if (string.IsNullOrEmpty(input.Email) || !new EmailAddressAttribute().IsValid(input.Email))
            {
                return(this.Error("Invalid email."));
            }
            if (!this.usersService.IsEmailAvailable(input.Email))
            {
                return(this.Error("Email already taken."));
            }
            if (string.IsNullOrEmpty(input.Password) || input.Password.Length < 6 || input.Password.Length > 20)
            {
                return(this.Error("Password should be between 6 and 20 characters."));
            }
            if (input.Password != input.ConfirmPassword)
            {
                return(this.Error("Passwords should match!"));
            }

            var userId = this.usersService.CreateUser(input.Username, input.Email, input.Password);

            return(this.Redirect("/Users/Login"));
        }
        public HttpResponse Register(RegisterInputModel input)
        {
            if (this.IsUserSignedIn())
            {
                return(this.Redirect("/Repositories/All"));
            }

            if (string.IsNullOrEmpty(input.Username) ||
                input.Username.Length < 5 ||
                input.Username.Length > 20)
            {
                return(this.Redirect("/Users/Register"));
            }

            if (string.IsNullOrEmpty(input.Email) ||
                !new EmailAddressAttribute().IsValid(input.Email))
            {
                return(this.Redirect("/Users/Register"));
            }

            if (string.IsNullOrEmpty(input.Password) ||
                input.Password.Length < 6 ||
                input.Password.Length > 20)
            {
                return(this.Redirect("/Users/Register"));
            }

            if (input.Password != input.ConfirmPassword)
            {
                return(this.Redirect("/Users/Register"));
            }

            this.usersService.CreateUser(input.Username, input.Email, input.Password);

            return(Redirect("/Users/Login"));
        }