Last active
August 29, 2015 14:18
-
-
Save codebucketdev/c4d404d4b3b5443f4b49 to your computer and use it in GitHub Desktop.
This is an example of a login page using the Yggdrasil Authentification of the Public API from Razex.de
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
<?php | |
if(isset($_POST['signin'])) { | |
$username = filter_var($_POST['username']); $password = filter_var($_POST['password']); | |
$ch = curl_init("https://api.razex.de/user/login"); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, array("username" => $username, "password" => $password)); | |
curl_setopt($ch, CURLOPT_USERAGENT, "Minecraft"); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
if(isset($result) && $result != null && $result != false) { | |
$data = json_decode($result, true); | |
if(array_key_exists("selectedProfile", $data)) { | |
$profile = $data['selectedProfile']; | |
} | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<meta name="author" content="Codebucket"> | |
<meta name="description" content="Login page example using Yggdrasil Authentication"> | |
<title>Sign in with your Mojang details</title> | |
<link href="//maxcdn.bootstrapcdn.com/bootswatch/3.3.4/paper/bootstrap.min.css" rel="stylesheet"> | |
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet"> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> | |
</head> | |
<style> | |
.signin-panel{margin-top:20px} | |
.form-signin{max-width:330px;padding:15px;margin:0 auto} | |
.form-signin .form-signin-heading,.form-signin .checkbox{margin-bottom:10px} | |
.form-signin .checkbox{font-weight:400} | |
.form-signin .form-control{position:relative;font-size:16px;height:auto;padding:10px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box} | |
.form-signin .form-control:focus{z-index:2} | |
.form-signin input.authfail{border:1px solid #dd4b39} | |
.form-signin p.authfail{color:red} | |
img.authfail{border:2px solid #dd4b39} | |
.form-signin input[type="text"]{margin-bottom:-1px;border-bottom-left-radius:0;border-bottom-right-radius:0} | |
.form-signin input[type="password"]{margin-bottom:10px;border-top-left-radius:0;border-top-right-radius:0} | |
.signin-title{color:#555;font-size:18px;font-weight:400;display:block} | |
.profile-img{width:142px;height:142px;margin:0 auto 10px;display:block} | |
.need-help{margin-top:10px} | |
.new-account{display:block;margin-top:10px} | |
.minecraft-logo{margin:30px 0} | |
</style> | |
<body> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-sm-6 col-md-4 col-md-offset-4"> | |
<div class="text-center minecraft-logo"><img src="http://upload.wikimedia.org/wikipedia/en/3/32/Minecraft_logo.svg" alt="Minecraft logo"></img></div> | |
<h1 class="text-center signin-title">Sign in with your Mojang details to continue</h1> | |
<?php if(isset($_POST['signin']) && !isset($profile)): ?> | |
<div class="alert alert-danger alert-dismissable"> | |
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> | |
<font size=2>Authentication failed: Invalid credentials. Invalid username or password.</font> | |
</div> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
$('.alert').delay(5000).fadeOut("def"); | |
}); | |
</script> | |
<?php endif; ?> | |
<div class="signin-panel panel panel-primary"> | |
<div class="panel-body"> | |
<?php if(isset($_POST['signin']) && isset($profile)): ?> | |
<div class="text-center"> | |
<div class="text-center profile-img"> | |
<img class="img-thumbnail" src="//api.razex.de/skin/avatar/<?= $profile['name']; ?>/142" alt=""></img> | |
</div> | |
<div class="text-center"> | |
<h5>Welcome back, <?= $profile['name']; ?>.</h5> | |
<p>Your UUID is: <code><?= $profile['id']; ?></code></p> | |
<a href="<?= $_POST['redirect_to']; ?>" class="btn btn-lg btn-primary btn-block">Continue</a> | |
</div> | |
</div> | |
<?php else: ?> | |
<form action="" method="post" class="form-signin classic"> | |
<fieldset> | |
<div class="form-group"> | |
<label>Email or username</label> | |
<input type="text" class="form-control" name="username" placeholder="Email or username" value="<?php echo isset($_POST['username']) ? $_POST['username'] : ""; ?>" required autofocus> | |
</div> | |
<div class="form-group"> | |
<label>Password</label><label class="pull-right"><a href="//minecraft.net/resetpassword">Forgot password?</a></label> | |
<input type="password" class="form-control" name="password" placeholder="Password" value="<?php echo isset($_POST['password']) ? $_POST['password'] : ""; ?>" required> | |
</div> | |
<br /> | |
<input type="hidden" class="form-control" name="redirect_to" value="<?php echo isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ""; ?>"> | |
<button class="btn btn-lg btn-success btn-block" type="submit" name="signin"> | |
Authenticate | |
</button> | |
</fieldset> | |
</form> | |
<?php endif; ?> | |
</div> | |
</div> | |
<div class="text-center new-account"> | |
Usernames and passwords are not stored and are only used for authentication. | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment