Created
July 11, 2016 15:26
-
-
Save caruccio/1f1240d016e107f97775956c1d643b04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type='text/javascript' src='https://code.jquery.com/jquery-3.1.0.min.js'></script> | |
<script type='text/javascript'> | |
$(document).ready(function () | |
{ | |
$('#show-password').change(function() { | |
$('#password').prop('type', this.checked ? 'text' : 'password') | |
}) | |
$('#signup-form').submit(function(event) { | |
event.preventDefault() | |
$('#signup').prop('disabled', true) | |
var messages = $('#messages'), | |
name = $('#name').val(), | |
email = $('#email').val(), | |
password = $('#password').val() | |
$('#password').val('') | |
messages.empty() | |
messages.append($('<div class="message">Aguarde um momento por favor...</div>')) | |
$.ajax({ | |
type: 'POST', | |
url: 'https://gapi.getupcloud.com/api/v1/auth/register/account/', | |
data: { | |
name: name, | |
email: email, | |
password: password, | |
} | |
}).then(function(res, data) { | |
messages.empty() | |
messages.append($('<div class="success">Cadastro realizado com sucesso. Por favor, verifique seu email.</div>')) | |
}).fail(function(res, data) { | |
messages.empty() | |
if (typeof res.responseJSON === 'object') { | |
for (var err in res.responseJSON) { | |
for (var msg in res.responseJSON[err]) { | |
messages.append($('<div class="error">' + res.responseJSON[err][msg] + '</div>')) | |
} | |
} | |
} | |
}).always(function() { | |
$('#signup').prop('disabled', false) | |
}) | |
}) | |
}) | |
</script> | |
<form id='signup-form' method='post'> | |
<input type='name' id='name' name='name' required placeholder='Nome'> | |
<input type='email' id='email' name='email' required placeholder='Email'> | |
<input type='password' id='password' name='password' placeholder='Senha'> | |
<label><input type='checkbox' id='show-password' name='show-password'/>Mostrar senha</label> | |
<button type='submit' id='signup' name='signup'>Registrar</button> | |
<div id='messages'></div> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment