Added login and registration forms

This commit is contained in:
Stian Thorgersen 2013-07-23 17:25:36 +01:00
parent 18750c5c9c
commit ae045d4822
14 changed files with 21930 additions and 0 deletions

36
sdk-html/pom.xml Executable file
View File

@ -0,0 +1,36 @@
<?xml version="1.0"?>
<project>
<parent>
<artifactId>keycloak-parent</artifactId>
<groupId>org.keycloak</groupId>
<version>1.0-alpha-1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>keycloak-sdk-html</artifactId>
<name>Keycloak HTML SDK</name>
<description />
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,117 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.keycloak.sdk.resources;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.UriInfo;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
@Path("sdk")
public class SdkResource {
@XmlRootElement
public static class LoginConfig {
private String callbackUrl;
private String name;
private String[] providers;
public String getCallbackUrl() {
return callbackUrl;
}
public String getName() {
return name;
}
public String[] getProviders() {
return providers;
}
public void setCallbackUrl(String callbackUrl) {
this.callbackUrl = callbackUrl;
}
public void setName(String name) {
this.name = name;
}
public void setProviders(String[] providers) {
this.providers = providers;
}
}
@Context
private HttpHeaders headers;
@Context
private UriInfo uriInfo;
@GET
@Path("config/{application}")
@Produces(MediaType.APPLICATION_JSON)
public Response getConfig(@PathParam("application") String application) {
String applicationCallbackUrl = null; // TODO Get application callback url
String applicationJavaScriptOrigin = null; // TODO Get application javascript origin
LoginConfig loginConfig = new LoginConfig();
loginConfig.setName(application);
loginConfig.setCallbackUrl(applicationCallbackUrl);
loginConfig.setProviders(null); // TODO Get configured identity providers for application
ResponseBuilder response = Response.ok(loginConfig);
if (applicationJavaScriptOrigin != null) {
response.header("Access-Control-Allow-Origin", applicationJavaScriptOrigin);
}
return response.build();
}
@GET
@Path("login/{application}")
@Produces(MediaType.TEXT_HTML)
public Response login(@PathParam("application") String application) {
return Response.ok(getClass().getResourceAsStream("login.html")).build();
}
@GET
@Path("register/{application}")
@Produces(MediaType.TEXT_HTML)
public Response register(@PathParam("application") String application) {
return Response.ok(getClass().getResourceAsStream("register.html")).build();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,17 @@
body {
margin: 50px;
}
div#keycloak-login-container,div#keycloak-register-container {
}
div#keycloak-login-standard,div#keycloak-register-standard {
width: 50%;
float: left;
}
div#keycloak-login-social,div#keycloak-register-social {
width: 50%;
float: left;
}

View File

@ -0,0 +1,5 @@
{
"id" : "acme-corp",
"name" : "Acme Corp",
"providers" : [ "google", "twitter" ]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -0,0 +1,457 @@
/**
* @license AngularJS v1.0.6
* (c) 2010-2012 Google, Inc. http://angularjs.org
* License: MIT
*/
(function(window, angular, undefined) {
'use strict';
/**
* @ngdoc overview
* @name ngResource
* @description
*/
/**
* @ngdoc object
* @name ngResource.$resource
* @requires $http
*
* @description
* A factory which creates a resource object that lets you interact with
* [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources.
*
* The returned resource object has action methods which provide high-level behaviors without
* the need to interact with the low level {@link ng.$http $http} service.
*
* # Installation
* To use $resource make sure you have included the `angular-resource.js` that comes in Angular
* package. You can also find this file on Google CDN, bower as well as at
* {@link http://code.angularjs.org/ code.angularjs.org}.
*
* Finally load the module in your application:
*
* angular.module('app', ['ngResource']);
*
* and you are ready to get started!
*
* @param {string} url A parameterized URL template with parameters prefixed by `:` as in
* `/user/:username`. If you are using a URL with a port number (e.g.
* `http://example.com:8080/api`), you'll need to escape the colon character before the port
* number, like this: `$resource('http://example.com\\:8080/api')`.
*
* @param {Object=} paramDefaults Default values for `url` parameters. These can be overridden in
* `actions` methods.
*
* Each key value in the parameter object is first bound to url template if present and then any
* excess keys are appended to the url search query after the `?`.
*
* Given a template `/path/:verb` and parameter `{verb:'greet', salutation:'Hello'}` results in
* URL `/path/greet?salutation=Hello`.
*
* If the parameter value is prefixed with `@` then the value of that parameter is extracted from
* the data object (useful for non-GET operations).
*
* @param {Object.<Object>=} actions Hash with declaration of custom action that should extend the
* default set of resource actions. The declaration should be created in the following format:
*
* {action1: {method:?, params:?, isArray:?},
* action2: {method:?, params:?, isArray:?},
* ...}
*
* Where:
*
* - `action` {string} The name of action. This name becomes the name of the method on your
* resource object.
* - `method` {string} HTTP request method. Valid methods are: `GET`, `POST`, `PUT`, `DELETE`,
* and `JSONP`
* - `params` {object=} Optional set of pre-bound parameters for this action.
* - isArray {boolean=} If true then the returned object for this action is an array, see
* `returns` section.
*
* @returns {Object} A resource "class" object with methods for the default set of resource actions
* optionally extended with custom `actions`. The default set contains these actions:
*
* { 'get': {method:'GET'},
* 'save': {method:'POST'},
* 'query': {method:'GET', isArray:true},
* 'remove': {method:'DELETE'},
* 'delete': {method:'DELETE'} };
*
* Calling these methods invoke an {@link ng.$http} with the specified http method,
* destination and parameters. When the data is returned from the server then the object is an
* instance of the resource class. The actions `save`, `remove` and `delete` are available on it
* as methods with the `$` prefix. This allows you to easily perform CRUD operations (create,
* read, update, delete) on server-side data like this:
* <pre>
var User = $resource('/user/:userId', {userId:'@id'});
var user = User.get({userId:123}, function() {
user.abc = true;
user.$save();
});
</pre>
*
* It is important to realize that invoking a $resource object method immediately returns an
* empty reference (object or array depending on `isArray`). Once the data is returned from the
* server the existing reference is populated with the actual data. This is a useful trick since
* usually the resource is assigned to a model which is then rendered by the view. Having an empty
* object results in no rendering, once the data arrives from the server then the object is
* populated with the data and the view automatically re-renders itself showing the new data. This
* means that in most case one never has to write a callback function for the action methods.
*
* The action methods on the class object or instance object can be invoked with the following
* parameters:
*
* - HTTP GET "class" actions: `Resource.action([parameters], [success], [error])`
* - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])`
* - non-GET instance actions: `instance.$action([parameters], [success], [error])`
*
*
* @example
*
* # Credit card resource
*
* <pre>
// Define CreditCard class
var CreditCard = $resource('/user/:userId/card/:cardId',
{userId:123, cardId:'@id'}, {
charge: {method:'POST', params:{charge:true}}
});
// We can retrieve a collection from the server
var cards = CreditCard.query(function() {
// GET: /user/123/card
// server returns: [ {id:456, number:'1234', name:'Smith'} ];
var card = cards[0];
// each item is an instance of CreditCard
expect(card instanceof CreditCard).toEqual(true);
card.name = "J. Smith";
// non GET methods are mapped onto the instances
card.$save();
// POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'}
// server returns: {id:456, number:'1234', name: 'J. Smith'};
// our custom method is mapped as well.
card.$charge({amount:9.99});
// POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'}
});
// we can create an instance as well
var newCard = new CreditCard({number:'0123'});
newCard.name = "Mike Smith";
newCard.$save();
// POST: /user/123/card {number:'0123', name:'Mike Smith'}
// server returns: {id:789, number:'01234', name: 'Mike Smith'};
expect(newCard.id).toEqual(789);
* </pre>
*
* The object returned from this function execution is a resource "class" which has "static" method
* for each action in the definition.
*
* Calling these methods invoke `$http` on the `url` template with the given `method` and `params`.
* When the data is returned from the server then the object is an instance of the resource type and
* all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
* operations (create, read, update, delete) on server-side data.
<pre>
var User = $resource('/user/:userId', {userId:'@id'});
var user = User.get({userId:123}, function() {
user.abc = true;
user.$save();
});
</pre>
*
* It's worth noting that the success callback for `get`, `query` and other method gets passed
* in the response that came from the server as well as $http header getter function, so one
* could rewrite the above example and get access to http headers as:
*
<pre>
var User = $resource('/user/:userId', {userId:'@id'});
User.get({userId:123}, function(u, getResponseHeaders){
u.abc = true;
u.$save(function(u, putResponseHeaders) {
//u => saved user object
//putResponseHeaders => $http header getter
});
});
</pre>
* # Buzz client
Let's look at what a buzz client created with the `$resource` service looks like:
<doc:example>
<doc:source jsfiddle="false">
<script>
function BuzzController($resource) {
this.userId = 'googlebuzz';
this.Activity = $resource(
'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
{alt:'json', callback:'JSON_CALLBACK'},
{get:{method:'JSONP', params:{visibility:'@self'}}, replies: {method:'JSONP', params:{visibility:'@self', comments:'@comments'}}}
);
}
BuzzController.prototype = {
fetch: function() {
this.activities = this.Activity.get({userId:this.userId});
},
expandReplies: function(activity) {
activity.replies = this.Activity.replies({userId:this.userId, activityId:activity.id});
}
};
BuzzController.$inject = ['$resource'];
</script>
<div ng-controller="BuzzController">
<input ng-model="userId"/>
<button ng-click="fetch()">fetch</button>
<hr/>
<div ng-repeat="item in activities.data.items">
<h1 style="font-size: 15px;">
<img src="{{item.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
<a href="{{item.actor.profileUrl}}">{{item.actor.name}}</a>
<a href ng-click="expandReplies(item)" style="float: right;">Expand replies: {{item.links.replies[0].count}}</a>
</h1>
{{item.object.content | html}}
<div ng-repeat="reply in item.replies.data.items" style="margin-left: 20px;">
<img src="{{reply.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
<a href="{{reply.actor.profileUrl}}">{{reply.actor.name}}</a>: {{reply.content | html}}
</div>
</div>
</div>
</doc:source>
<doc:scenario>
</doc:scenario>
</doc:example>
*/
angular.module('ngResource', ['ng']).
factory('$resource', ['$http', '$parse', function($http, $parse) {
var DEFAULT_ACTIONS = {
'get': {method:'GET'},
'save': {method:'POST'},
'query': {method:'GET', isArray:true},
'remove': {method:'DELETE'},
'delete': {method:'DELETE'}
};
var noop = angular.noop,
forEach = angular.forEach,
extend = angular.extend,
copy = angular.copy,
isFunction = angular.isFunction,
getter = function(obj, path) {
return $parse(path)(obj);
};
/**
* We need our custom method because encodeURIComponent is too aggressive and doesn't follow
* http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
* segments:
* segment = *pchar
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
* pct-encoded = "%" HEXDIG HEXDIG
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
* / "*" / "+" / "," / ";" / "="
*/
function encodeUriSegment(val) {
return encodeUriQuery(val, true).
replace(/%26/gi, '&').
replace(/%3D/gi, '=').
replace(/%2B/gi, '+');
}
/**
* This method is intended for encoding *key* or *value* parts of query component. We need a custom
* method becuase encodeURIComponent is too agressive and encodes stuff that doesn't have to be
* encoded per http://tools.ietf.org/html/rfc3986:
* query = *( pchar / "/" / "?" )
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
* pct-encoded = "%" HEXDIG HEXDIG
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
* / "*" / "+" / "," / ";" / "="
*/
function encodeUriQuery(val, pctEncodeSpaces) {
return encodeURIComponent(val).
replace(/%40/gi, '@').
replace(/%3A/gi, ':').
replace(/%24/g, '$').
replace(/%2C/gi, ',').
replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
}
function Route(template, defaults) {
this.template = template = template + '#';
this.defaults = defaults || {};
var urlParams = this.urlParams = {};
forEach(template.split(/\W/), function(param){
if (param && (new RegExp("(^|[^\\\\]):" + param + "\\W").test(template))) {
urlParams[param] = true;
}
});
this.template = template.replace(/\\:/g, ':');
}
Route.prototype = {
url: function(params) {
var self = this,
url = this.template,
val,
encodedVal;
params = params || {};
forEach(this.urlParams, function(_, urlParam){
val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
if (angular.isDefined(val) && val !== null) {
encodedVal = encodeUriSegment(val);
url = url.replace(new RegExp(":" + urlParam + "(\\W)", "g"), encodedVal + "$1");
} else {
url = url.replace(new RegExp("(\/?):" + urlParam + "(\\W)", "g"), function(match,
leadingSlashes, tail) {
if (tail.charAt(0) == '/') {
return tail;
} else {
return leadingSlashes + tail;
}
});
}
});
url = url.replace(/\/?#$/, '');
var query = [];
forEach(params, function(value, key){
if (!self.urlParams[key]) {
query.push(encodeUriQuery(key) + '=' + encodeUriQuery(value));
}
});
query.sort();
url = url.replace(/\/*$/, '');
return url + (query.length ? '?' + query.join('&') : '');
}
};
function ResourceFactory(url, paramDefaults, actions) {
var route = new Route(url);
actions = extend({}, DEFAULT_ACTIONS, actions);
function extractParams(data, actionParams){
var ids = {};
actionParams = extend({}, paramDefaults, actionParams);
forEach(actionParams, function(value, key){
ids[key] = value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
});
return ids;
}
function Resource(value){
copy(value || {}, this);
}
forEach(actions, function(action, name) {
action.method = angular.uppercase(action.method);
var hasBody = action.method == 'POST' || action.method == 'PUT' || action.method == 'PATCH';
Resource[name] = function(a1, a2, a3, a4) {
var params = {};
var data;
var success = noop;
var error = null;
switch(arguments.length) {
case 4:
error = a4;
success = a3;
//fallthrough
case 3:
case 2:
if (isFunction(a2)) {
if (isFunction(a1)) {
success = a1;
error = a2;
break;
}
success = a2;
error = a3;
//fallthrough
} else {
params = a1;
data = a2;
success = a3;
break;
}
case 1:
if (isFunction(a1)) success = a1;
else if (hasBody) data = a1;
else params = a1;
break;
case 0: break;
default:
throw "Expected between 0-4 arguments [params, data, success, error], got " +
arguments.length + " arguments.";
}
var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
$http({
method: action.method,
url: route.url(extend({}, extractParams(data, action.params || {}), params)),
data: data
}).then(function(response) {
var data = response.data;
if (data) {
if (action.isArray) {
value.length = 0;
forEach(data, function(item) {
value.push(new Resource(item));
});
} else {
copy(data, value);
}
}
(success||noop)(value, response.headers);
}, error);
return value;
};
Resource.prototype['$' + name] = function(a1, a2, a3) {
var params = extractParams(this),
success = noop,
error;
switch(arguments.length) {
case 3: params = a1; success = a2; error = a3; break;
case 2:
case 1:
if (isFunction(a1)) {
success = a1;
error = a2;
} else {
params = a1;
success = a2 || noop;
}
case 0: break;
default:
throw "Expected between 1-3 arguments [params, success, error], got " +
arguments.length + " arguments.";
}
var data = hasBody ? this : undefined;
Resource[name].call(this, params, data, success, error);
};
});
Resource.bind = function(additionalParamDefaults){
return ResourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
};
return Resource;
}
return ResourceFactory;
}]);
})(window, window.angular);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,5 @@
var keycloakModule = angular.module('keycloak', [ 'ngResource' ]);
keycloakModule.controller('LoginCtrl', function($scope, $resource) {
$scope.config = $resource("example-config.json").get();
});

View File

@ -0,0 +1,248 @@
window.Keycloak = (function () {
var queryParameters = function (name) {
var parameters = window.location.search.substring(1).split("&");
for (var i = 0; i < parameters.length; i++) {
var param = parameters[i].split("=");
if (decodeURIComponent(param[0]) == name) {
return decodeURIComponent(param[1]);
}
}
};
var messageError = queryParameters("error");
var messageInfo = queryParameters("info");
var keycloak = {
appKey: queryParameters("app"),
token: queryParameters("token"),
baseUrl: "/ejs-identity",
get loginUrl() {
return this.baseUrl + "/api/login/" + this.appKey;
},
get registerUrl() {
return this.baseUrl + "/api/register/" + this.appKey;
},
get userInfoUrl() {
return this.baseUrl + "/api/auth/userinfo?appKey=" + this.appKey;
}
};
keycloak.getConfig = function (success, error) {
var req = new XMLHttpRequest();
req.open("GET", keycloak.loginUrl);
req.setRequestHeader("Accept", "application/json");
req.onreadystatechange = function () {
if (req.readyState == 4) {
if (req.status == 200) {
var config = JSON.parse(req.responseText);
if (success) {
success(config);
}
} else {
if (error) {
error(req.status);
}
}
}
};
req.send();
};
keycloak.getUser = function (success, error) {
var req = new XMLHttpRequest();
req.open("GET", keycloak.userInfoUrl + "&token=" + keycloak.token);
req.setRequestHeader("Accept", "application/json");
req.onreadystatechange = function () {
if (req.readyState == 4) {
if (req.status == 200) {
var user = JSON.parse(req.responseText);
if (success) {
success(user);
}
} else {
if (error) {
error(req.status);
}
}
}
};
req.send();
};
var createLogin = function(containerId) {
var login = document.createElement("div");
login.setAttribute("class", "keycloak-login");
var container = document.getElementById(containerId);
container.setAttribute("class", "keycloak-login-container");
container.innerHTML = null;
container.appendChild(login);
return login;
};
var createHeader = function(text) {
var div = document.createElement("div");
div.setAttribute("class", "keycloak-login-header");
var h = document.createElement("h1");
h.textContent = text;
div.appendChild(h);
return div;
};
var createInput = function(group, name, labelText, type) {
var div = document.createElement("div");
div.setAttribute("class", "keycloak-login-" + group + "-" + name);
var label = document.createElement("label");
label.setAttribute("for", name);
label.textContent = labelText;
div.appendChild(label);
var input = document.createElement("input");
input.setAttribute("name", name);
if (type) {
input.setAttribute("type", type);
} else {
input.setAttribute("type", "text");
}
div.appendChild(input);
return div;
};
var createMessage = function(message, type) {
var div = document.createElement("div");
div.setAttribute("class", "keycloak-login-message-" + type);
if (message == "login_failed") {
div.textContent = "Failed to login";
} else if (message == "register_failed") {
div.textContent = "Failed to register user";
} else if (message = "register_created") {
div.textContent = "Created user";
} else {
div.textContent = message;
}
return div;
};
keycloak.renderLoginForm = function (containerId) {
var success = function (config) {
var login = createLogin(containerId);
login.appendChild(createHeader("Login to " + config.name));
if (messageError) {
login.appendChild(createMessage(messageError, "warn"));
}
if (messageInfo) {
login.appendChild(createMessage(messageInfo, "info"));
}
var standardLogin = document.createElement("div");
standardLogin.setAttribute("class", "keycloak-login-standard");
login.appendChild(standardLogin);
var form = document.createElement("form");
form.setAttribute("action", keycloak.loginUrl);
form.setAttribute("method", "post");
standardLogin.appendChild(form);
form.appendChild(createInput("standard", "username", "Username"));
form.appendChild(createInput("standard", "password", "Password", "password"));
var buttonsDiv = document.createElement("div");
buttonsDiv.setAttribute("class", "keycloak-login-buttons");
form.appendChild(buttonsDiv);
var submitButton = document.createElement("button");
submitButton.setAttribute("type", "submit");
submitButton.textContent = "Login";
buttonsDiv.appendChild(submitButton);
var registerButton = document.createElement("button");
registerButton.setAttribute("type", "button");
registerButton.setAttribute("onclick", "location.href='" + keycloak.registerUrl + "'");
registerButton.textContent = "Register";
buttonsDiv.appendChild(registerButton);
var cancelButton = document.createElement("button");
cancelButton.setAttribute("type", "button");
cancelButton.setAttribute("onclick", "location.href='" + config.callbackUrl + "'");
cancelButton.textContent = "Cancel";
buttonsDiv.appendChild(cancelButton);
var socialLogin = document.createElement("div");
socialLogin.setAttribute("class", "keycloak-login-social");
login.appendChild(socialLogin);
for (var i = 0; i < config.providerConfigs.length; i++) {
var provider = config.providerConfigs[i];
var providerLink = document.createElement("a");
providerLink.setAttribute("href", provider.loginUri);
socialLogin.appendChild(providerLink);
var providerImage = document.createElement("img");
providerImage.setAttribute("src", provider.icon);
providerLink.appendChild(providerImage);
}
};
var error = function() {
var login = createLogin(containerId);
login.appendChild(createHeader("Invalid"));
login.appendChild(createMessage("Invalid application key", "warn"));
};
keycloak.getConfig(success, error);
};
keycloak.renderRegistrationForm = function (containerId) {
var login = createLogin(containerId);
var success = function (config) {
login.appendChild(createHeader("Register with " + config.name));
if (messageError) {
login.appendChild(createMessage(messageError, "warn"));
}
var form = document.createElement("form");
form.setAttribute("action", keycloak.registerUrl);
form.setAttribute("method", "post");
login.appendChild(form);
form.appendChild(createInput("register", "username", "Username"));
form.appendChild(createInput("register", "email", "Email", "email"));
form.appendChild(createInput("register", "firstName", "First name"));
form.appendChild(createInput("register", "lastName", "Last name"));
form.appendChild(createInput("register", "password", "Password", "password"));
var buttonsDiv = document.createElement("div");
buttonsDiv.setAttribute("class", "keycloak-login-buttons");
form.appendChild(buttonsDiv);
var submitButton = document.createElement("button");
submitButton.setAttribute("type", "submit");
submitButton.textContent = "Register";
buttonsDiv.appendChild(submitButton);
var cancelButton = document.createElement("button");
cancelButton.setAttribute("type", "button");
cancelButton.setAttribute("onclick", "location.href='" + keycloak.loginUrl + "'");
cancelButton.textContent = "Cancel";
buttonsDiv.appendChild(cancelButton);
};
keycloak.getConfig(success);
};
return keycloak;
}());

View File

@ -0,0 +1,39 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/default.css" rel="stylesheet">
<script src="js/angular.js"></script>
<script src="js/angular-resource.js"></script>
<script src="js/app.js"></script>
</head>
<body class=keycloak-login-page data-ng-app=keycloak>
<div id=keycloak-login-container data-ng-controller=LoginCtrl>
<div id=keycloak-login-standard>
<h1>Login to {{config.name}}</h1>
<form action="#">
<label for=username>Username</label>
<input id=username type=text data-ng-model=username required />
<label for=password>Password</label>
<input id=password type=text data-ng-model=password required />
<div><button class="btn btn-primary" id=keycloak-login-submit type=submit>Login</button></div>
</form>
</div>
<div id=keycloak-login-social>
<h3>Login with</h3>
<div data-ng-repeat="p in config.providers">
<a href="/social/{{config.id}}/provider/{{p}}"><img data-ng-src="icons/{{p}}.png" /></a>
</div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,51 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/default.css" rel="stylesheet">
<script src="js/angular.js"></script>
<script src="js/angular-resource.js"></script>
<script src="js/app.js"></script>
</head>
<body class=keycloak-login-page data-ng-app=keycloak>
<div id=keycloak-login-container data-ng-controller=LoginCtrl>
<div id=keycloak-login-standard>
<h1>Register with {{config.name}}</h1>
<form action="#">
<label for=firstname>Firstname</label>
<input id=firstname type=text data-ng-model=firstname />
<label for=lastname>Lastname</label>
<input id=lastname type=text data-ng-model=lastname />
<label for=email>Email</label>
<input id=email type=email data-ng-model=email />
<label for=username>Username</label>
<input id=username type=text data-ng-model=username />
<label for=password>Password</label>
<input id=password type=text data-ng-model=password required />
<label for=password-confirm>Password confirmation</label>
<input id=password-confirm type=text data-ng-model=passwordConfirm required pattern="{{password}}" title="Passwords don't match" />
<div><button class="btn btn-primary" id=keycloak-login-submit type=submit>Register</button></div>
</form>
</div>
<div id=keycloak-login-social>
<h3>Login with</h3>
<div data-ng-repeat="p in config.providers">
<a href="/social/{{config.id}}/provider/{{p}}"><img data-ng-src="icons/{{p}}.png" /></a>
</div>
</div>
</div>
</body>
</html>

37
server/pom.xml Executable file
View File

@ -0,0 +1,37 @@
<?xml version="1.0"?>
<project>
<parent>
<artifactId>keycloak-parent</artifactId>
<groupId>org.keycloak</groupId>
<version>1.0-alpha-1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>keycloak-server</artifactId>
<name>Keycloak Server</name>
<packaging>war</packaging>
<description />
<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-sdk-html</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>