<commit_before><?php

// ¯\_(ツ)_/¯

?><!doctype html>
<html>
<head>
	<base href=/>
	<title>Test OAuth Client</title>
	<script src=./bower_components/angular/angular.min.js></script>
	<script>
(function(){
	"use strict";
	angular.module('ZapOAuth', []).
	controller('cred', function($scope, $http){
		var s = $scope;

		s.isIn = false;

		s.getStatus = function() {
			$http.get('/status')
			.then(function(ret){
				s.isIn = true;
				s.uid = ret.data.data.uid;
				s.uname = ret.data.data.uname;
			}, function(){
				s.isIn = false;
				s.uid = null;
				s.uname = null;
			});
		}
		s.getStatus();

		s.signOut = function() {
			$http.get('/logout')
			.then(function(ret){
				s.getStatus();
			}, function(){
			});
		};

		s.errMsg = null;
		s.isSigningIn = false;

		s.signIn10 = function() {
			s.isSigningIn = true;
			$http.post('/byway/oauth/10/twitter/auth', {
			}).then(function(ret){
				top.location.href = ret.data.data;
			}, function(){
				s.errMsg = 'Cannot connect to remove server.';
			}).then(function(){
				s.isSigningIn = false;
			});
		};

		s.signIn20 = function() {
			s.isSigningIn = true;
			$http.post('/byway/oauth/20/github/auth', {
			}).then(function(ret){
				top.location.href = ret.data.data;
			}, function(){
				s.errMsg = 'Cannot connect to remove server.';
			}).then(function(){
				s.isSigningIn = false;
			});
		};

		s.signIn20Google = function() {
			s.isSigningIn = true;
			$http.post('/byway/oauth/20/google/auth', {
			}).then(function(ret){
				top.location.href = ret.data.data;
			}, function(){
				s.errMsg = 'Cannot connect to remove server.';
			}).then(function(){
				s.isSigningIn = false;
			});
		};

		s.signInXX = function() {
			s.isSigningIn = true;
			$http.post('/byway/oauth/30/something/auth', {
			}).then(function(ret){
				top.location.href = ret.data.data;
			}, function(){
				s.errMsg = 'Unknown service provider.';
			}).then(function(){
				s.isSigningIn = false;
			});
		};
	});
})();
	</script>
	<style>
	#wrap{
		display:flex;
		align-items:center;
		justify-content:center;
		height:90vh;
		font-family:monospace;
	}
	#box{
		height:12em;
		padding:8px;
		border:1px solid rgba(0,0,0,.3);
		width:400px;
	</style>
</head>
<body>
<div id=wrap ng-app=ZapOAuth ng-controller=cred>
	<div id=box>
		<div ng-show=isIn>
			<p>uid: {{uid}}</p>
			<p>uname: {{uname}}</p>
			<p>
				<button ng-click='signOut()'>
					SIGN OUT
				</button>
			</p>
		</div>
		<div ng-show=!isIn>
			<p>
				<button ng-click='signIn10()' ng-disabled=isSigningIn>
					OAuth1.0 with Twitter
				</button>
			</p>
			<p>
				<button ng-click='signIn20()' ng-disabled=isSigningIn>
					OAuth2.0 with Github
				</button>
			</p>
			<p>
				<button ng-click='signIn20Google()' ng-disabled=isSigningIn>
					OAuth2.0 with Google+
				</button>
			</p>
			<p>
				<button ng-click='signInXX()' ng-disabled=isSigningIn>
					Unknown Service
				</button>
			</p>

			<h4 ng-show=errMsg>ERROR: {{errMsg}}</h4>
		</div>
	</div>
</div>
<commit_msg>Optimize sample home.php a bit.<commit_after><?php

// @todo
// - Add token refresh button for OAuth2.0 if applicable.
// - This sample assumes installation in the root path '/'.
//   Parameterize HTML base to fix this.

?><!doctype html>
<html>
<head>
	<base href=/>
	<title>Test OAuth Client</title>
	<script src=./bower_components/angular/angular.min.js></script>
	<script>
(function(){
	"use strict";
	angular.module('ZapOAuth', []).
	controller('cred', function($scope, $http, $timeout){
		var s = $scope;

		s.isIn = false;

		s.getStatus = function() {
			$http.get('/status')
			.then(function(ret){
				s.isIn = true;
				s.uid = ret.data.data.uid;
				s.uname = ret.data.data.uname;
			}, function(){
				s.isIn = false;
				s.uid = null;
				s.uname = null;
			});
		}
		s.getStatus();

		s.signOut = function() {
			$http.get('/logout')
			.then(function(ret){
				s.getStatus();
			}, function(){
			});
		};

		s.errMsg = null;
		s.isSigningIn = false;

		s.signIn = function(key) {
			var authUrls = {
				twitter: '/byway/oauth/10/twitter/auth',
				github:  '/byway/oauth/20/github/auth',
				google:  '/byway/oauth/20/google/auth',
				unknown: '/byway/oauth/30/unknown/auth',
			};
			var authUrl = !authUrls[key]
				? authUrls.unknown : authUrls[key];
			s.isSigningIn = true;
			$http.post(authUrl, {
			}).then(function(ret){
				top.location.href = ret.data.data;
			}, function(){
				s.errMsg = key == 'unknown'
					? 'Service unknown.'
					: 'Cannot connect to remove server.';
				$timeout(function(){
					s.errMsg = null;
				}, 8e3);
			}).then(function(){
				s.isSigningIn = false;
			});
		};
	});
})();
	</script>
	<style>
	#wrap{
		display:flex;
		align-items:center;
		justify-content:center;
		height:90vh;
		font-family:monospace;
	}
	#box{
		height:14em;
		padding:8px 16px;
		border:1px solid rgba(0,0,0,.3);
		width:400px;
	}
	</style>
</head>
<body>
<div id=wrap ng-app=ZapOAuth ng-controller=cred>
	<div id=box>
		<div ng-show=isIn>
			<p>uid: {{uid}}</p>
			<p>uname: {{uname}}</p>
			<p>
				<button ng-click='signOut()'>
					SIGN OUT
				</button>
			</p>
		</div>
		<div ng-show=!isIn>
			<p>
				<button ng-click='signIn("twitter")'
					ng-disabled=isSigningIn>
					OAuth1.0 with Twitter
				</button>
			</p>
			<p>
				<button ng-click='signIn("github")'
					ng-disabled=isSigningIn>
					OAuth2.0 with Github
				</button>
			</p>
			<p>
				<button ng-click='signIn("google")'
					ng-disabled=isSigningIn>
					OAuth2.0 with Google
				</button>
			</p>
			<p>
				<button ng-click='signIn("whatever")'
					ng-disabled=isSigningIn>
					Unknown Service
				</button>
			</p>
			<p ng-show=errMsg>
				<strong>ERROR:</strong> {{errMsg}}
			</p>
		</div>
	</div>
</div>

{'fraction_non_alphanumeric': 0.19849991278562706, 'fraction_numerical': 0.012907727193441479, 'mean_word_length': 2.7898215465961664, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5870556', 'n_tokens_mistral': 2781, 'n_tokens_neox': 2284, 'n_words': 415}