Last active
August 29, 2015 14:14
-
-
Save kylejson/e1a95ff5477112cd6dbc to your computer and use it in GitHub Desktop.
Parse demo of registering a User and Login with error messages
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Parse Test</title> | |
<style> | |
p { | |
font-size: 20px; | |
} | |
#second-sentence { | |
display: none; | |
} | |
button { | |
margin-bottom: 20px; | |
} | |
#showMe { | |
display: none; | |
} | |
#error { | |
display: none; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Parse Demo of Registering and Login</h1> | |
<p id="first-sentence">Hey this sentence!</p> | |
<p id="second-sentence">Hey this second sentence!</p> | |
<button id="first-btn"> Show Button </button> | |
<button id="second-btn"> 2nd Action </button> | |
<h1>Sign Up</h1> | |
<form id="SignUp"> | |
<input placeholder="username" id="username" type="text"> | |
<input placeholder="password" id="password" type="password"> | |
<input placeholder="email" id="email" type="email"> | |
<input type="submit" value="submit"> | |
</form> | |
<h2>Login</h2> | |
<p id="error" style="color:red"> Wrong Username or password</p> | |
<form id="Login"> | |
<input placeholder="username" id="login-username" type="text"> | |
<input placeholder="password" id="login-password" type="password"> | |
<input type="submit" value="Login"> | |
</form> | |
<div id="showMe"> | |
<h1 style="color: blue"> | |
Show me if user is logged in!!! | |
</h1> | |
</div> | |
<script src="https://www.parsecdn.com/js/parse-1.3.4.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script type="text/javascript"> | |
Parse.initialize("", ""); | |
$('#SignUp').on('submit', function(e){ | |
e.preventDefault(); | |
var User = Parse.Object.extend("User"); | |
var newUser = new User(); | |
newUser.save({ | |
username: $("#username").val(), | |
password: $("#password").val(), | |
email: $("#email").val() | |
},{ | |
success: function(newUser){ | |
console.log("Yo it saved"); | |
} | |
}); | |
}); | |
var checkUser = new Parse.Query("User"); | |
$('#Login').on('submit', function(e){ | |
e.preventDefault(); | |
Parse.User.logIn($("#login-username").val(), $('#login-password').val(), { | |
success: function(user) { | |
$('#error').hide(); | |
$('#showMe').show(); | |
}, | |
error: function(user, error) { | |
// The login failed. Check error to see why. | |
$('#error').show(); | |
} | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment