x x x
x
Only portrait mode is currently supported - please rotate your device.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

HTML
<script>
let nameError = document.getElementsByClassName('name-error')[0]
let emailError = document.getElementsByClassName('email-error')[0]
let passwordError = document.getElementsByClassName('password-error')[0]

function validateEmail(email) {
  const re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  return re.test(email);
}

function registerUser(){
	// display loading indicator
	document.getElementById('signup-spinner').style.display = "inline-block"

	let validated = true;

	let name = document.querySelector("input#name").value
	let email = document.querySelector("input#email").value
	let password = document.querySelector("input#password").value
	let passwordConfirm = document.querySelector("input#password-confirm").value

	if(name === ""){
		validated = false;
		nameError.innerText = "You must provide a name!";
	}

	if(password === "" || passwordConfirm === ""){
		validated = false;
		passwordError.innerText = "You must provide a password!";
	}

	if(!validateEmail(email)){
		validated = false;
		emailError.innerText = "Please enter a valid email and try again!";
		
	}

	if(email === ""){
		validated = false;
		emailError.innerText = "You must provide an email!";
	}

	if(password !== passwordConfirm){
		validated = false;
		passwordError.innerText = "The entered passwords didn't match. Please try again!";	
	}
	
	if(validated){
jQuery.ajax({
  url: "/rest/scriptrunner/latest/custom/passportSignUp",
  headers: {
    'X-Atlassian-Token' : 'nocheck',
    'Content-type' : 'application/json'
  },
  type: "POST",
  dataType: 'text',
  data: JSON.stringify({
    "fullname":name,
    "email":email,
    "password" : password
  }),
  success: function(text){
	
   var encoded_os_password = encodeURIComponent(password);
   var encoded_os_username = encodeURIComponent(email)

	var url = window.location.href;
      analytics.track('signupButtonClicked', {
        url
      });
	

    window.location.href = `/login.action?os_username=${encoded_os_username}&os_password=${encoded_os_password}&formname=loginform&login=Log%20In&os_destination=/site/pass`display/das?newuser=true`;
  },
  error: function(err){
	// display loading indicator
	document.getElementById('signup-spinner').style.display = "none"

    let errorCode = JSON.parse(err.responseText).error
	console.log(errorCode)
	if (errorCode === -1){
		console.log('spit error message')
		emailError.innerText = "Email already exists. Please try signing in!";
		$( ".err-msg" ).effect( "bounce", {times:3 , distance: 5, direction: 'left'}, 100 )
	}
  }
});
	}else{
		document.getElementById('signup-spinner').style.display = "none"
		 $( ".err-msg" ).effect( "bounce", {times:3 , distance: 5, direction: 'left'}, 100 )
	}
	
}
</script>

...