Skip to content

Instantly share code, notes, and snippets.

@drblue
Created March 2, 2015 12:54
Show Gist options
  • Save drblue/e150f92b570aa33480da to your computer and use it in GitHub Desktop.
Save drblue/e150f92b570aa33480da to your computer and use it in GitHub Desktop.
Example // source http://jsbin.com/iCISilA/2
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="http://www.parsecdn.com/js/parse-1.2.12.min.js"></script>
<meta charset=utf-8 />
<title>Example</title>
</head>
<body ng-app="AuthApp">
<div ng-hide="currentUser">
<form ng-show="scenario == 'Sign up'">
<h2>Sign up</h2>
Email: <input type="email" ng-model="user.email" /><br />
Username: <input type="text" ng-model="user.username" /><br />
Password: <input type="password" ng-model="user.password" /><br />
<button ng-click="signUp(user)">Sign up</button>
or <a href="#" ng-click='scenario="Log in"'>Log in</a>
</form>
<form ng-show="scenario == 'Log in'">
<h2>Log in</h2>
Username: <input type="text" ng-model="user.username" /><br />
Password: <input type="password" ng-model="user.password" /><br />
<button ng-click="logIn(user)">Log in</button>
or <a href="#" ng-click='scenario="Sign up"'>Sign up</a>
</form>
</div>
<div ng-show="currentUser">
<h1>Welcome {{currentUser.get('username')}}</h1>
<p> You have been successfully logged in</p>
<button ng-click="logOut(user)">Log out</button>
</div>
<script id="jsbin-javascript">
Parse.initialize("YJwHjwYF08scjC2SEdl9Ve2YFB3056FQfkUgGu8p", "awDPDR2YNfZNtbJ54VzEZPiWJZmLekU8qkJxnlOw");
angular.module('AuthApp', [])
.run(['$rootScope', function($scope) {
$scope.scenario = 'Sign up';
$scope.currentUser = Parse.User.current();
$scope.signUp = function(form) {
var user = new Parse.User();
user.set("email", form.email);
user.set("username", form.username);
user.set("password", form.password);
user.signUp(null, {
success: function(user) {
$scope.currentUser = user;
$scope.$apply();
},
error: function(user, error) {
alert("Unable to sign up: " + error.code + " " + error.message);
}
});
};
$scope.logIn = function(form) {
Parse.User.logIn(form.username, form.password, {
success: function(user) {
$scope.currentUser = user;
$scope.$apply();
},
error: function(user, error) {
alert("Unable to log in: " + error.code + " " + error.message);
}
});
};
$scope.logOut = function(form) {
Parse.User.logOut();
$scope.currentUser = null;
};
}]);
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"><\/script>
<script src="http://www.parsecdn.com/js/parse-1.2.12.min.js"><\/script>
<meta charset=utf-8 />
<title>Example</title>
</head>
<body ng-app="AuthApp">
<div ng-hide="currentUser">
<form ng-show="scenario == 'Sign up'">
<h2>Sign up</h2>
Email: <input type="email" ng-model="user.email" /><br />
Username: <input type="text" ng-model="user.username" /><br />
Password: <input type="password" ng-model="user.password" /><br />
<button ng-click="signUp(user)">Sign up</button>
or <a href="#" ng-click='scenario="Log in"'>Log in</a>
</form>
<form ng-show="scenario == 'Log in'">
<h2>Log in</h2>
Username: <input type="text" ng-model="user.username" /><br />
Password: <input type="password" ng-model="user.password" /><br />
<button ng-click="logIn(user)">Log in</button>
or <a href="#" ng-click='scenario="Sign up"'>Sign up</a>
</form>
</div>
<div ng-show="currentUser">
<h1>Welcome {{currentUser.get('username')}}</h1>
<p> You have been successfully logged in</p>
<button ng-click="logOut(user)">Log out</button>
</div>
</body>
</html>
</script>
<script id="jsbin-source-javascript" type="text/javascript">Parse.initialize("YJwHjwYF08scjC2SEdl9Ve2YFB3056FQfkUgGu8p", "awDPDR2YNfZNtbJ54VzEZPiWJZmLekU8qkJxnlOw");
angular.module('AuthApp', [])
.run(['$rootScope', function($scope) {
$scope.scenario = 'Sign up';
$scope.currentUser = Parse.User.current();
$scope.signUp = function(form) {
var user = new Parse.User();
user.set("email", form.email);
user.set("username", form.username);
user.set("password", form.password);
user.signUp(null, {
success: function(user) {
$scope.currentUser = user;
$scope.$apply();
},
error: function(user, error) {
alert("Unable to sign up: " + error.code + " " + error.message);
}
});
};
$scope.logIn = function(form) {
Parse.User.logIn(form.username, form.password, {
success: function(user) {
$scope.currentUser = user;
$scope.$apply();
},
error: function(user, error) {
alert("Unable to log in: " + error.code + " " + error.message);
}
});
};
$scope.logOut = function(form) {
Parse.User.logOut();
$scope.currentUser = null;
};
}]);
</script></body>
</html>
Parse.initialize("YJwHjwYF08scjC2SEdl9Ve2YFB3056FQfkUgGu8p", "awDPDR2YNfZNtbJ54VzEZPiWJZmLekU8qkJxnlOw");
angular.module('AuthApp', [])
.run(['$rootScope', function($scope) {
$scope.scenario = 'Sign up';
$scope.currentUser = Parse.User.current();
$scope.signUp = function(form) {
var user = new Parse.User();
user.set("email", form.email);
user.set("username", form.username);
user.set("password", form.password);
user.signUp(null, {
success: function(user) {
$scope.currentUser = user;
$scope.$apply();
},
error: function(user, error) {
alert("Unable to sign up: " + error.code + " " + error.message);
}
});
};
$scope.logIn = function(form) {
Parse.User.logIn(form.username, form.password, {
success: function(user) {
$scope.currentUser = user;
$scope.$apply();
},
error: function(user, error) {
alert("Unable to log in: " + error.code + " " + error.message);
}
});
};
$scope.logOut = function(form) {
Parse.User.logOut();
$scope.currentUser = null;
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment