Last active
August 29, 2015 14:14
-
-
Save shyampurk/36909b3a15a7945f2ece to your computer and use it in GitHub Desktop.
Parse Authentication Dialog
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
<div class='overlay' id='auth-overlay'> | |
<div class="container" id="auth-super"> | |
<div class="row"> | |
<div class="col-sm-6" style="background: #afa6a6;border-radius: 10px;"> | |
<div id="auth-dialog"> | |
<div id="title-section"> | |
<div class="row"> | |
<div class="col-sm-8 col-sm-offset-3"><span><h4>PubNub WebRTC App with Parse</h4></span></div> | |
</div> | |
</div> | |
<div id="logo-section"> | |
<div class="row"> | |
<div class="col-sm-4 col-sm-offset-2"><img src="img/parse.png" width=100/></div> | |
<div class="col-sm-3"><img src="img/pubnub.png" width=150/></div> | |
</div> | |
</div> | |
<div id="username-section"> | |
<div class="row"> | |
<div class="col-sm-3 col-sm-offset-1" style="text-align:center;"><span>Username</span></div> | |
<div class="col-sm-6"><input id='user-text' type="text" class="form-control" placeholder="Username"></div> | |
</div> | |
</div> | |
<div id="password-section"> | |
<div class="row"> | |
<div class="col-sm-3 col-sm-offset-1" style="text-align:center;"><span>Password</span></div> | |
<div class="col-sm-6"><input id='password-text' type="password" class="form-control" placeholder="Password"></div> | |
</div> | |
</div> | |
<div id="button-section" class="row"> | |
<div class="col-sm-2 col-sm-offset-4" style="text-align:center;"> | |
<span><button id='login-button' type="button" class="btn btn-default">Login</button></span> | |
</div> | |
<div class="col-sm-2" style="text-align:center;"> | |
<span><button id='signup-button' type="button" class="btn btn-default">Signup</button></span> | |
</div> | |
</div> | |
<div id="status-section"> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> |
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
//Handler for performing Parse Login Operation | |
var performLogin = function(){ | |
//Step 1 - Set status message | |
$('#status-section').html('Attempting to login as user ' + $('#user-text').val()); | |
//Step 2 - Perform login via Parse | |
Parse.User.logIn($('#user-text').val(), $('#password-text').val(), { | |
success: function(user) { | |
$('#status-section').html('Authentication successful for user ' + user.getUsername() + ' , Loading PubNub WebRTC App'); | |
initWebRTC(); | |
$('#auth-overlay').fadeOut(2000); | |
setTimeout(function(){ | |
$('#auth-overlay').remove(); | |
},3000); | |
}, | |
error: function(user, error) { | |
$('#status-section').html('Authentication failed for user ' + user.getUsername() + ' ' + error.message); | |
} | |
}); | |
} |
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
$('#logout').click(function(){ | |
if(Parse.User.current()){ | |
Parse.User.logOut(); | |
} | |
window.location.reload(true); | |
}) |
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
var performSignup = function(){ | |
//Step 1 - Create the Parse User Object | |
var user = new Parse.User(); | |
user.set("username", $('#user-text').val()); | |
user.set("password", $('#password-text').val()); | |
//Step 2 - Set status message | |
$('#status-section').html('Attempting to signup user ' + $('#user-text').val()); | |
//Step 3 - Perform signup via Parse | |
user.signUp(null, { | |
success: function(user) { | |
$('#status-section').html('User ' + user.getUsername() + ' signed up successfully , Redirecting to Login page'); | |
//Logout the just signed up user | |
Parse.User.logOut(); | |
setTimeout(function(){ | |
window.location.reload(); | |
},3000); | |
}, | |
error: function(user, error) { | |
$('#status-section').html('Signup failed for User ' + user.getUsername() + ' , ' + ' ' + error.message); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PubNub WebRTC App with Parse