Compare commits
1 Commits
es_rev9844
...
es_rev9847
| Author | SHA1 | Date | |
|---|---|---|---|
| 3496536751 |
@@ -0,0 +1 @@
|
|||||||
|
{include file="block_account_info.tpl" /}
|
||||||
@@ -1,62 +1,34 @@
|
|||||||
<div class="primary-tabs">
|
<div class="primary-tabs">
|
||||||
{if isset="$user"}
|
{if isset="$user"}
|
||||||
<h3>Account Information</h3>
|
<h3>Account Information</h3>
|
||||||
<div>
|
<ul class="user-information">
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<label>Username:</label> {$user.name/}
|
||||||
<label>Username:</label> {$user.name/}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label>Email:</label> {$user.email/}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label>Creation Date:</label> {$user.creation_date/}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label>Last login:</label> {$user.last_login_date/}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<form method="get" action="{$site_url/}{$auth_login_strategy/}">
|
|
||||||
<button type="submit">Logout</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div>
|
||||||
<hr>
|
<label>Email:</label> {$user.email/}
|
||||||
{include file="block_change_password.tpl" /}
|
</div>
|
||||||
<hr>
|
<div>
|
||||||
<h4>Roles</h4>
|
<label>Creation Date:</label> {$user.creation_date/} (UTC)
|
||||||
<div>
|
</div>
|
||||||
{foreach item="ic" from="$roles"}
|
<div>
|
||||||
<div>
|
<label>Last login:</label> {$user.last_login_date/} (UTC)
|
||||||
<ul>
|
</div>
|
||||||
<li>
|
<div>
|
||||||
<strong>{$ic.name/}</strong>
|
<form method="get" action="{$site_url/}account/roc-logout">
|
||||||
<ul>
|
<button type="submit">Logout</button>
|
||||||
<li> <i>permissions</i>
|
</form>
|
||||||
<ul>
|
</div>
|
||||||
{foreach item="ip" from="$ic.permissions"}
|
</ul>
|
||||||
<li>{$ip/}</li>
|
|
||||||
{/foreach}
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
{/foreach}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<h4>Profile</h4>
|
<h4>Profile</h4>
|
||||||
<div>
|
<ul class="user-profile">
|
||||||
{foreach item="the_value" key="the_name" from="$user.profile"}
|
{foreach item="the_value" key="the_name" from="$user.profile"}
|
||||||
<div>
|
<li>
|
||||||
<label>{$the_name/}:</label> {$the_value/}
|
<label>{$the_name/}:</label><div>{$the_value/}</div>
|
||||||
</div>
|
</li>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</div>
|
</ul>
|
||||||
{/if}
|
{/if}
|
||||||
{unless isset="$user"}
|
{unless isset="$user"}
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<form action="{$site_url/}account/change-password" method="post">
|
<form action="{$site_url/}account/change-password" method="post">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Change Password Form</legend>
|
<legend>Change Password</legend>
|
||||||
<div>
|
<div>
|
||||||
<input type="password" id="password" name="password" value="" required/>
|
<input type="password" id="password" name="password" value="" required/>
|
||||||
<label for="password">Password</label>
|
<label for="password">Password</label>
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
<div class="primary-tabs">
|
|
||||||
{unless isset="$user"}
|
|
||||||
<h3>Login or <a href="{$site_url/}account/roc-register">Register</a></h3>
|
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
<form action method="POST">
|
|
||||||
<div>
|
|
||||||
<input type="text" name="username" required>
|
|
||||||
<label>Username</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<input type="password" name="password" required>
|
|
||||||
<label>Password</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="button" onclick="ROC_AUTH.login();">Login</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
<p>
|
|
||||||
<a href="{$site_url/}account/new-password">Forgot password?</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{/unless}
|
|
||||||
</div>
|
|
||||||
@@ -1,307 +1,291 @@
|
|||||||
var ROC_AUTH = ROC_AUTH || { };
|
var ROC_AUTH = ROC_AUTH || { };
|
||||||
|
|
||||||
var loginURL = "/basic_auth_login";
|
var loginURL = "/roc-basic-login";
|
||||||
var logoutURL = "/basic_auth_logoff";
|
var logoutURL = "/roc-basic-logoff";
|
||||||
|
|
||||||
var userAgent = navigator.userAgent.toLowerCase();
|
var userAgent = navigator.userAgent.toLowerCase();
|
||||||
var firstLogIn = true;
|
var firstLogIn = true;
|
||||||
|
|
||||||
ROC_AUTH.login = function() {
|
ROC_AUTH.login = function() {
|
||||||
var form = document.forms['cms_basic_auth'];
|
var form = document.forms['cms_basic_auth'];
|
||||||
var username = form.username.value;
|
var username = form.username.value;
|
||||||
var password = form.password.value;
|
var password = form.password.value;
|
||||||
//var host = form.host.value;
|
//var host = form.host.value;
|
||||||
var origin = window.location.origin + window.location.pathname;
|
var origin = window.location.origin + window.location.pathname;
|
||||||
var _login = function(){
|
var _login = function(){
|
||||||
|
if (document.getElementById('myModalFormId') !== null ) {
|
||||||
|
ROC_AUTH.remove ('myModalFormId');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (username === "" || password === "") {
|
||||||
if (document.getElementById('myModalFormId') !== null ) {
|
if (document.getElementById('myModalFormId') === null ) {
|
||||||
ROC_AUTH.remove ('myModalFormId');
|
var newdiv = document.createElement('div');
|
||||||
}
|
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
||||||
|
newdiv.id = 'myModalFormId';
|
||||||
|
$(".login-box").append(newdiv);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//Instantiate HTTP Request
|
||||||
|
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
||||||
|
request.open("GET", loginURL, true, username, password);
|
||||||
|
request.send(null);
|
||||||
|
|
||||||
|
//Process Response
|
||||||
|
request.onreadystatechange = function(){
|
||||||
|
if (request.readyState == 4) {
|
||||||
|
if (request.status==200) {
|
||||||
|
delete form;
|
||||||
|
window.location=window.location.origin;
|
||||||
|
} else {
|
||||||
|
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
|
||||||
|
// .. ?
|
||||||
|
}
|
||||||
|
if (document.getElementById('myModalFormId') === null ) {
|
||||||
|
var newdiv = document.createElement('div');
|
||||||
|
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
||||||
|
newdiv.id = 'myModalFormId';
|
||||||
|
$(".login-box").append(newdiv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (username === "" || password === "") {
|
var userAgent = navigator.userAgent.toLowerCase();
|
||||||
if (document.getElementById('myModalFormId') === null ) {
|
if (userAgent.indexOf("firefox") != -1) { //TODO: check version number
|
||||||
var newdiv = document.createElement('div');
|
if (firstLogIn) {
|
||||||
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
_login();
|
||||||
newdiv.id = 'myModalFormId';
|
} else {
|
||||||
$(".primary-tabs").append(newdiv);
|
ROC_AUTH.logoff(_login);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
|
_login();
|
||||||
//Instantiate HTTP Request
|
}
|
||||||
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
|
||||||
request.open("GET", loginURL, true, username, password);
|
|
||||||
request.send(null);
|
|
||||||
|
|
||||||
//Process Response
|
|
||||||
request.onreadystatechange = function(){
|
|
||||||
if (request.readyState == 4) {
|
|
||||||
if (request.status==200) {
|
|
||||||
delete form;
|
|
||||||
window.location=window.location.origin;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.getElementById('myModalFormId') === null ) {
|
|
||||||
var newdiv = document.createElement('div');
|
|
||||||
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
|
||||||
newdiv.id = 'myModalFormId';
|
|
||||||
$(".primary-tabs").append(newdiv);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
if (firstLogIn) {
|
||||||
}
|
firstLogIn = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var userAgent = navigator.userAgent.toLowerCase();
|
|
||||||
if (userAgent.indexOf("firefox") != -1){ //TODO: check version number
|
|
||||||
if (firstLogIn) _login();
|
|
||||||
else logoff(_login);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
_login();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstLogIn) firstLogIn = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ROC_AUTH.login_with_redirect = function() {
|
ROC_AUTH.login_with_redirect = function() {
|
||||||
var form = document.forms[2];
|
var form = document.forms[2];
|
||||||
var username = form.username.value;
|
var username = form.username.value;
|
||||||
var password = form.password.value;
|
var password = form.password.value;
|
||||||
var host = form.host.value;
|
var host = form.host.value;
|
||||||
var _login = function(){
|
var _login = function(){
|
||||||
|
var redirectURL = form.redirect && form.redirect.value || "";
|
||||||
|
$("#imgProgressRedirect").show();
|
||||||
|
|
||||||
var redirectURL = form.redirect && form.redirect.value || "";
|
if (document.getElementById('myModalFormId') !== null ) {
|
||||||
|
ROC_AUTH.remove ('myModalFormId');
|
||||||
|
}
|
||||||
|
if (username === "" || password === "") {
|
||||||
|
if (document.getElementById('myModalFormId') === null ) {
|
||||||
|
var newdiv = document.createElement('div');
|
||||||
|
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
||||||
|
newdiv.id = 'myModalFormId';
|
||||||
|
$(".login-box").append(newdiv);
|
||||||
|
$("#imgProgressRedirect").hide();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//Instantiate HTTP Request
|
||||||
|
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
||||||
|
request.open("GET", host + loginURL, true, username, password);
|
||||||
|
request.send(null);
|
||||||
|
|
||||||
|
//Process Response
|
||||||
|
request.onreadystatechange = function() {
|
||||||
|
if (request.readyState == 4) {
|
||||||
|
if (request.status==200) {
|
||||||
|
if (redirectURL === "") {
|
||||||
|
window.location=host + "/";
|
||||||
|
} else {
|
||||||
|
window.location=host + redirectURL;
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
|
||||||
|
}
|
||||||
|
if (document.getElementById('myModalFormId') === null ) {
|
||||||
|
var newdiv = document.createElement('div');
|
||||||
|
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
||||||
|
newdiv.id = 'myModalFormId';
|
||||||
|
$(".login-box").append(newdiv);
|
||||||
|
$("#imgProgressRedirect").hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$("#imgProgressRedirect").show();
|
var userAgent = navigator.userAgent.toLowerCase();
|
||||||
|
if (userAgent.indexOf("firefox") != -1){ //TODO: check version number
|
||||||
if (document.getElementById('myModalFormId') !== null ) {
|
if (firstLogIn) {
|
||||||
ROC_AUTH.remove ('myModalFormId');
|
_login();
|
||||||
}
|
} else {
|
||||||
|
ROC_AUTH.logoff(_login);
|
||||||
|
}
|
||||||
if (username === "" || password === "") {
|
} else{
|
||||||
if (document.getElementById('myModalFormId') === null ) {
|
_login();
|
||||||
var newdiv = document.createElement('div');
|
}
|
||||||
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
if (firstLogIn) {
|
||||||
newdiv.id = 'myModalFormId';
|
firstLogIn = false;
|
||||||
$(".primary-tabs").append(newdiv);
|
}
|
||||||
$("#imgProgressRedirect").hide();
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
|
|
||||||
//Instantiate HTTP Request
|
|
||||||
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
|
||||||
request.open("GET", host.concat(loginURL), true, username, password);
|
|
||||||
request.send(null);
|
|
||||||
|
|
||||||
//Process Response
|
|
||||||
request.onreadystatechange = function(){
|
|
||||||
if (request.readyState == 4) {
|
|
||||||
if (request.status==200) {
|
|
||||||
if (redirectURL === "") {
|
|
||||||
window.location=host.concat("/");
|
|
||||||
} else {
|
|
||||||
window.location=host.concat(redirectURL);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.getElementById('myModalFormId') === null ) {
|
|
||||||
var newdiv = document.createElement('div');
|
|
||||||
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
|
||||||
newdiv.id = 'myModalFormId';
|
|
||||||
$(".primary-tabs").append(newdiv);
|
|
||||||
$("#imgProgressRedirect").hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var userAgent = navigator.userAgent.toLowerCase();
|
|
||||||
if (userAgent.indexOf("firefox") != -1){ //TODO: check version number
|
|
||||||
if (firstLogIn) _login();
|
|
||||||
else logoff(_login);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
_login();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstLogIn) firstLogIn = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ROC_AUTH.getQueryParameterByName = function (name) {
|
ROC_AUTH.getQueryParameterByName = function (name) {
|
||||||
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
||||||
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
|
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search);
|
||||||
results = regex.exec(location.search);
|
return results === null ? " " : decodeURIComponent(results[1].replace(/\+/g, " "));
|
||||||
return results === null ? " " : decodeURIComponent(results[1].replace(/\+/g, " "));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ROC_AUTH.logoff = function(callback){
|
ROC_AUTH.logoff = function(callback){
|
||||||
var form = document.forms[0];
|
var form = document.forms[0];
|
||||||
var host = form.host.value;
|
var host = form.host.value;
|
||||||
|
|
||||||
if (userAgent.indexOf("msie") != -1) {
|
if (userAgent.indexOf("msie") != -1) {
|
||||||
document.execCommand("ClearAuthenticationCache");
|
document.execCommand("ClearAuthenticationCache");
|
||||||
}
|
} else if (userAgent.indexOf("firefox") != -1){ //TODO: check version number
|
||||||
else if (userAgent.indexOf("firefox") != -1){ //TODO: check version number
|
var request1 = new XMLHttpRequest();
|
||||||
|
var request2 = new XMLHttpRequest();
|
||||||
var request1 = new XMLHttpRequest();
|
|
||||||
var request2 = new XMLHttpRequest();
|
//Logout. Tell the server not to return the "WWW-Authenticate" header
|
||||||
|
request1.open("GET", host + logoutURL + "?prompt=false", true);
|
||||||
//Logout. Tell the server not to return the "WWW-Authenticate" header
|
request1.send("");
|
||||||
request1.open("GET", host.concat(logoutURL) + "?prompt=false", true);
|
request1.onreadystatechange = function(){
|
||||||
request1.send("");
|
if (request1.readyState == 4) {
|
||||||
request1.onreadystatechange = function(){
|
//Sign in with dummy credentials to clear the auth cache
|
||||||
if (request1.readyState == 4) {
|
request2.open("GET", host + logoutURL, true, "logout", "logout");
|
||||||
|
request2.send("");
|
||||||
//Sign in with dummy credentials to clear the auth cache
|
request2.onreadystatechange = function(){
|
||||||
request2.open("GET", host.concat(logoutURL), true, "logout", "logout");
|
if (request2.readyState == 4) {
|
||||||
request2.send("");
|
if (callback!=null) {
|
||||||
|
callback.call();
|
||||||
request2.onreadystatechange = function(){
|
} else {
|
||||||
if (request2.readyState == 4) {
|
window.location=host + logoutURL;
|
||||||
if (callback!=null) { callback.call(); } else { window.location=host.concat(logoutURL);}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
}
|
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
||||||
else {
|
request.open("GET", host + logoutURL, true, "logout", "logout");
|
||||||
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
request.send("");
|
||||||
request.open("GET", host.concat(logoutURL), true, "logout", "logout");
|
request.onreadystatechange = function(){
|
||||||
request.send("");
|
if (request.status==401 || request.status==403 ) {
|
||||||
request.onreadystatechange = function(){
|
window.location=host + logoutURL;
|
||||||
if (request.status==401 || request.status==403 ) { window.location=host.concat(logoutURL);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ROC_AUTH.remove = function (id)
|
ROC_AUTH.remove = function (id) {
|
||||||
{
|
var element = document.getElementById(id);
|
||||||
var element = document.getElementById(id);
|
element.outerHTML = "";
|
||||||
element.outerHTML = "";
|
delete element;
|
||||||
delete element;
|
return;
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
if (typeof String.prototype.contains != 'function') {
|
||||||
if (typeof String.prototype.contains != 'function') {
|
String.prototype.contains = function (str){
|
||||||
String.prototype.contains = function (str){
|
return this.indexOf(str) != -1;
|
||||||
return this.indexOf(str) != -1;
|
};
|
||||||
};
|
}
|
||||||
}
|
ROC_AUTH.progressive_loging();
|
||||||
ROC_AUTH.progressive_loging();
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
ROC_AUTH.progressive_loging = function () {
|
ROC_AUTH.progressive_loging = function () {
|
||||||
|
ROC_AUTH.login_href();
|
||||||
ROC_AUTH.login_href();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
$(document).keypress(function(e) {
|
$(document).keypress(function(e) {
|
||||||
if ((e.which === 13) && (e.target.localName === 'input' && e.target.id === 'password')) {
|
if ((e.which === 13) && (e.target.localName === 'input' && e.target.id === 'password')) {
|
||||||
ROC_AUTH.login();
|
ROC_AUTH.login();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ROC_AUTH.OnOneClick = function(event) {
|
ROC_AUTH.OnOneClick = function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if ( document.forms[0] === undefined ) {
|
if ( document.forms[0] === undefined ) {
|
||||||
ROC_AUTH.create_form();
|
ROC_AUTH.create_form();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
ROC_AUTH.login_href = function() {
|
ROC_AUTH.login_href = function() {
|
||||||
var els = document.getElementsByTagName("a");
|
var els = document.getElementsByTagName("a");
|
||||||
for (var i = 0, l = els.length; i < l; i++) {
|
for (var i = 0, l = els.length; i < l; i++) {
|
||||||
var el = els[i];
|
var el = els[i];
|
||||||
if (el.href.contains("/basic_auth_login?destination")) {
|
if (el.href.contains(loginURL + "?destination")) {
|
||||||
loginURL = el.href;
|
// loginURL = el.href;
|
||||||
var OneClick = el;
|
var OneClick = el;
|
||||||
OneClick.addEventListener('click', ROC_AUTH.OnOneClick, false);
|
OneClick.addEventListener('click', ROC_AUTH.OnOneClick, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ROC_AUTH.create_form = function() {
|
ROC_AUTH.create_form = function() {
|
||||||
|
|
||||||
// Fetching HTML Elements in Variables by ID.
|
// Fetching HTML Elements in Variables by ID.
|
||||||
var createform = document.createElement('form'); // Create New Element Form
|
var createform = document.createElement('form'); // Create New Element Form
|
||||||
createform.setAttribute("action", ""); // Setting Action Attribute on Form
|
createform.setAttribute("action", ""); // Setting Action Attribute on Form
|
||||||
createform.setAttribute("method", "post"); // Setting Method Attribute on Form
|
createform.setAttribute("method", "post"); // Setting Method Attribute on Form
|
||||||
$("body").append(createform);
|
$("body").append(createform);
|
||||||
|
|
||||||
var heading = document.createElement('h2'); // Heading of Form
|
var heading = document.createElement('h2'); // Heading of Form
|
||||||
heading.innerHTML = "Login Form ";
|
heading.innerHTML = "Login Form ";
|
||||||
createform.appendChild(heading);
|
createform.appendChild(heading);
|
||||||
|
|
||||||
var line = document.createElement('hr'); // Giving Horizontal Row After Heading
|
var line = document.createElement('hr'); // Giving Horizontal Row After Heading
|
||||||
createform.appendChild(line);
|
createform.appendChild(line);
|
||||||
|
|
||||||
var linebreak = document.createElement('br');
|
var linebreak = document.createElement('br');
|
||||||
createform.appendChild(linebreak);
|
createform.appendChild(linebreak);
|
||||||
|
|
||||||
var namelabel = document.createElement('label'); // Create Label for Name Field
|
var namelabel = document.createElement('label'); // Create Label for Name Field
|
||||||
namelabel.innerHTML = "Username : "; // Set Field Labels
|
namelabel.innerHTML = "Username : "; // Set Field Labels
|
||||||
createform.appendChild(namelabel);
|
createform.appendChild(namelabel);
|
||||||
|
|
||||||
var inputelement = document.createElement('input'); // Create Input Field for UserName
|
var inputelement = document.createElement('input'); // Create Input Field for UserName
|
||||||
inputelement.setAttribute("type", "text");
|
inputelement.setAttribute("type", "text");
|
||||||
inputelement.setAttribute("name", "username");
|
inputelement.setAttribute("name", "username");
|
||||||
inputelement.setAttribute("required","required");
|
inputelement.setAttribute("required","required");
|
||||||
createform.appendChild(inputelement);
|
createform.appendChild(inputelement);
|
||||||
|
|
||||||
var linebreak = document.createElement('br');
|
var linebreak = document.createElement('br');
|
||||||
createform.appendChild(linebreak);
|
createform.appendChild(linebreak);
|
||||||
|
|
||||||
var passwordlabel = document.createElement('label'); // Create Label for Password Field
|
var passwordlabel = document.createElement('label'); // Create Label for Password Field
|
||||||
passwordlabel.innerHTML = "Password : ";
|
passwordlabel.innerHTML = "Password : ";
|
||||||
createform.appendChild(passwordlabel);
|
createform.appendChild(passwordlabel);
|
||||||
|
|
||||||
var passwordelement = document.createElement('input'); // Create Input Field for Password.
|
var passwordelement = document.createElement('input'); // Create Input Field for Password.
|
||||||
passwordelement.setAttribute("type", "password");
|
passwordelement.setAttribute("type", "password");
|
||||||
passwordelement.setAttribute("name", "password");
|
passwordelement.setAttribute("name", "password");
|
||||||
passwordelement.setAttribute("id", "password");
|
passwordelement.setAttribute("id", "password");
|
||||||
passwordelement.setAttribute("required","required");
|
passwordelement.setAttribute("required","required");
|
||||||
createform.appendChild(passwordelement);
|
createform.appendChild(passwordelement);
|
||||||
|
|
||||||
|
|
||||||
var passwordbreak = document.createElement('br');
|
var passwordbreak = document.createElement('br');
|
||||||
createform.appendChild(passwordbreak);
|
createform.appendChild(passwordbreak);
|
||||||
|
|
||||||
|
|
||||||
var submitelement = document.createElement('button'); // Append Submit Button
|
var submitelement = document.createElement('button'); // Append Submit Button
|
||||||
submitelement.setAttribute("type", "button");
|
submitelement.setAttribute("type", "button");
|
||||||
submitelement.setAttribute("onclick", "ROC_AUTH.login();");
|
submitelement.setAttribute("onclick", "ROC_AUTH.login();");
|
||||||
submitelement.innerHTML = "Sign In ";
|
submitelement.innerHTML = "Sign In ";
|
||||||
createform.appendChild(submitelement);
|
createform.appendChild(submitelement);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -310,16 +294,16 @@ var password = document.getElementById("password");
|
|||||||
var confirm_password = document.getElementById("confirm_password");
|
var confirm_password = document.getElementById("confirm_password");
|
||||||
|
|
||||||
ROC_AUTH.validatePassword =function(){
|
ROC_AUTH.validatePassword =function(){
|
||||||
if ((password != null) && (confirm_password != null)) {
|
if ((password != null) && (confirm_password != null)) {
|
||||||
if(password.value != confirm_password.value) {
|
if(password.value != confirm_password.value) {
|
||||||
confirm_password.setCustomValidity("Passwords Don't Match");
|
confirm_password.setCustomValidity("Passwords Don't Match");
|
||||||
} else {
|
} else {
|
||||||
confirm_password.setCustomValidity('');
|
confirm_password.setCustomValidity('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((password != null) && (confirm_password != null)) {
|
if ((password != null) && (confirm_password != null)) {
|
||||||
password.onchange = ROC_AUTH.validatePassword();
|
password.onchange = ROC_AUTH.validatePassword();
|
||||||
confirm_password.onkeyup = ROC_AUTH.validatePassword;
|
confirm_password.onkeyup = ROC_AUTH.validatePassword;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,23 @@
|
|||||||
<div class="primary-tabs">
|
{unless isset="$user"}
|
||||||
{unless isset="$user"}
|
<div class="login-box">
|
||||||
<h3>Login or <a href="{$site_url/}account/roc-register">Register</a></h3>
|
<div class="description">The "Basic Auth" relies on the HTTP basic acces authentication.<br/>(see also: <a href="https://en.wikipedia.org/wiki/Basic_access_authentication">https://en.wikipedia.org/wiki/Basic_access_authentication</a> )</div>
|
||||||
|
<h3>Login or <a href="{$site_url/}account/roc-register">Register</a></h3>
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<form name="cms_basic_auth" action="{$site_url/}roc-basic-login" method="POST">
|
||||||
<form name="cms_basic_auth" action method="POST">
|
<input type="hidden" name="host" id="host" value="{$site_url/}">
|
||||||
<div>
|
<div>
|
||||||
<input type="text" name="username" id="username" required>
|
<input type="text" name="username" id="username" required>
|
||||||
<label>Username</label>
|
<label>Username</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
<div>
|
<input type="password" name="password" id="password" required>
|
||||||
<input type="password" name="password" id="password" required>
|
<label>Password</label>
|
||||||
<label>Password</label>
|
</div>
|
||||||
</div>
|
<button type="button" onclick="ROC_AUTH.login();">Login</button>
|
||||||
|
</form>
|
||||||
<button type="button" onclick="ROC_AUTH.login();">Login</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<a href="{$site_url/}account/new-password">Forgot password?</a>
|
||||||
<p>
|
|
||||||
<a href="{$site_url/}account/new-password">Forgot password?</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{/unless}
|
|
||||||
</div>
|
</div>
|
||||||
|
{/unless}
|
||||||
|
|||||||
@@ -1,37 +1,23 @@
|
|||||||
<div class="primary-tabs">
|
{unless isset="$user"}
|
||||||
{unless isset="$user"}
|
<div class="login-box">
|
||||||
<h3>Login or <a href="{$site_url/}account/roc-register">Register</a></h3>
|
<div class="description">The "Session" is the standard authentication system. (based on cookie)</div>
|
||||||
<div>
|
<h3>Login or <a href="{$site_url/}account/roc-register">Register</a></h3>
|
||||||
<div>
|
<div>
|
||||||
<form name="cms_session_auth" action="{$site_url/}account/login-with-session" method="POST">
|
<form name="cms_session_auth" action="{$site_url/}account/auth/roc-session-login" method="POST">
|
||||||
<div>
|
|
||||||
<input type="text" name="username" id="username" required value="{$username/}">
|
|
||||||
<label>Username</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<input type="password" name="password" id="password" required >
|
|
||||||
<label>Password</label>
|
|
||||||
</div>
|
|
||||||
<button type="submit">Login</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div>
|
<div>
|
||||||
<p>
|
<input type="text" name="username" id="username" required value="{$username/}">
|
||||||
<a href="{$site_url/}account/new-password">Forgot password?</a>
|
<label>Username</label>
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{/unless}
|
|
||||||
{if isset=$error}
|
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<input type="password" name="password" id="password" required >
|
||||||
<p>
|
<label>Password</label>
|
||||||
<strong>{$error/}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<button type="submit">Login</button>
|
||||||
{/if}
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<a href="{$site_url/}account/new-password">Forgot password?</a>
|
||||||
|
</div>
|
||||||
|
{if isset="$error"}<div class="error">{$error/}</div>{/if}
|
||||||
|
</div>
|
||||||
|
{/unless}
|
||||||
|
|||||||
@@ -37,6 +37,80 @@ feature -- Access
|
|||||||
weight: INTEGER
|
weight: INTEGER
|
||||||
-- Optional weight used for order.
|
-- Optional weight used for order.
|
||||||
|
|
||||||
|
query_string: detachable STRING
|
||||||
|
-- Query string from `location'.
|
||||||
|
local
|
||||||
|
i: INTEGER
|
||||||
|
loc: like location
|
||||||
|
do
|
||||||
|
loc := location
|
||||||
|
i := loc.index_of ('?', 1)
|
||||||
|
if i > 0 then
|
||||||
|
Result := loc.substring (i + 1, loc.count)
|
||||||
|
i := loc.last_index_of ('#', loc.count)
|
||||||
|
if i > 0 then
|
||||||
|
Result.keep_head (i - 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
fragment_string: detachable STRING
|
||||||
|
-- Query string from `location'.
|
||||||
|
local
|
||||||
|
i: INTEGER
|
||||||
|
loc: like location
|
||||||
|
do
|
||||||
|
loc := location
|
||||||
|
i := loc.last_index_of ('#', loc.count)
|
||||||
|
if i > 0 then
|
||||||
|
Result := loc.substring (i + 1, loc.count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Element change
|
||||||
|
|
||||||
|
add_query_parameter (a_encoded_name: READABLE_STRING_8; a_encoded_value: detachable READABLE_STRING_8)
|
||||||
|
-- Add query parameter "$a_encoded_name=$a_encoded_value" to `location'.
|
||||||
|
-- note: the argument must already be url encoded!
|
||||||
|
local
|
||||||
|
q: STRING_8
|
||||||
|
f: detachable READABLE_STRING_8
|
||||||
|
i,j: INTEGER
|
||||||
|
loc: STRING_8
|
||||||
|
do
|
||||||
|
create loc.make_from_string (location)
|
||||||
|
|
||||||
|
j := loc.last_index_of ('#', loc.count)
|
||||||
|
if j > 0 then
|
||||||
|
f := loc.substring (j, loc.count)
|
||||||
|
loc.keep_head (j - 1)
|
||||||
|
end
|
||||||
|
i := loc.index_of ('?', 1)
|
||||||
|
if i > 0 then
|
||||||
|
q := loc.substring (i + 1, loc.count)
|
||||||
|
loc.keep_head (i)
|
||||||
|
else
|
||||||
|
create q.make_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
if not q.is_empty then
|
||||||
|
q.append_character ('&')
|
||||||
|
end
|
||||||
|
|
||||||
|
q.append (a_encoded_name)
|
||||||
|
if a_encoded_value /= Void then
|
||||||
|
q.append_character ('=')
|
||||||
|
q.append (a_encoded_value)
|
||||||
|
end
|
||||||
|
|
||||||
|
loc.append_character ('?')
|
||||||
|
loc.append (q)
|
||||||
|
if f /= Void then
|
||||||
|
loc.append (f)
|
||||||
|
end
|
||||||
|
location := loc
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Comparison
|
feature -- Comparison
|
||||||
|
|
||||||
is_less alias "<" (other: like Current): BOOLEAN
|
is_less alias "<" (other: like Current): BOOLEAN
|
||||||
@@ -134,6 +208,6 @@ feature -- Status report
|
|||||||
end
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
|
copyright: "2011-2016, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -65,9 +65,6 @@ feature -- Access
|
|||||||
email: detachable READABLE_STRING_8
|
email: detachable READABLE_STRING_8
|
||||||
-- User email.
|
-- User email.
|
||||||
|
|
||||||
profile: detachable CMS_USER_PROFILE
|
|
||||||
-- User profile.
|
|
||||||
|
|
||||||
creation_date: DATE_TIME
|
creation_date: DATE_TIME
|
||||||
-- Creation date.
|
-- Creation date.
|
||||||
|
|
||||||
@@ -189,26 +186,6 @@ feature -- Change element
|
|||||||
email_set: email = a_email
|
email_set: email = a_email
|
||||||
end
|
end
|
||||||
|
|
||||||
set_profile (prof: like profile)
|
|
||||||
-- Set `profile' with `prof'.
|
|
||||||
do
|
|
||||||
profile := prof
|
|
||||||
ensure
|
|
||||||
profile_set: profile = prof
|
|
||||||
end
|
|
||||||
|
|
||||||
set_profile_item (k: READABLE_STRING_8; v: READABLE_STRING_8)
|
|
||||||
local
|
|
||||||
prof: like profile
|
|
||||||
do
|
|
||||||
prof := profile
|
|
||||||
if prof = Void then
|
|
||||||
create prof.make
|
|
||||||
profile := prof
|
|
||||||
end
|
|
||||||
prof.force (v, k)
|
|
||||||
end
|
|
||||||
|
|
||||||
set_last_login_date (dt: like last_login_date)
|
set_last_login_date (dt: like last_login_date)
|
||||||
do
|
do
|
||||||
last_login_date := dt
|
last_login_date := dt
|
||||||
@@ -284,7 +261,6 @@ feature -- Status change
|
|||||||
status_set: status = a_status
|
status_set: status = a_status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- User status
|
feature -- User status
|
||||||
|
|
||||||
not_active: INTEGER = 0
|
not_active: INTEGER = 0
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
note
|
|
||||||
description: "[
|
|
||||||
User profile used to extend information associated with a {CMS_USER}.
|
|
||||||
]"
|
|
||||||
date: "$Date$"
|
|
||||||
revision: "$Revision$"
|
|
||||||
|
|
||||||
class
|
|
||||||
CMS_USER_PROFILE
|
|
||||||
|
|
||||||
inherit
|
|
||||||
TABLE_ITERABLE [READABLE_STRING_8, READABLE_STRING_GENERAL]
|
|
||||||
|
|
||||||
create
|
|
||||||
make
|
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
|
||||||
|
|
||||||
make
|
|
||||||
-- Create Current profile.
|
|
||||||
do
|
|
||||||
create items.make (0)
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Access
|
|
||||||
|
|
||||||
item (k: READABLE_STRING_GENERAL): detachable READABLE_STRING_8
|
|
||||||
-- Profile item associated with key `k'.
|
|
||||||
do
|
|
||||||
Result := items.item (k)
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Change
|
|
||||||
|
|
||||||
force (v: READABLE_STRING_8; k: READABLE_STRING_GENERAL)
|
|
||||||
-- Associated value `v' with key `k'.
|
|
||||||
do
|
|
||||||
items.force (v, k)
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Access
|
|
||||||
|
|
||||||
new_cursor: TABLE_ITERATION_CURSOR [READABLE_STRING_8, READABLE_STRING_GENERAL]
|
|
||||||
-- Fresh cursor associated with current structure
|
|
||||||
do
|
|
||||||
Result := items.new_cursor
|
|
||||||
end
|
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
|
||||||
|
|
||||||
items: STRING_TABLE [READABLE_STRING_8]
|
|
||||||
|
|
||||||
;note
|
|
||||||
copyright: "2011-2014, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
|
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
|
||||||
end
|
|
||||||
@@ -166,7 +166,7 @@ feature -- Error
|
|||||||
do_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
|
do_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
if attached current_user (req) as l_user then
|
if attached api.user as l_user then
|
||||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||||
if
|
if
|
||||||
l_id.is_integer and then
|
l_id.is_integer and then
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ feature -- Error
|
|||||||
do_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
|
do_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
if attached current_user (req) as l_user then
|
if attached api.user as l_user then
|
||||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||||
if
|
if
|
||||||
l_id.is_integer and then
|
l_id.is_integer and then
|
||||||
|
|||||||
@@ -86,12 +86,13 @@ feature -- Execution
|
|||||||
not l_roles.is_empty
|
not l_roles.is_empty
|
||||||
then
|
then
|
||||||
s.append ("<h4>Role(s):</h4>")
|
s.append ("<h4>Role(s):</h4>")
|
||||||
|
s.append ("<ul class=%"user-roles%">")
|
||||||
across l_roles as ic loop
|
across l_roles as ic loop
|
||||||
l_role := ic.item
|
l_role := ic.item
|
||||||
s.append ("<i>")
|
s.append ("<li>")
|
||||||
s.append (link (l_role.name, "admin/role/" + l_role.id.out, Void))
|
s.append (link (l_role.name, "admin/role/" + l_role.id.out, Void))
|
||||||
s.append ("</i>")
|
s.append ("</li>")
|
||||||
debug
|
if request.query_parameter ("debug") /= Void then
|
||||||
s.append ("<h5>Permissions:</h5>")
|
s.append ("<h5>Permissions:</h5>")
|
||||||
s.append ("<ul class=%"cms-permissions%">%N")
|
s.append ("<ul class=%"cms-permissions%">%N")
|
||||||
across l_role.permissions as perms_ic loop
|
across l_role.permissions as perms_ic loop
|
||||||
@@ -100,6 +101,7 @@ feature -- Execution
|
|||||||
s.append ("</ul>%N")
|
s.append ("</ul>%N")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
s.append ("</ul>%N")
|
||||||
end
|
end
|
||||||
|
|
||||||
s.append ("</div>")
|
s.append ("</div>")
|
||||||
|
|||||||
17
modules/auth/cms_auth_api_i.e
Normal file
17
modules/auth/cms_auth_api_i.e
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
note
|
||||||
|
description: "[
|
||||||
|
Common interface for Auth module API.
|
||||||
|
]"
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
CMS_AUTH_API_I
|
||||||
|
|
||||||
|
inherit
|
||||||
|
CMS_MODULE_API
|
||||||
|
|
||||||
|
create
|
||||||
|
make
|
||||||
|
|
||||||
|
end
|
||||||
44
modules/auth/cms_auth_filter_i.e
Normal file
44
modules/auth/cms_auth_filter_i.e
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
note
|
||||||
|
description: "[
|
||||||
|
Processes a HTTP request, and depending on header, authenticate a current user or not.
|
||||||
|
]"
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
deferred class
|
||||||
|
CMS_AUTH_FILTER_I
|
||||||
|
|
||||||
|
inherit
|
||||||
|
WSF_FILTER
|
||||||
|
|
||||||
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
make (a_api: CMS_API)
|
||||||
|
-- Initialize Current handler with `a_api'.
|
||||||
|
do
|
||||||
|
api := a_api
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- API Service
|
||||||
|
|
||||||
|
api: CMS_API
|
||||||
|
|
||||||
|
feature -- Basic operations
|
||||||
|
|
||||||
|
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
|
-- <Precursor>
|
||||||
|
deferred
|
||||||
|
end
|
||||||
|
|
||||||
|
auth_strategy: STRING
|
||||||
|
deferred
|
||||||
|
end
|
||||||
|
|
||||||
|
set_current_user (u: CMS_USER)
|
||||||
|
do
|
||||||
|
api.set_user (u)
|
||||||
|
-- Record auth strategy:
|
||||||
|
api.set_execution_variable ("auth_strategy", auth_strategy)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
108
modules/auth/cms_auth_module_i.e
Normal file
108
modules/auth/cms_auth_module_i.e
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
note
|
||||||
|
description: "Common ancestor for Authentication modules."
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
deferred class
|
||||||
|
CMS_AUTH_MODULE_I
|
||||||
|
|
||||||
|
inherit
|
||||||
|
CMS_MODULE
|
||||||
|
redefine
|
||||||
|
setup_hooks
|
||||||
|
end
|
||||||
|
|
||||||
|
CMS_HOOK_AUTO_REGISTER
|
||||||
|
|
||||||
|
CMS_HOOK_MENU_SYSTEM_ALTER
|
||||||
|
|
||||||
|
SHARED_LOGGER
|
||||||
|
|
||||||
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
make
|
||||||
|
do
|
||||||
|
package := "authentication"
|
||||||
|
add_dependency ({CMS_AUTHENTICATION_MODULE})
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Access: auth strategy
|
||||||
|
|
||||||
|
login_title: READABLE_STRING_GENERAL
|
||||||
|
-- Module specific login title.
|
||||||
|
deferred
|
||||||
|
end
|
||||||
|
|
||||||
|
login_location: STRING
|
||||||
|
-- Login cms location for Current module.
|
||||||
|
deferred
|
||||||
|
end
|
||||||
|
|
||||||
|
logout_location: STRING
|
||||||
|
-- Logout cms location for Current module.
|
||||||
|
deferred
|
||||||
|
end
|
||||||
|
|
||||||
|
is_authenticating (a_response: CMS_RESPONSE): BOOLEAN
|
||||||
|
-- Is Current module strategy currently authenticating active user?
|
||||||
|
deferred
|
||||||
|
ensure
|
||||||
|
Result implies a_response.is_authenticated
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Hooks configuration
|
||||||
|
|
||||||
|
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
|
||||||
|
-- Module hooks configuration.
|
||||||
|
do
|
||||||
|
auto_subscribe_to_hooks (a_hooks)
|
||||||
|
a_hooks.subscribe_to_menu_system_alter_hook (Current)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Hooks
|
||||||
|
|
||||||
|
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)
|
||||||
|
-- <Precursor>
|
||||||
|
local
|
||||||
|
lnk: CMS_LOCAL_LINK
|
||||||
|
l_destination: READABLE_STRING_8
|
||||||
|
do
|
||||||
|
if attached {WSF_STRING} a_response.request.query_parameter ("destination") as p_destination then
|
||||||
|
l_destination := p_destination.url_encoded_value
|
||||||
|
else
|
||||||
|
l_destination := percent_encoded (a_response.location)
|
||||||
|
end
|
||||||
|
if is_authenticating (a_response) then
|
||||||
|
|
||||||
|
else
|
||||||
|
if a_response.location.starts_with ("account/auth/") then
|
||||||
|
create lnk.make (login_title, login_location)
|
||||||
|
if not l_destination.starts_with ("account/auth/") then
|
||||||
|
lnk.add_query_parameter ("destination", l_destination)
|
||||||
|
end
|
||||||
|
lnk.set_expandable (True)
|
||||||
|
a_response.add_to_primary_tabs (lnk)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
feature {NONE} -- Helpers
|
||||||
|
|
||||||
|
template_block (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE): detachable CMS_SMARTY_TEMPLATE_BLOCK
|
||||||
|
-- Smarty content block for `a_block_id'
|
||||||
|
local
|
||||||
|
p: detachable PATH
|
||||||
|
do
|
||||||
|
create p.make_from_string ("templates")
|
||||||
|
p := p.extended ("block_").appended (a_block_id).appended_with_extension ("tpl")
|
||||||
|
p := a_response.api.module_theme_resource_location (Current, p)
|
||||||
|
if p /= Void then
|
||||||
|
if attached p.entry as e then
|
||||||
|
create Result.make (a_block_id, Void, p.parent, e)
|
||||||
|
else
|
||||||
|
create Result.make (a_block_id, Void, p.parent, p)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -7,7 +7,6 @@ class
|
|||||||
CMS_AUTHENTICATION_MODULE
|
CMS_AUTHENTICATION_MODULE
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
||||||
CMS_MODULE
|
CMS_MODULE
|
||||||
redefine
|
redefine
|
||||||
setup_hooks,
|
setup_hooks,
|
||||||
@@ -33,8 +32,6 @@ inherit
|
|||||||
|
|
||||||
SHARED_LOGGER
|
SHARED_LOGGER
|
||||||
|
|
||||||
CMS_REQUEST_UTIL
|
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
@@ -93,9 +90,13 @@ feature -- Router
|
|||||||
local
|
local
|
||||||
m: WSF_URI_MAPPING
|
m: WSF_URI_MAPPING
|
||||||
do
|
do
|
||||||
create m.make_trailing_slash_ignored ("/account", create {WSF_URI_AGENT_HANDLER}.make (agent handle_account(a_api, ?, ?)))
|
create m.make_trailing_slash_ignored ("/account", create {WSF_URI_AGENT_HANDLER}.make (agent handle_account (a_api, ?, ?)))
|
||||||
a_router.map (m, a_router.methods_head_get)
|
a_router.map (m, a_router.methods_head_get)
|
||||||
|
|
||||||
|
create m.make_trailing_slash_ignored ("/account/edit", create {WSF_URI_AGENT_HANDLER}.make (agent handle_edit_account (a_api, ?, ?)))
|
||||||
|
a_router.map (m, a_router.methods_head_get)
|
||||||
|
|
||||||
|
|
||||||
a_router.handle ("/account/roc-login", create {WSF_URI_AGENT_HANDLER}.make (agent handle_login(a_api, ?, ?)), a_router.methods_head_get)
|
a_router.handle ("/account/roc-login", create {WSF_URI_AGENT_HANDLER}.make (agent handle_login(a_api, ?, ?)), a_router.methods_head_get)
|
||||||
a_router.handle ("/account/roc-logout", create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout(a_api, ?, ?)), a_router.methods_head_get)
|
a_router.handle ("/account/roc-logout", create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout(a_api, ?, ?)), a_router.methods_head_get)
|
||||||
a_router.handle ("/account/roc-register", create {WSF_URI_AGENT_HANDLER}.make (agent handle_register(a_api, ?, ?)), a_router.methods_get_post)
|
a_router.handle ("/account/roc-register", create {WSF_URI_AGENT_HANDLER}.make (agent handle_register(a_api, ?, ?)), a_router.methods_get_post)
|
||||||
@@ -104,8 +105,7 @@ feature -- Router
|
|||||||
a_router.handle ("/account/reactivate", create {WSF_URI_AGENT_HANDLER}.make (agent handle_reactivation(a_api, ?, ?)), a_router.methods_get_post)
|
a_router.handle ("/account/reactivate", create {WSF_URI_AGENT_HANDLER}.make (agent handle_reactivation(a_api, ?, ?)), a_router.methods_get_post)
|
||||||
a_router.handle ("/account/new-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_new_password(a_api, ?, ?)), a_router.methods_get_post)
|
a_router.handle ("/account/new-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_new_password(a_api, ?, ?)), a_router.methods_get_post)
|
||||||
a_router.handle ("/account/reset-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_reset_password(a_api, ?, ?)), a_router.methods_get_post)
|
a_router.handle ("/account/reset-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_reset_password(a_api, ?, ?)), a_router.methods_get_post)
|
||||||
a_router.handle ("/account/change-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_change_password(a_api, ?, ?)), a_router.methods_get_post)
|
a_router.handle ("/account/change/{field}", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_change_field (a_api, ?, ?)), a_router.methods_get_post)
|
||||||
a_router.handle ("/account/post-change-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_post_change_password(a_api, ?, ?)), a_router.methods_get)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -142,14 +142,22 @@ feature -- Hooks configuration
|
|||||||
create lnk.make (u.name, "account")
|
create lnk.make (u.name, "account")
|
||||||
lnk.set_weight (97)
|
lnk.set_weight (97)
|
||||||
a_menu_system.primary_menu.extend (lnk)
|
a_menu_system.primary_menu.extend (lnk)
|
||||||
|
|
||||||
create lnk.make ("Logout", "account/roc-logout")
|
create lnk.make ("Logout", "account/roc-logout")
|
||||||
lnk.set_weight (98)
|
|
||||||
a_menu_system.primary_menu.extend (lnk)
|
|
||||||
else
|
else
|
||||||
create lnk.make ("Login", "account/roc-login")
|
create lnk.make ("Login", "account/roc-login")
|
||||||
lnk.set_weight (98)
|
|
||||||
a_menu_system.primary_menu.extend (lnk)
|
|
||||||
end
|
end
|
||||||
|
lnk.set_weight (98)
|
||||||
|
if
|
||||||
|
a_response.location.starts_with_general ("account/auth/")
|
||||||
|
or a_response.location.starts_with_general ("account/roc-log")
|
||||||
|
then
|
||||||
|
-- ignore destination
|
||||||
|
else
|
||||||
|
lnk.add_query_parameter ("destination", percent_encoded (a_response.location))
|
||||||
|
end
|
||||||
|
a_menu_system.primary_menu.extend (lnk)
|
||||||
|
|
||||||
-- Add the link to the taxonomy to the main menu
|
-- Add the link to the taxonomy to the main menu
|
||||||
if a_response.has_permission ("admin registration") then
|
if a_response.has_permission ("admin registration") then
|
||||||
create lnk.make ("Registration", "admin/pending-registrations/")
|
create lnk.make ("Registration", "admin/pending-registrations/")
|
||||||
@@ -162,18 +170,78 @@ feature -- Handler
|
|||||||
handle_account (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
handle_account (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
local
|
local
|
||||||
r: CMS_RESPONSE
|
r: CMS_RESPONSE
|
||||||
|
l_user: detachable CMS_USER
|
||||||
|
b: STRING
|
||||||
|
lnk: CMS_LOCAL_LINK
|
||||||
do
|
do
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
|
create b.make_empty
|
||||||
|
l_user := r.user
|
||||||
if attached template_block ("account_info", r) as l_tpl_block then
|
if attached template_block ("account_info", r) as l_tpl_block then
|
||||||
if attached r.user as l_user then
|
l_tpl_block.set_weight (-10)
|
||||||
r.set_value (api.user_api.user_roles (l_user), "roles")
|
|
||||||
end
|
|
||||||
r.add_block (l_tpl_block, "content")
|
r.add_block (l_tpl_block, "content")
|
||||||
else
|
else
|
||||||
debug ("cms")
|
debug ("cms")
|
||||||
r.add_warning_message ("Error with block [resources_page]")
|
r.add_warning_message ("Error with block [resources_page]")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if r.is_authenticated then
|
||||||
|
create lnk.make ("View", "account/")
|
||||||
|
lnk.set_weight (1)
|
||||||
|
r.add_to_primary_tabs (lnk)
|
||||||
|
|
||||||
|
create lnk.make ("Edit", "account/edit")
|
||||||
|
lnk.set_weight (2)
|
||||||
|
r.add_to_primary_tabs (lnk)
|
||||||
|
end
|
||||||
|
|
||||||
|
r.set_main_content (b)
|
||||||
|
|
||||||
|
if l_user = Void then
|
||||||
|
r.set_redirection ("account/roc-login")
|
||||||
|
end
|
||||||
|
r.execute
|
||||||
|
end
|
||||||
|
|
||||||
|
handle_edit_account (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
|
local
|
||||||
|
r: CMS_RESPONSE
|
||||||
|
l_user: detachable CMS_USER
|
||||||
|
b: STRING
|
||||||
|
f: CMS_FORM
|
||||||
|
lnk: CMS_LOCAL_LINK
|
||||||
|
do
|
||||||
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
|
create b.make_empty
|
||||||
|
l_user := r.user
|
||||||
|
if attached template_block ("account_edit", r) as l_tpl_block then
|
||||||
|
l_tpl_block.set_weight (-10)
|
||||||
|
r.add_block (l_tpl_block, "content")
|
||||||
|
else
|
||||||
|
debug ("cms")
|
||||||
|
r.add_warning_message ("Error with block [resources_page]")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
create lnk.make ("View", "account/")
|
||||||
|
lnk.set_weight (1)
|
||||||
|
r.add_to_primary_tabs (lnk)
|
||||||
|
|
||||||
|
create lnk.make ("Edit", "account/edit")
|
||||||
|
lnk.set_weight (2)
|
||||||
|
r.add_to_primary_tabs (lnk)
|
||||||
|
|
||||||
|
f := new_change_password_form (r)
|
||||||
|
f.append_to_html (r.wsf_theme, b)
|
||||||
|
|
||||||
|
f := new_change_email_form (r)
|
||||||
|
f.append_to_html (r.wsf_theme, b)
|
||||||
|
|
||||||
|
r.set_main_content (b)
|
||||||
|
|
||||||
|
if l_user = Void then
|
||||||
|
r.set_redirection ("account")
|
||||||
|
end
|
||||||
r.execute
|
r.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -181,10 +249,30 @@ feature -- Handler
|
|||||||
local
|
local
|
||||||
r: CMS_RESPONSE
|
r: CMS_RESPONSE
|
||||||
do
|
do
|
||||||
if attached api.module_by_name ("basic_auth") then
|
if api.user_is_authenticated then
|
||||||
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
|
r.set_redirection ("account")
|
||||||
|
r.execute
|
||||||
|
elseif attached api.module_by_name ("session_auth") then
|
||||||
-- FIXME: find better solution to support a default login system.
|
-- FIXME: find better solution to support a default login system.
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
r.set_redirection (r.absolute_url ("/account/roc-basic-auth", Void))
|
if attached {WSF_STRING} req.query_parameter ("destination") as l_destination then
|
||||||
|
r.set_redirection ("account/auth/roc-session-login?destination=" + l_destination.url_encoded_value)
|
||||||
|
else
|
||||||
|
r.set_redirection ("account/auth/roc-session-login")
|
||||||
|
end
|
||||||
|
|
||||||
|
r.execute
|
||||||
|
|
||||||
|
elseif attached api.module_by_name ("basic_auth") then
|
||||||
|
-- FIXME: find better solution to support a default login system.
|
||||||
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
|
if attached {WSF_STRING} req.query_parameter ("destination") as l_destination then
|
||||||
|
r.set_redirection ("account/auth/roc-basic-login?destination=" + l_destination.url_encoded_value)
|
||||||
|
else
|
||||||
|
r.set_redirection ("account/auth/roc-basic-login")
|
||||||
|
end
|
||||||
|
|
||||||
r.execute
|
r.execute
|
||||||
else
|
else
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
@@ -195,9 +283,19 @@ feature -- Handler
|
|||||||
handle_logout (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
handle_logout (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
local
|
local
|
||||||
r: CMS_RESPONSE
|
r: CMS_RESPONSE
|
||||||
|
loc: STRING
|
||||||
do
|
do
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
r.set_redirection (r.absolute_url ("", Void))
|
if attached {READABLE_STRING_8} api.execution_variable ("auth_strategy") as l_auth_strategy then
|
||||||
|
loc := l_auth_strategy
|
||||||
|
else
|
||||||
|
loc := ""
|
||||||
|
end
|
||||||
|
|
||||||
|
if attached {WSF_STRING} req.query_parameter ("destination") as l_destination then
|
||||||
|
loc.append ("?destination=" + l_destination.url_encoded_value)
|
||||||
|
end
|
||||||
|
r.set_redirection (loc)
|
||||||
r.execute
|
r.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -232,7 +330,7 @@ feature -- Handler
|
|||||||
l_exist := True
|
l_exist := True
|
||||||
end
|
end
|
||||||
if attached l_user_api.user_by_email (l_email) or else attached l_user_api.temp_user_by_email (l_email) then
|
if attached l_user_api.user_by_email (l_email) or else attached l_user_api.temp_user_by_email (l_email) then
|
||||||
-- Emails already exist.
|
-- Email already exists.
|
||||||
r.set_value ("An account is already associated with that email address!", "error_email")
|
r.set_value ("An account is already associated with that email address!", "error_email")
|
||||||
l_exist := True
|
l_exist := True
|
||||||
end
|
end
|
||||||
@@ -524,45 +622,91 @@ feature -- Handler
|
|||||||
r.execute
|
r.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
handle_change_password (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
handle_change_field (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
local
|
local
|
||||||
r: CMS_RESPONSE
|
r: CMS_RESPONSE
|
||||||
l_user_api: CMS_USER_API
|
l_user_api: CMS_USER_API
|
||||||
|
f: CMS_FORM
|
||||||
|
l_fieldname: detachable READABLE_STRING_8
|
||||||
|
b: STRING
|
||||||
|
lnk: CMS_LOCAL_LINK
|
||||||
do
|
do
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
if attached {WSF_STRING} req.path_parameter ("field") as p_field then
|
||||||
l_user_api := api.user_api
|
l_fieldname := p_field.url_encoded_value
|
||||||
if req.is_post_request_method then
|
end
|
||||||
if attached r.user as l_user then
|
if l_fieldname = Void then
|
||||||
r.set_value (api.user_api.user_roles (l_user), "roles")
|
create {BAD_REQUEST_ERROR_CMS_RESPONSE} r.make (req, res, api)
|
||||||
if attached {WSF_STRING} req.form_parameter ("password") as l_password and then attached {WSF_STRING} req.form_parameter ("confirm_password") as l_confirm_password and then l_password.value.same_string (l_confirm_password.value) then
|
else
|
||||||
-- Does the passwords match?
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
l_user.set_password (l_password.value)
|
|
||||||
l_user_api.update_user (l_user)
|
if r.is_authenticated then
|
||||||
r.set_redirection (req.absolute_script_url ("/account/post-change-password"))
|
create lnk.make ("View", "account/")
|
||||||
else
|
lnk.set_weight (1)
|
||||||
if attached template_block ("account_info", r) as l_tpl_block then
|
r.add_to_primary_tabs (lnk)
|
||||||
-- r.set_value (l_user, "user")
|
|
||||||
r.set_value ("Passwords Don't Match", "error_password")
|
create lnk.make ("Edit", "account/edit")
|
||||||
r.set_status_code ({HTTP_CONSTANTS}.bad_request)
|
lnk.set_weight (2)
|
||||||
r.add_block (l_tpl_block, "content")
|
r.add_to_primary_tabs (lnk)
|
||||||
|
end
|
||||||
|
|
||||||
|
l_user_api := api.user_api
|
||||||
|
if req.is_post_request_method then
|
||||||
|
if attached r.user as l_user then
|
||||||
|
if l_fieldname.is_case_insensitive_equal ("password") then
|
||||||
|
if
|
||||||
|
attached {WSF_STRING} req.form_parameter ("password") as l_password and then
|
||||||
|
attached {WSF_STRING} req.form_parameter ("confirm_password") as l_confirm_password and then
|
||||||
|
l_password.value.same_string (l_confirm_password.value)
|
||||||
|
then
|
||||||
|
-- passwords matched?
|
||||||
|
l_user.set_password (l_password.value)
|
||||||
|
l_user_api.update_user (l_user)
|
||||||
|
r.add_success_message ("Password updated.")
|
||||||
|
r.set_redirection ("account/")
|
||||||
|
r.set_redirection_delay (3)
|
||||||
|
else
|
||||||
|
r.add_error_message ("Passwords do not match!")
|
||||||
|
f := new_change_password_form (r)
|
||||||
|
r.set_main_content (f.to_html (r.wsf_theme))
|
||||||
|
end
|
||||||
|
elseif l_fieldname.is_case_insensitive_equal ("email") then
|
||||||
|
-- FIXME: find a safer workflow .. allow multiple emails, and have a primary email?
|
||||||
|
if
|
||||||
|
attached {WSF_STRING} req.form_parameter ("email") as l_email and then
|
||||||
|
attached {WSF_STRING} req.form_parameter ("confirm_email") as l_confirm_email and then
|
||||||
|
l_email.value.same_string (l_confirm_email.value) and then
|
||||||
|
l_email.value.is_valid_as_string_8
|
||||||
|
then
|
||||||
|
-- emails matched?
|
||||||
|
l_user.set_email (l_email.value.to_string_8)
|
||||||
|
l_user_api.update_user (l_user)
|
||||||
|
r.add_success_message ("Email updated.")
|
||||||
|
r.set_redirection ("account/")
|
||||||
|
r.set_redirection_delay (3)
|
||||||
|
else
|
||||||
|
r.add_error_message ("Emails do not match!")
|
||||||
|
f := new_change_email_form (r)
|
||||||
|
r.set_main_content (f.to_html (r.wsf_theme))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
r.add_error_message ("You can not change %"" + l_fieldname + "%" information!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
create b.make_empty
|
||||||
|
if l_fieldname.is_case_insensitive_equal_general ("password") then
|
||||||
|
f := new_change_password_form (r)
|
||||||
|
f.append_to_html (r.wsf_theme, b)
|
||||||
|
elseif l_fieldname.is_case_insensitive_equal_general ("email") then
|
||||||
|
f := new_change_email_form (r)
|
||||||
|
f.append_to_html (r.wsf_theme, b)
|
||||||
|
end
|
||||||
|
r.set_main_content (b)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
r.execute
|
r.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
handle_post_change_password (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
|
||||||
local
|
|
||||||
r: CMS_RESPONSE
|
|
||||||
do
|
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
|
||||||
if attached template_block ("post_change", r) as l_tpl_block then
|
|
||||||
r.add_block (l_tpl_block, "content")
|
|
||||||
end
|
|
||||||
r.execute
|
|
||||||
end
|
|
||||||
|
|
||||||
handle_admin_pending_registrations (req: WSF_REQUEST; res: WSF_RESPONSE; api: CMS_API)
|
handle_admin_pending_registrations (req: WSF_REQUEST; res: WSF_RESPONSE; api: CMS_API)
|
||||||
local
|
local
|
||||||
l_response: CMS_RESPONSE
|
l_response: CMS_RESPONSE
|
||||||
@@ -655,20 +799,8 @@ feature -- Handler
|
|||||||
end
|
end
|
||||||
|
|
||||||
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
||||||
local
|
|
||||||
l_string: STRING
|
|
||||||
do
|
do
|
||||||
Result := <<"register", "reactivate", "new_password", "reset_password", "registration">>
|
Result := <<"register", "reactivate", "new_password", "reset_password", "registration">>
|
||||||
debug ("roc")
|
|
||||||
create l_string.make_empty
|
|
||||||
across
|
|
||||||
Result as ic
|
|
||||||
loop
|
|
||||||
l_string.append (ic.item)
|
|
||||||
l_string.append_character (' ')
|
|
||||||
end
|
|
||||||
write_debug_log (generator + ".block_list:" + l_string)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
||||||
@@ -689,6 +821,53 @@ feature -- Handler
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
new_change_password_form (a_response: CMS_RESPONSE): CMS_FORM
|
||||||
|
local
|
||||||
|
fs: WSF_FORM_FIELD_SET
|
||||||
|
pwd: WSF_FORM_PASSWORD_INPUT
|
||||||
|
do
|
||||||
|
create Result.make (a_response.url ("account/change/password", Void), "change-password-form")
|
||||||
|
create fs.make
|
||||||
|
fs.set_legend ("Change password")
|
||||||
|
Result.extend (fs)
|
||||||
|
|
||||||
|
create pwd.make ("password")
|
||||||
|
pwd.set_label ("Password")
|
||||||
|
pwd.enable_required
|
||||||
|
fs.extend (pwd)
|
||||||
|
create pwd.make ("confirm_password")
|
||||||
|
pwd.set_label ("Confirm password")
|
||||||
|
pwd.enable_required
|
||||||
|
fs.extend (pwd)
|
||||||
|
|
||||||
|
-- create but.make_with_text ("op", "Confirm")
|
||||||
|
-- fs.extend (but)
|
||||||
|
|
||||||
|
fs.extend_html_text ("<button type=%"submit%">Confirm</button>")
|
||||||
|
end
|
||||||
|
|
||||||
|
new_change_email_form (a_response: CMS_RESPONSE): CMS_FORM
|
||||||
|
local
|
||||||
|
fs: WSF_FORM_FIELD_SET
|
||||||
|
tf: WSF_FORM_EMAIL_INPUT
|
||||||
|
do
|
||||||
|
create Result.make (a_response.url ("account/change/email", Void), "change-email-form")
|
||||||
|
create fs.make
|
||||||
|
fs.set_legend ("Change email")
|
||||||
|
Result.extend (fs)
|
||||||
|
|
||||||
|
create tf.make ("email")
|
||||||
|
tf.set_label ("Email")
|
||||||
|
tf.enable_required
|
||||||
|
fs.extend (tf)
|
||||||
|
create tf.make ("confirm_email")
|
||||||
|
tf.set_label ("Confirm email")
|
||||||
|
tf.enable_required
|
||||||
|
fs.extend (tf)
|
||||||
|
|
||||||
|
fs.extend_html_text ("<button type=%"submit%">Confirm</button>")
|
||||||
|
end
|
||||||
|
|
||||||
feature {NONE} -- Token Generation
|
feature {NONE} -- Token Generation
|
||||||
|
|
||||||
new_token: STRING
|
new_token: STRING
|
||||||
|
|||||||
1
modules/auth/site/templates/block_account_edit.tpl
Normal file
1
modules/auth/site/templates/block_account_edit.tpl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{include file="block_account_info.tpl" /}
|
||||||
@@ -1,62 +1,34 @@
|
|||||||
<div class="primary-tabs">
|
<div class="primary-tabs">
|
||||||
{if isset="$user"}
|
{if isset="$user"}
|
||||||
<h3>Account Information</h3>
|
<h3>Account Information</h3>
|
||||||
<div>
|
<ul class="user-information">
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<label>Username:</label> {$user.name/}
|
||||||
<label>Username:</label> {$user.name/}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label>Email:</label> {$user.email/}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label>Creation Date:</label> {$user.creation_date/}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label>Last login:</label> {$user.last_login_date/}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<form method="get" action="{$site_url/}{$auth_login_strategy/}">
|
|
||||||
<button type="submit">Logout</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div>
|
||||||
<hr>
|
<label>Email:</label> {$user.email/}
|
||||||
{include file="block_change_password.tpl" /}
|
</div>
|
||||||
<hr>
|
<div>
|
||||||
<h4>Roles</h4>
|
<label>Creation Date:</label> {$user.creation_date/} (UTC)
|
||||||
<div>
|
</div>
|
||||||
{foreach item="ic" from="$roles"}
|
<div>
|
||||||
<div>
|
<label>Last login:</label> {$user.last_login_date/} (UTC)
|
||||||
<ul>
|
</div>
|
||||||
<li>
|
<div>
|
||||||
<strong>{$ic.name/}</strong>
|
<form method="get" action="{$site_url/}account/roc-logout">
|
||||||
<ul>
|
<button type="submit">Logout</button>
|
||||||
<li> <i>permissions</i>
|
</form>
|
||||||
<ul>
|
</div>
|
||||||
{foreach item="ip" from="$ic.permissions"}
|
</ul>
|
||||||
<li>{$ip/}</li>
|
|
||||||
{/foreach}
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
{/foreach}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<h4>Profile</h4>
|
<h4>Profile</h4>
|
||||||
<div>
|
<ul class="user-profile">
|
||||||
{foreach item="the_value" key="the_name" from="$user.profile"}
|
{foreach item="the_value" key="the_name" from="$user.profile"}
|
||||||
<div>
|
<li>
|
||||||
<label>{$the_name/}:</label> {$the_value/}
|
<label>{$the_name/}:</label><div>{$the_value/}</div>
|
||||||
</div>
|
</li>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</div>
|
</ul>
|
||||||
{/if}
|
{/if}
|
||||||
{unless isset="$user"}
|
{unless isset="$user"}
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<form action="{$site_url/}account/change-password" method="post">
|
<form action="{$site_url/}account/change-password" method="post">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Change Password Form</legend>
|
<legend>Change Password</legend>
|
||||||
<div>
|
<div>
|
||||||
<input type="password" id="password" name="password" value="" required/>
|
<input type="password" id="password" name="password" value="" required/>
|
||||||
<label for="password">Password</label>
|
<label for="password">Password</label>
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
<div class="primary-tabs">
|
|
||||||
{unless isset="$user"}
|
|
||||||
<h3>Login or <a href="{$site_url/}account/roc-register">Register</a></h3>
|
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
<form action method="POST">
|
|
||||||
<div>
|
|
||||||
<input type="text" name="username" required>
|
|
||||||
<label>Username</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<input type="password" name="password" required>
|
|
||||||
<label>Password</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="button" onclick="ROC_AUTH.login();">Login</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
<p>
|
|
||||||
<a href="{$site_url/}account/new-password">Forgot password?</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{/unless}
|
|
||||||
</div>
|
|
||||||
@@ -10,24 +10,17 @@ class
|
|||||||
CMS_BASIC_AUTH_MODULE
|
CMS_BASIC_AUTH_MODULE
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
CMS_MODULE
|
CMS_AUTH_MODULE_I
|
||||||
|
rename
|
||||||
|
module_api as basic_auth_api
|
||||||
redefine
|
redefine
|
||||||
|
make,
|
||||||
filters,
|
filters,
|
||||||
setup_hooks
|
setup_hooks
|
||||||
end
|
end
|
||||||
|
|
||||||
CMS_HOOK_AUTO_REGISTER
|
|
||||||
|
|
||||||
CMS_HOOK_BLOCK
|
CMS_HOOK_BLOCK
|
||||||
|
|
||||||
CMS_HOOK_MENU_SYSTEM_ALTER
|
|
||||||
|
|
||||||
CMS_HOOK_VALUE_TABLE_ALTER
|
|
||||||
|
|
||||||
SHARED_LOGGER
|
|
||||||
|
|
||||||
CMS_REQUEST_UTIL
|
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
@@ -35,26 +28,42 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
make
|
make
|
||||||
do
|
do
|
||||||
|
Precursor
|
||||||
version := "1.0"
|
version := "1.0"
|
||||||
description := "Service to manage basic authentication"
|
description := "Service to manage basic authentication"
|
||||||
package := "authentication"
|
|
||||||
add_dependency ({CMS_AUTHENTICATION_MODULE})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
name: STRING = "basic_auth"
|
name: STRING = "basic_auth"
|
||||||
|
|
||||||
feature -- Access: router
|
feature -- Access: auth strategy
|
||||||
|
|
||||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
login_title: STRING = "Basic Auth"
|
||||||
|
-- Module specific login title.
|
||||||
|
|
||||||
|
login_location: STRING = "account/auth/roc-basic-login"
|
||||||
|
|
||||||
|
do_login_location: STRING = "roc-basic-login" -- IMPORTANT: it has to be at the root !
|
||||||
|
|
||||||
|
logout_location: STRING = "roc-basic-logoff" -- IMPORTANT: it has to be at the root !
|
||||||
|
|
||||||
|
is_authenticating (a_response: CMS_RESPONSE): BOOLEAN
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
configure_api_login (a_api, a_router)
|
if
|
||||||
configure_api_logoff (a_api, a_router)
|
a_response.is_authenticated and then
|
||||||
a_router.handle ("/account/roc-basic-auth", create {WSF_URI_AGENT_HANDLER}.make (agent handle_login_basic_auth (a_api, ?, ?)), a_router.methods_head_get)
|
a_response.request.http_authorization /= Void
|
||||||
|
then
|
||||||
|
Result := True
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature {CMS_API} -- Access: API
|
||||||
|
|
||||||
|
oauth20_api: detachable CMS_AUTH_API_I
|
||||||
|
-- <Precursor>
|
||||||
|
|
||||||
feature -- Access: filter
|
feature -- Access: filter
|
||||||
|
|
||||||
filters (a_api: CMS_API): detachable LIST [WSF_FILTER]
|
filters (a_api: CMS_API): detachable LIST [WSF_FILTER]
|
||||||
@@ -65,6 +74,16 @@ feature -- Access: filter
|
|||||||
Result.extend (create {CMS_BASIC_AUTH_FILTER}.make (a_api))
|
Result.extend (create {CMS_BASIC_AUTH_FILTER}.make (a_api))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Access: router
|
||||||
|
|
||||||
|
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||||
|
-- <Precursor>
|
||||||
|
do
|
||||||
|
configure_api_login (a_api, a_router)
|
||||||
|
configure_api_logoff (a_api, a_router)
|
||||||
|
a_router.handle ("/" + login_location, create {WSF_URI_AGENT_HANDLER}.make (agent handle_login_basic_auth (a_api, ?, ?)), a_router.methods_head_get)
|
||||||
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation: routes
|
feature {NONE} -- Implementation: routes
|
||||||
|
|
||||||
configure_api_login (api: CMS_API; a_router: WSF_ROUTER)
|
configure_api_login (api: CMS_API; a_router: WSF_ROUTER)
|
||||||
@@ -75,7 +94,7 @@ feature {NONE} -- Implementation: routes
|
|||||||
create l_bal_handler.make (api)
|
create l_bal_handler.make (api)
|
||||||
create l_methods
|
create l_methods
|
||||||
l_methods.enable_get
|
l_methods.enable_get
|
||||||
a_router.handle ("/basic_auth_login", l_bal_handler, l_methods)
|
a_router.handle ("/" + do_login_location, l_bal_handler, l_methods)
|
||||||
end
|
end
|
||||||
|
|
||||||
configure_api_logoff (api: CMS_API; a_router: WSF_ROUTER)
|
configure_api_logoff (api: CMS_API; a_router: WSF_ROUTER)
|
||||||
@@ -86,16 +105,38 @@ feature {NONE} -- Implementation: routes
|
|||||||
create l_bal_handler.make (api)
|
create l_bal_handler.make (api)
|
||||||
create l_methods
|
create l_methods
|
||||||
l_methods.enable_get
|
l_methods.enable_get
|
||||||
a_router.handle ("/basic_auth_logoff", l_bal_handler, l_methods)
|
a_router.handle ("/" + logout_location, l_bal_handler, l_methods)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
handle_login_basic_auth (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
handle_login_basic_auth (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
local
|
local
|
||||||
r: CMS_RESPONSE
|
r: CMS_RESPONSE
|
||||||
|
vals: CMS_VALUE_TABLE
|
||||||
do
|
do
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
r.set_value ("Basic Auth", "optional_content_type")
|
if api.user_is_authenticated then
|
||||||
|
r.add_error_message ("You are already signed in!")
|
||||||
|
r.set_main_content (r.link ("Logout", "account/roc-logout", Void))
|
||||||
|
else
|
||||||
|
if attached template_block ("login", r) as l_tpl_block then
|
||||||
|
r.add_javascript_url (r.url ("module/" + name + "/files/js/roc_basic_auth.js", Void))
|
||||||
|
|
||||||
|
create vals.make (1)
|
||||||
|
-- add the variable to the block
|
||||||
|
api.hooks.invoke_value_table_alter (vals, r)
|
||||||
|
across
|
||||||
|
vals as ic
|
||||||
|
loop
|
||||||
|
l_tpl_block.set_value (ic.item, ic.key)
|
||||||
|
end
|
||||||
|
r.add_block (l_tpl_block, "content")
|
||||||
|
else
|
||||||
|
debug ("cms")
|
||||||
|
r.add_warning_message ("Error with block [login]")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
r.set_value ("Basic Auth", "optional_content_type")
|
||||||
|
end
|
||||||
r.execute
|
r.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -104,103 +145,25 @@ feature -- Hooks configuration
|
|||||||
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
|
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
|
||||||
-- Module hooks configuration.
|
-- Module hooks configuration.
|
||||||
do
|
do
|
||||||
auto_subscribe_to_hooks (a_hooks)
|
Precursor (a_hooks)
|
||||||
a_hooks.subscribe_to_block_hook (Current)
|
a_hooks.subscribe_to_block_hook (Current)
|
||||||
a_hooks.subscribe_to_value_table_alter_hook (Current)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Hooks
|
feature -- Hooks
|
||||||
|
|
||||||
value_table_alter (a_value: CMS_VALUE_TABLE; a_response: CMS_RESPONSE)
|
|
||||||
-- <Precursor>
|
|
||||||
do
|
|
||||||
if a_response.is_authenticated then
|
|
||||||
a_value.force ("basic_auth_logoff", "auth_login_strategy")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)
|
|
||||||
-- Hook execution on collection of menu contained by `a_menu_system'
|
|
||||||
-- for related response `a_response'.
|
|
||||||
local
|
|
||||||
lnk: CMS_LOCAL_LINK
|
|
||||||
lnk2: detachable CMS_LINK
|
|
||||||
do
|
|
||||||
if attached a_response.user as u then
|
|
||||||
across
|
|
||||||
a_menu_system.primary_menu.items as ic
|
|
||||||
until
|
|
||||||
lnk2 /= Void
|
|
||||||
loop
|
|
||||||
if ic.item.location.same_string ("account/roc-logout") then
|
|
||||||
lnk2 := ic.item
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if lnk2 /= Void then
|
|
||||||
a_menu_system.primary_menu.remove (lnk2)
|
|
||||||
end
|
|
||||||
|
|
||||||
create lnk.make ("Logout", "basic_auth_logoff")
|
|
||||||
lnk.set_weight (98)
|
|
||||||
a_menu_system.primary_menu.extend (lnk)
|
|
||||||
else
|
|
||||||
if a_response.location.starts_with ("account/") then
|
|
||||||
create lnk.make ("Basic Auth", "account/roc-basic-auth")
|
|
||||||
lnk.set_expandable (True)
|
|
||||||
a_response.add_to_primary_tabs (lnk)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
||||||
local
|
|
||||||
l_string: STRING
|
|
||||||
do
|
do
|
||||||
Result := <<"login">>
|
Result := <<"?login">>
|
||||||
debug ("roc")
|
|
||||||
create l_string.make_empty
|
|
||||||
across
|
|
||||||
Result as ic
|
|
||||||
loop
|
|
||||||
l_string.append (ic.item)
|
|
||||||
l_string.append_character (' ')
|
|
||||||
end
|
|
||||||
write_debug_log (generator + ".block_list:" + l_string )
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
||||||
do
|
do
|
||||||
if
|
if a_block_id.is_case_insensitive_equal_general ("login") then
|
||||||
a_block_id.is_case_insensitive_equal_general ("login") and then
|
|
||||||
a_response.location.starts_with ("account/roc-basic-auth")
|
|
||||||
then
|
|
||||||
a_response.add_javascript_url (a_response.url ("module/" + name + "/files/js/roc_basic_auth.js", Void))
|
a_response.add_javascript_url (a_response.url ("module/" + name + "/files/js/roc_basic_auth.js", Void))
|
||||||
get_block_view_login (a_block_id, a_response)
|
get_block_view_login (a_block_id, a_response)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Helpers
|
|
||||||
|
|
||||||
template_block (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE): detachable CMS_SMARTY_TEMPLATE_BLOCK
|
|
||||||
-- Smarty content block for `a_block_id'
|
|
||||||
local
|
|
||||||
p: detachable PATH
|
|
||||||
do
|
|
||||||
create p.make_from_string ("templates")
|
|
||||||
p := p.extended ("block_").appended (a_block_id).appended_with_extension ("tpl")
|
|
||||||
|
|
||||||
p := a_response.api.module_theme_resource_location (Current, p)
|
|
||||||
if p /= Void then
|
|
||||||
if attached p.entry as e then
|
|
||||||
create Result.make (a_block_id, Void, p.parent, e)
|
|
||||||
else
|
|
||||||
create Result.make (a_block_id, Void, p.parent, p)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
feature {NONE} -- Block views
|
feature {NONE} -- Block views
|
||||||
|
|
||||||
get_block_view_login (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
get_block_view_login (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
||||||
@@ -210,7 +173,7 @@ feature {NONE} -- Block views
|
|||||||
if attached template_block (a_block_id, a_response) as l_tpl_block then
|
if attached template_block (a_block_id, a_response) as l_tpl_block then
|
||||||
create vals.make (1)
|
create vals.make (1)
|
||||||
-- add the variable to the block
|
-- add the variable to the block
|
||||||
value_table_alter (vals, a_response)
|
a_response.api.hooks.invoke_value_table_alter (vals, a_response)
|
||||||
across
|
across
|
||||||
vals as ic
|
vals as ic
|
||||||
loop
|
loop
|
||||||
|
|||||||
@@ -9,54 +9,46 @@ class
|
|||||||
CMS_BASIC_AUTH_FILTER
|
CMS_BASIC_AUTH_FILTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
WSF_URI_TEMPLATE_HANDLER
|
CMS_AUTH_FILTER_I
|
||||||
CMS_HANDLER
|
|
||||||
WSF_FILTER
|
REFACTORING_HELPER
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature -- Basic operations
|
feature -- Basic operations
|
||||||
|
|
||||||
|
auth_strategy: STRING
|
||||||
|
do
|
||||||
|
Result := {CMS_BASIC_AUTH_MODULE}.logout_location
|
||||||
|
end
|
||||||
|
|
||||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- Execute the filter.
|
-- Execute the filter.
|
||||||
local
|
local
|
||||||
l_auth: HTTP_AUTHORIZATION
|
l_auth: HTTP_AUTHORIZATION
|
||||||
do
|
do
|
||||||
api.logger.put_debug (generator + ".execute ", Void)
|
|
||||||
create l_auth.make (req.http_authorization)
|
create l_auth.make (req.http_authorization)
|
||||||
debug
|
|
||||||
if attached req.raw_header_data as l_raw_data then
|
|
||||||
api.logger.put_debug (generator + ".execute " + (create {UTF_CONVERTER}).escaped_utf_32_string_to_utf_8_string_8 (l_raw_data), Void)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- A valid user
|
|
||||||
if
|
if
|
||||||
(attached l_auth.type as l_auth_type and then l_auth_type.is_case_insensitive_equal_general ("basic")) and then
|
l_auth.is_basic and then
|
||||||
attached l_auth.login as l_auth_login and then attached l_auth.password as l_auth_password
|
attached l_auth.login as l_auth_login and then
|
||||||
|
attached l_auth.password as l_auth_password
|
||||||
then
|
then
|
||||||
if api.user_api.is_valid_credential (l_auth_login, l_auth_password) then
|
if
|
||||||
if attached api.user_api.user_by_name (l_auth_login) as l_user then
|
api.user_api.is_valid_credential (l_auth_login, l_auth_password) and then
|
||||||
debug ("refactor_fixme")
|
attached api.user_api.user_by_name (l_auth_login) as l_user
|
||||||
fixme ("Maybe we need to store in the credentials in a shared context SECURITY_CONTEXT")
|
then
|
||||||
-- req.set_execution_variable ("security_content", create SECURITY_CONTEXT.make (l_user))
|
debug ("refactor_fixme")
|
||||||
-- other authentication filters (OpenID, etc) should implement the same approach.
|
fixme ("Maybe we need to store in the credentials in a shared context SECURITY_CONTEXT")
|
||||||
end
|
-- req.set_execution_variable ("security_content", create SECURITY_CONTEXT.make (l_user))
|
||||||
set_current_user (req, l_user)
|
-- other authentication filters (OpenID, etc) should implement the same approach.
|
||||||
execute_next (req, res)
|
|
||||||
else
|
|
||||||
debug ("refactor_fixme")
|
|
||||||
to_implement ("Internal server error")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
set_current_user (l_user)
|
||||||
else
|
else
|
||||||
api.logger.put_error (generator + ".execute login_valid failed for: " + l_auth_login, Void)
|
api.logger.put_error (generator + ".execute login_valid failed for: " + l_auth_login, Void)
|
||||||
execute_next (req, res)
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
api.logger.put_debug (generator + ".execute without authentication", Void)
|
|
||||||
execute_next (req, res)
|
|
||||||
end
|
end
|
||||||
|
execute_next (req, res)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,9 +49,9 @@ feature -- HTTP Methods
|
|||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
api.logger.put_information (generator + ".do_get Processing basic auth login", Void)
|
api.logger.put_information (generator + ".do_get Processing basic auth login", Void)
|
||||||
if attached {STRING_32} current_user_name (req) as l_user then
|
if api.user_is_authenticated then
|
||||||
if attached {WSF_STRING} req.query_parameter ("destination") as l_uri then
|
if attached {WSF_STRING} req.query_parameter ("destination") as l_uri then
|
||||||
redirect_to (req.absolute_script_url (l_uri.url_encoded_value), res)
|
redirect_to (req.absolute_script_url (l_uri.url_encoded_value), res)
|
||||||
else
|
else
|
||||||
redirect_to (req.absolute_script_url ("/"), res)
|
redirect_to (req.absolute_script_url ("/"), res)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -51,11 +51,11 @@ feature -- HTTP Methods
|
|||||||
do
|
do
|
||||||
api.logger.put_information (generator + ".do_get Processing basic auth logoff", Void)
|
api.logger.put_information (generator + ".do_get Processing basic auth logoff", Void)
|
||||||
if attached req.query_parameter ("prompt") as l_prompt then
|
if attached req.query_parameter ("prompt") as l_prompt then
|
||||||
unset_current_user (req)
|
api.unset_current_user (req)
|
||||||
send_access_denied_message (res)
|
send_access_denied_message (res)
|
||||||
else
|
else
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||||
unset_current_user (req)
|
api.unset_current_user (req)
|
||||||
l_page.set_status_code ({HTTP_STATUS_CODE}.unauthorized) -- Note: can not use {HTTP_STATUS_CODE}.unauthorized for redirection
|
l_page.set_status_code ({HTTP_STATUS_CODE}.unauthorized) -- Note: can not use {HTTP_STATUS_CODE}.unauthorized for redirection
|
||||||
l_url := req.absolute_script_url ("")
|
l_url := req.absolute_script_url ("")
|
||||||
i := l_url.substring_index ("://", 1)
|
i := l_url.substring_index ("://", 1)
|
||||||
|
|||||||
@@ -1,307 +1,291 @@
|
|||||||
var ROC_AUTH = ROC_AUTH || { };
|
var ROC_AUTH = ROC_AUTH || { };
|
||||||
|
|
||||||
var loginURL = "/basic_auth_login";
|
var loginURL = "/roc-basic-login";
|
||||||
var logoutURL = "/basic_auth_logoff";
|
var logoutURL = "/roc-basic-logoff";
|
||||||
|
|
||||||
var userAgent = navigator.userAgent.toLowerCase();
|
var userAgent = navigator.userAgent.toLowerCase();
|
||||||
var firstLogIn = true;
|
var firstLogIn = true;
|
||||||
|
|
||||||
ROC_AUTH.login = function() {
|
ROC_AUTH.login = function() {
|
||||||
var form = document.forms['cms_basic_auth'];
|
var form = document.forms['cms_basic_auth'];
|
||||||
var username = form.username.value;
|
var username = form.username.value;
|
||||||
var password = form.password.value;
|
var password = form.password.value;
|
||||||
//var host = form.host.value;
|
//var host = form.host.value;
|
||||||
var origin = window.location.origin + window.location.pathname;
|
var origin = window.location.origin + window.location.pathname;
|
||||||
var _login = function(){
|
var _login = function(){
|
||||||
|
if (document.getElementById('myModalFormId') !== null ) {
|
||||||
|
ROC_AUTH.remove ('myModalFormId');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (username === "" || password === "") {
|
||||||
if (document.getElementById('myModalFormId') !== null ) {
|
if (document.getElementById('myModalFormId') === null ) {
|
||||||
ROC_AUTH.remove ('myModalFormId');
|
var newdiv = document.createElement('div');
|
||||||
}
|
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
||||||
|
newdiv.id = 'myModalFormId';
|
||||||
|
$(".login-box").append(newdiv);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//Instantiate HTTP Request
|
||||||
|
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
||||||
|
request.open("GET", loginURL, true, username, password);
|
||||||
|
request.send(null);
|
||||||
|
|
||||||
|
//Process Response
|
||||||
|
request.onreadystatechange = function(){
|
||||||
|
if (request.readyState == 4) {
|
||||||
|
if (request.status==200) {
|
||||||
|
delete form;
|
||||||
|
window.location=window.location.origin;
|
||||||
|
} else {
|
||||||
|
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
|
||||||
|
// .. ?
|
||||||
|
}
|
||||||
|
if (document.getElementById('myModalFormId') === null ) {
|
||||||
|
var newdiv = document.createElement('div');
|
||||||
|
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
||||||
|
newdiv.id = 'myModalFormId';
|
||||||
|
$(".login-box").append(newdiv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (username === "" || password === "") {
|
var userAgent = navigator.userAgent.toLowerCase();
|
||||||
if (document.getElementById('myModalFormId') === null ) {
|
if (userAgent.indexOf("firefox") != -1) { //TODO: check version number
|
||||||
var newdiv = document.createElement('div');
|
if (firstLogIn) {
|
||||||
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
_login();
|
||||||
newdiv.id = 'myModalFormId';
|
} else {
|
||||||
$(".primary-tabs").append(newdiv);
|
ROC_AUTH.logoff(_login);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
|
_login();
|
||||||
//Instantiate HTTP Request
|
}
|
||||||
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
|
||||||
request.open("GET", loginURL, true, username, password);
|
|
||||||
request.send(null);
|
|
||||||
|
|
||||||
//Process Response
|
|
||||||
request.onreadystatechange = function(){
|
|
||||||
if (request.readyState == 4) {
|
|
||||||
if (request.status==200) {
|
|
||||||
delete form;
|
|
||||||
window.location=window.location.origin;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.getElementById('myModalFormId') === null ) {
|
|
||||||
var newdiv = document.createElement('div');
|
|
||||||
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
|
||||||
newdiv.id = 'myModalFormId';
|
|
||||||
$(".primary-tabs").append(newdiv);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
if (firstLogIn) {
|
||||||
}
|
firstLogIn = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var userAgent = navigator.userAgent.toLowerCase();
|
|
||||||
if (userAgent.indexOf("firefox") != -1){ //TODO: check version number
|
|
||||||
if (firstLogIn) _login();
|
|
||||||
else logoff(_login);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
_login();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstLogIn) firstLogIn = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ROC_AUTH.login_with_redirect = function() {
|
ROC_AUTH.login_with_redirect = function() {
|
||||||
var form = document.forms[2];
|
var form = document.forms[2];
|
||||||
var username = form.username.value;
|
var username = form.username.value;
|
||||||
var password = form.password.value;
|
var password = form.password.value;
|
||||||
var host = form.host.value;
|
var host = form.host.value;
|
||||||
var _login = function(){
|
var _login = function(){
|
||||||
|
var redirectURL = form.redirect && form.redirect.value || "";
|
||||||
|
$("#imgProgressRedirect").show();
|
||||||
|
|
||||||
var redirectURL = form.redirect && form.redirect.value || "";
|
if (document.getElementById('myModalFormId') !== null ) {
|
||||||
|
ROC_AUTH.remove ('myModalFormId');
|
||||||
|
}
|
||||||
|
if (username === "" || password === "") {
|
||||||
|
if (document.getElementById('myModalFormId') === null ) {
|
||||||
|
var newdiv = document.createElement('div');
|
||||||
|
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
||||||
|
newdiv.id = 'myModalFormId';
|
||||||
|
$(".login-box").append(newdiv);
|
||||||
|
$("#imgProgressRedirect").hide();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//Instantiate HTTP Request
|
||||||
|
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
||||||
|
request.open("GET", host + loginURL, true, username, password);
|
||||||
|
request.send(null);
|
||||||
|
|
||||||
|
//Process Response
|
||||||
|
request.onreadystatechange = function() {
|
||||||
|
if (request.readyState == 4) {
|
||||||
|
if (request.status==200) {
|
||||||
|
if (redirectURL === "") {
|
||||||
|
window.location=host + "/";
|
||||||
|
} else {
|
||||||
|
window.location=host + redirectURL;
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
|
||||||
|
}
|
||||||
|
if (document.getElementById('myModalFormId') === null ) {
|
||||||
|
var newdiv = document.createElement('div');
|
||||||
|
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
||||||
|
newdiv.id = 'myModalFormId';
|
||||||
|
$(".login-box").append(newdiv);
|
||||||
|
$("#imgProgressRedirect").hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$("#imgProgressRedirect").show();
|
var userAgent = navigator.userAgent.toLowerCase();
|
||||||
|
if (userAgent.indexOf("firefox") != -1){ //TODO: check version number
|
||||||
if (document.getElementById('myModalFormId') !== null ) {
|
if (firstLogIn) {
|
||||||
ROC_AUTH.remove ('myModalFormId');
|
_login();
|
||||||
}
|
} else {
|
||||||
|
ROC_AUTH.logoff(_login);
|
||||||
|
}
|
||||||
if (username === "" || password === "") {
|
} else{
|
||||||
if (document.getElementById('myModalFormId') === null ) {
|
_login();
|
||||||
var newdiv = document.createElement('div');
|
}
|
||||||
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
if (firstLogIn) {
|
||||||
newdiv.id = 'myModalFormId';
|
firstLogIn = false;
|
||||||
$(".primary-tabs").append(newdiv);
|
}
|
||||||
$("#imgProgressRedirect").hide();
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
|
|
||||||
//Instantiate HTTP Request
|
|
||||||
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
|
||||||
request.open("GET", host.concat(loginURL), true, username, password);
|
|
||||||
request.send(null);
|
|
||||||
|
|
||||||
//Process Response
|
|
||||||
request.onreadystatechange = function(){
|
|
||||||
if (request.readyState == 4) {
|
|
||||||
if (request.status==200) {
|
|
||||||
if (redirectURL === "") {
|
|
||||||
window.location=host.concat("/");
|
|
||||||
} else {
|
|
||||||
window.location=host.concat(redirectURL);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.getElementById('myModalFormId') === null ) {
|
|
||||||
var newdiv = document.createElement('div');
|
|
||||||
newdiv.innerHTML = "<br>Invalid Credentials</br>";
|
|
||||||
newdiv.id = 'myModalFormId';
|
|
||||||
$(".primary-tabs").append(newdiv);
|
|
||||||
$("#imgProgressRedirect").hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var userAgent = navigator.userAgent.toLowerCase();
|
|
||||||
if (userAgent.indexOf("firefox") != -1){ //TODO: check version number
|
|
||||||
if (firstLogIn) _login();
|
|
||||||
else logoff(_login);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
_login();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstLogIn) firstLogIn = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ROC_AUTH.getQueryParameterByName = function (name) {
|
ROC_AUTH.getQueryParameterByName = function (name) {
|
||||||
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
||||||
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
|
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search);
|
||||||
results = regex.exec(location.search);
|
return results === null ? " " : decodeURIComponent(results[1].replace(/\+/g, " "));
|
||||||
return results === null ? " " : decodeURIComponent(results[1].replace(/\+/g, " "));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ROC_AUTH.logoff = function(callback){
|
ROC_AUTH.logoff = function(callback){
|
||||||
var form = document.forms[0];
|
var form = document.forms[0];
|
||||||
var host = form.host.value;
|
var host = form.host.value;
|
||||||
|
|
||||||
if (userAgent.indexOf("msie") != -1) {
|
if (userAgent.indexOf("msie") != -1) {
|
||||||
document.execCommand("ClearAuthenticationCache");
|
document.execCommand("ClearAuthenticationCache");
|
||||||
}
|
} else if (userAgent.indexOf("firefox") != -1){ //TODO: check version number
|
||||||
else if (userAgent.indexOf("firefox") != -1){ //TODO: check version number
|
var request1 = new XMLHttpRequest();
|
||||||
|
var request2 = new XMLHttpRequest();
|
||||||
var request1 = new XMLHttpRequest();
|
|
||||||
var request2 = new XMLHttpRequest();
|
//Logout. Tell the server not to return the "WWW-Authenticate" header
|
||||||
|
request1.open("GET", host + logoutURL + "?prompt=false", true);
|
||||||
//Logout. Tell the server not to return the "WWW-Authenticate" header
|
request1.send("");
|
||||||
request1.open("GET", host.concat(logoutURL) + "?prompt=false", true);
|
request1.onreadystatechange = function(){
|
||||||
request1.send("");
|
if (request1.readyState == 4) {
|
||||||
request1.onreadystatechange = function(){
|
//Sign in with dummy credentials to clear the auth cache
|
||||||
if (request1.readyState == 4) {
|
request2.open("GET", host + logoutURL, true, "logout", "logout");
|
||||||
|
request2.send("");
|
||||||
//Sign in with dummy credentials to clear the auth cache
|
request2.onreadystatechange = function(){
|
||||||
request2.open("GET", host.concat(logoutURL), true, "logout", "logout");
|
if (request2.readyState == 4) {
|
||||||
request2.send("");
|
if (callback!=null) {
|
||||||
|
callback.call();
|
||||||
request2.onreadystatechange = function(){
|
} else {
|
||||||
if (request2.readyState == 4) {
|
window.location=host + logoutURL;
|
||||||
if (callback!=null) { callback.call(); } else { window.location=host.concat(logoutURL);}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
}
|
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
||||||
else {
|
request.open("GET", host + logoutURL, true, "logout", "logout");
|
||||||
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
|
request.send("");
|
||||||
request.open("GET", host.concat(logoutURL), true, "logout", "logout");
|
request.onreadystatechange = function(){
|
||||||
request.send("");
|
if (request.status==401 || request.status==403 ) {
|
||||||
request.onreadystatechange = function(){
|
window.location=host + logoutURL;
|
||||||
if (request.status==401 || request.status==403 ) { window.location=host.concat(logoutURL);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ROC_AUTH.remove = function (id)
|
ROC_AUTH.remove = function (id) {
|
||||||
{
|
var element = document.getElementById(id);
|
||||||
var element = document.getElementById(id);
|
element.outerHTML = "";
|
||||||
element.outerHTML = "";
|
delete element;
|
||||||
delete element;
|
return;
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
if (typeof String.prototype.contains != 'function') {
|
||||||
if (typeof String.prototype.contains != 'function') {
|
String.prototype.contains = function (str){
|
||||||
String.prototype.contains = function (str){
|
return this.indexOf(str) != -1;
|
||||||
return this.indexOf(str) != -1;
|
};
|
||||||
};
|
}
|
||||||
}
|
ROC_AUTH.progressive_loging();
|
||||||
ROC_AUTH.progressive_loging();
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
ROC_AUTH.progressive_loging = function () {
|
ROC_AUTH.progressive_loging = function () {
|
||||||
|
ROC_AUTH.login_href();
|
||||||
ROC_AUTH.login_href();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
$(document).keypress(function(e) {
|
$(document).keypress(function(e) {
|
||||||
if ((e.which === 13) && (e.target.localName === 'input' && e.target.id === 'password')) {
|
if ((e.which === 13) && (e.target.localName === 'input' && e.target.id === 'password')) {
|
||||||
ROC_AUTH.login();
|
ROC_AUTH.login();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ROC_AUTH.OnOneClick = function(event) {
|
ROC_AUTH.OnOneClick = function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if ( document.forms[0] === undefined ) {
|
if ( document.forms[0] === undefined ) {
|
||||||
ROC_AUTH.create_form();
|
ROC_AUTH.create_form();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
ROC_AUTH.login_href = function() {
|
ROC_AUTH.login_href = function() {
|
||||||
var els = document.getElementsByTagName("a");
|
var els = document.getElementsByTagName("a");
|
||||||
for (var i = 0, l = els.length; i < l; i++) {
|
for (var i = 0, l = els.length; i < l; i++) {
|
||||||
var el = els[i];
|
var el = els[i];
|
||||||
if (el.href.contains("/basic_auth_login?destination")) {
|
if (el.href.contains(loginURL + "?destination")) {
|
||||||
loginURL = el.href;
|
// loginURL = el.href;
|
||||||
var OneClick = el;
|
var OneClick = el;
|
||||||
OneClick.addEventListener('click', ROC_AUTH.OnOneClick, false);
|
OneClick.addEventListener('click', ROC_AUTH.OnOneClick, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ROC_AUTH.create_form = function() {
|
ROC_AUTH.create_form = function() {
|
||||||
|
|
||||||
// Fetching HTML Elements in Variables by ID.
|
// Fetching HTML Elements in Variables by ID.
|
||||||
var createform = document.createElement('form'); // Create New Element Form
|
var createform = document.createElement('form'); // Create New Element Form
|
||||||
createform.setAttribute("action", ""); // Setting Action Attribute on Form
|
createform.setAttribute("action", ""); // Setting Action Attribute on Form
|
||||||
createform.setAttribute("method", "post"); // Setting Method Attribute on Form
|
createform.setAttribute("method", "post"); // Setting Method Attribute on Form
|
||||||
$("body").append(createform);
|
$("body").append(createform);
|
||||||
|
|
||||||
var heading = document.createElement('h2'); // Heading of Form
|
var heading = document.createElement('h2'); // Heading of Form
|
||||||
heading.innerHTML = "Login Form ";
|
heading.innerHTML = "Login Form ";
|
||||||
createform.appendChild(heading);
|
createform.appendChild(heading);
|
||||||
|
|
||||||
var line = document.createElement('hr'); // Giving Horizontal Row After Heading
|
var line = document.createElement('hr'); // Giving Horizontal Row After Heading
|
||||||
createform.appendChild(line);
|
createform.appendChild(line);
|
||||||
|
|
||||||
var linebreak = document.createElement('br');
|
var linebreak = document.createElement('br');
|
||||||
createform.appendChild(linebreak);
|
createform.appendChild(linebreak);
|
||||||
|
|
||||||
var namelabel = document.createElement('label'); // Create Label for Name Field
|
var namelabel = document.createElement('label'); // Create Label for Name Field
|
||||||
namelabel.innerHTML = "Username : "; // Set Field Labels
|
namelabel.innerHTML = "Username : "; // Set Field Labels
|
||||||
createform.appendChild(namelabel);
|
createform.appendChild(namelabel);
|
||||||
|
|
||||||
var inputelement = document.createElement('input'); // Create Input Field for UserName
|
var inputelement = document.createElement('input'); // Create Input Field for UserName
|
||||||
inputelement.setAttribute("type", "text");
|
inputelement.setAttribute("type", "text");
|
||||||
inputelement.setAttribute("name", "username");
|
inputelement.setAttribute("name", "username");
|
||||||
inputelement.setAttribute("required","required");
|
inputelement.setAttribute("required","required");
|
||||||
createform.appendChild(inputelement);
|
createform.appendChild(inputelement);
|
||||||
|
|
||||||
var linebreak = document.createElement('br');
|
var linebreak = document.createElement('br');
|
||||||
createform.appendChild(linebreak);
|
createform.appendChild(linebreak);
|
||||||
|
|
||||||
var passwordlabel = document.createElement('label'); // Create Label for Password Field
|
var passwordlabel = document.createElement('label'); // Create Label for Password Field
|
||||||
passwordlabel.innerHTML = "Password : ";
|
passwordlabel.innerHTML = "Password : ";
|
||||||
createform.appendChild(passwordlabel);
|
createform.appendChild(passwordlabel);
|
||||||
|
|
||||||
var passwordelement = document.createElement('input'); // Create Input Field for Password.
|
var passwordelement = document.createElement('input'); // Create Input Field for Password.
|
||||||
passwordelement.setAttribute("type", "password");
|
passwordelement.setAttribute("type", "password");
|
||||||
passwordelement.setAttribute("name", "password");
|
passwordelement.setAttribute("name", "password");
|
||||||
passwordelement.setAttribute("id", "password");
|
passwordelement.setAttribute("id", "password");
|
||||||
passwordelement.setAttribute("required","required");
|
passwordelement.setAttribute("required","required");
|
||||||
createform.appendChild(passwordelement);
|
createform.appendChild(passwordelement);
|
||||||
|
|
||||||
|
|
||||||
var passwordbreak = document.createElement('br');
|
var passwordbreak = document.createElement('br');
|
||||||
createform.appendChild(passwordbreak);
|
createform.appendChild(passwordbreak);
|
||||||
|
|
||||||
|
|
||||||
var submitelement = document.createElement('button'); // Append Submit Button
|
var submitelement = document.createElement('button'); // Append Submit Button
|
||||||
submitelement.setAttribute("type", "button");
|
submitelement.setAttribute("type", "button");
|
||||||
submitelement.setAttribute("onclick", "ROC_AUTH.login();");
|
submitelement.setAttribute("onclick", "ROC_AUTH.login();");
|
||||||
submitelement.innerHTML = "Sign In ";
|
submitelement.innerHTML = "Sign In ";
|
||||||
createform.appendChild(submitelement);
|
createform.appendChild(submitelement);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -310,16 +294,16 @@ var password = document.getElementById("password");
|
|||||||
var confirm_password = document.getElementById("confirm_password");
|
var confirm_password = document.getElementById("confirm_password");
|
||||||
|
|
||||||
ROC_AUTH.validatePassword =function(){
|
ROC_AUTH.validatePassword =function(){
|
||||||
if ((password != null) && (confirm_password != null)) {
|
if ((password != null) && (confirm_password != null)) {
|
||||||
if(password.value != confirm_password.value) {
|
if(password.value != confirm_password.value) {
|
||||||
confirm_password.setCustomValidity("Passwords Don't Match");
|
confirm_password.setCustomValidity("Passwords Don't Match");
|
||||||
} else {
|
} else {
|
||||||
confirm_password.setCustomValidity('');
|
confirm_password.setCustomValidity('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((password != null) && (confirm_password != null)) {
|
if ((password != null) && (confirm_password != null)) {
|
||||||
password.onchange = ROC_AUTH.validatePassword();
|
password.onchange = ROC_AUTH.validatePassword();
|
||||||
confirm_password.onkeyup = ROC_AUTH.validatePassword;
|
confirm_password.onkeyup = ROC_AUTH.validatePassword;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,23 @@
|
|||||||
<div class="primary-tabs">
|
{unless isset="$user"}
|
||||||
{unless isset="$user"}
|
<div class="login-box">
|
||||||
<h3>Login or <a href="{$site_url/}account/roc-register">Register</a></h3>
|
<div class="description">The "Basic Auth" relies on the HTTP basic acces authentication.<br/>(see also: <a href="https://en.wikipedia.org/wiki/Basic_access_authentication">https://en.wikipedia.org/wiki/Basic_access_authentication</a> )</div>
|
||||||
|
<h3>Login or <a href="{$site_url/}account/roc-register">Register</a></h3>
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<form name="cms_basic_auth" action="{$site_url/}roc-basic-login" method="POST">
|
||||||
<form name="cms_basic_auth" action method="POST">
|
<input type="hidden" name="host" id="host" value="{$site_url/}">
|
||||||
<div>
|
<div>
|
||||||
<input type="text" name="username" id="username" required>
|
<input type="text" name="username" id="username" required>
|
||||||
<label>Username</label>
|
<label>Username</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
<div>
|
<input type="password" name="password" id="password" required>
|
||||||
<input type="password" name="password" id="password" required>
|
<label>Password</label>
|
||||||
<label>Password</label>
|
</div>
|
||||||
</div>
|
<button type="button" onclick="ROC_AUTH.login();">Login</button>
|
||||||
|
</form>
|
||||||
<button type="button" onclick="ROC_AUTH.login();">Login</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<a href="{$site_url/}account/new-password">Forgot password?</a>
|
||||||
<p>
|
|
||||||
<a href="{$site_url/}account/new-password">Forgot password?</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{/unless}
|
|
||||||
</div>
|
</div>
|
||||||
|
{/unless}
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ inherit
|
|||||||
contact_api
|
contact_api
|
||||||
end
|
end
|
||||||
|
|
||||||
SHARED_HTML_ENCODER
|
|
||||||
|
|
||||||
CMS_HOOK_BLOCK
|
CMS_HOOK_BLOCK
|
||||||
|
|
||||||
CMS_HOOK_BLOCK_HELPER
|
CMS_HOOK_BLOCK_HELPER
|
||||||
@@ -287,8 +285,8 @@ feature -- Hooks
|
|||||||
r.values.force (False, "has_error")
|
r.values.force (False, "has_error")
|
||||||
|
|
||||||
create vars.make_caseless (5)
|
create vars.make_caseless (5)
|
||||||
vars.put (html_encoded (api.setup.site_url), "siteurl")
|
vars.put (safe_html_encoded (api.setup.site_url), "siteurl")
|
||||||
vars.put (html_encoded (api.setup.site_name), "sitename")
|
vars.put (safe_html_encoded (api.setup.site_name), "sitename")
|
||||||
|
|
||||||
write_debug_log (generator + ".handle_post_contact {Form Parameters:" + form_parameters_as_string (req) + "}")
|
write_debug_log (generator + ".handle_post_contact {Form Parameters:" + form_parameters_as_string (req) + "}")
|
||||||
if
|
if
|
||||||
@@ -422,17 +420,6 @@ feature {NONE} -- Helpers
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- HTML ENCODING.
|
|
||||||
|
|
||||||
html_encoded (s: detachable READABLE_STRING_GENERAL): STRING_8
|
|
||||||
do
|
|
||||||
if s /= Void then
|
|
||||||
Result := html_encoder.general_encoded_string (s)
|
|
||||||
else
|
|
||||||
create Result.make_empty
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
feature {NONE} -- Contact Message
|
feature {NONE} -- Contact Message
|
||||||
|
|
||||||
template_block_with_values (a_module: CMS_MODULE; a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE; a_values: STRING_TABLE [ANY]): like template_block
|
template_block_with_values (a_module: CMS_MODULE; a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE; a_values: STRING_TABLE [ANY]): like template_block
|
||||||
|
|||||||
@@ -290,9 +290,7 @@ feature -- Access: Node
|
|||||||
is_author_of_node (u: CMS_USER; a_node: CMS_NODE): BOOLEAN
|
is_author_of_node (u: CMS_USER; a_node: CMS_NODE): BOOLEAN
|
||||||
-- Is the user `u' owner of the node `n'.
|
-- Is the user `u' owner of the node `n'.
|
||||||
do
|
do
|
||||||
if attached node_storage.node_author (a_node) as l_author then
|
Result := u.same_as (a_node.author)
|
||||||
Result := u.same_as (l_author)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
nodes_of_type (a_node_type: CMS_CONTENT_TYPE): LIST [CMS_NODE]
|
nodes_of_type (a_node_type: CMS_CONTENT_TYPE): LIST [CMS_NODE]
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ feature -- HTTP Methods
|
|||||||
if
|
if
|
||||||
l_node /= Void and then
|
l_node /= Void and then
|
||||||
l_rev > 0 and then
|
l_rev > 0 and then
|
||||||
node_api.has_permission_for_action_on_node ("view revisions", l_node, current_user (req))
|
node_api.has_permission_for_action_on_node ("view revisions", l_node, api.user)
|
||||||
then
|
then
|
||||||
l_node := node_api.revision_node (l_nid, l_rev)
|
l_node := node_api.revision_node (l_nid, l_rev)
|
||||||
end
|
end
|
||||||
@@ -137,9 +137,9 @@ feature -- HTTP Methods
|
|||||||
view_response.set_revision (l_rev)
|
view_response.set_revision (l_rev)
|
||||||
view_response.execute
|
view_response.execute
|
||||||
elseif
|
elseif
|
||||||
attached current_user (req) as l_user and then
|
attached api.user as l_user and then
|
||||||
( node_api.is_author_of_node (l_user, l_node)
|
( node_api.is_author_of_node (l_user, l_node)
|
||||||
or else api.user_api.user_has_permission (l_user, "view unpublished " + l_node.content_type)
|
or else api.user_has_permission (l_user, "view unpublished " + l_node.content_type)
|
||||||
)
|
)
|
||||||
then
|
then
|
||||||
create view_response.make (req, res, api, node_api)
|
create view_response.make (req, res, api, node_api)
|
||||||
@@ -208,13 +208,13 @@ feature -- HTTP Methods
|
|||||||
do_trash (req: WSF_REQUEST; res: WSF_RESPONSE)
|
do_trash (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- Trash a node, soft delete.
|
-- Trash a node, soft delete.
|
||||||
do
|
do
|
||||||
if attached current_user (req) as l_user then
|
if attached api.user as l_user then
|
||||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||||
if
|
if
|
||||||
l_id.is_integer and then
|
l_id.is_integer and then
|
||||||
attached node_api.node (l_id.integer_value) as l_node
|
attached node_api.node (l_id.integer_value) as l_node
|
||||||
then
|
then
|
||||||
if node_api.has_permission_for_action_on_node ("trash", l_node, current_user (req)) then
|
if node_api.has_permission_for_action_on_node ("trash", l_node, l_user) then
|
||||||
node_api.trash_node (l_node)
|
node_api.trash_node (l_node)
|
||||||
res.send (create {CMS_REDIRECTION_RESPONSE_MESSAGE}.make (req.absolute_script_url ("")))
|
res.send (create {CMS_REDIRECTION_RESPONSE_MESSAGE}.make (req.absolute_script_url ("")))
|
||||||
else
|
else
|
||||||
@@ -245,13 +245,13 @@ feature {NONE} -- Trash:Restore
|
|||||||
local
|
local
|
||||||
l_source: STRING
|
l_source: STRING
|
||||||
do
|
do
|
||||||
if attached current_user (req) as l_user then
|
if attached api.user as l_user then
|
||||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||||
if
|
if
|
||||||
l_id.is_integer and then
|
l_id.is_integer and then
|
||||||
attached {CMS_NODE} node_api.node (l_id.integer_value) as l_node
|
attached {CMS_NODE} node_api.node (l_id.integer_value) as l_node
|
||||||
then
|
then
|
||||||
if node_api.has_permission_for_action_on_node ("delete", l_node, current_user (req)) then
|
if node_api.has_permission_for_action_on_node ("delete", l_node, l_user) then
|
||||||
node_api.delete_node (l_node)
|
node_api.delete_node (l_node)
|
||||||
l_source := node_api.node_path (l_node)
|
l_source := node_api.node_path (l_node)
|
||||||
api.unset_path_alias (l_source, api.location_alias (l_source))
|
api.unset_path_alias (l_source, api.location_alias (l_source))
|
||||||
@@ -274,13 +274,13 @@ feature {NONE} -- Trash:Restore
|
|||||||
do_restore (req: WSF_REQUEST; res: WSF_RESPONSE)
|
do_restore (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- Restore a node: From {CMS_NODE_API}.trashed to {CMS_NODE_API}.not_published.
|
-- Restore a node: From {CMS_NODE_API}.trashed to {CMS_NODE_API}.not_published.
|
||||||
do
|
do
|
||||||
if attached current_user (req) as l_user then
|
if attached api.user as l_user then
|
||||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||||
if
|
if
|
||||||
l_id.is_integer and then
|
l_id.is_integer and then
|
||||||
attached node_api.node (l_id.integer_value) as l_node
|
attached node_api.node (l_id.integer_value) as l_node
|
||||||
then
|
then
|
||||||
if node_api.has_permission_for_action_on_node ("restore", l_node, current_user (req)) then
|
if node_api.has_permission_for_action_on_node ("restore", l_node, l_user) then
|
||||||
node_api.restore_node (l_node)
|
node_api.restore_node (l_node)
|
||||||
res.send (create {CMS_REDIRECTION_RESPONSE_MESSAGE}.make (req.absolute_script_url ("")))
|
res.send (create {CMS_REDIRECTION_RESPONSE_MESSAGE}.make (req.absolute_script_url ("")))
|
||||||
else
|
else
|
||||||
@@ -310,7 +310,7 @@ feature {NONE} -- Trash:Restore
|
|||||||
l_id.is_integer and then
|
l_id.is_integer and then
|
||||||
attached node_api.node (l_id.integer_value) as l_node
|
attached node_api.node (l_id.integer_value) as l_node
|
||||||
then
|
then
|
||||||
if node_api.has_permission_for_action_on_node ("view revisions", l_node, current_user (req)) then
|
if node_api.has_permission_for_action_on_node ("view revisions", l_node, api.user) then
|
||||||
create r.make (req, res, api)
|
create r.make (req, res, api)
|
||||||
create b.make_empty
|
create b.make_empty
|
||||||
b.append ("<ul>")
|
b.append ("<ul>")
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ feature -- Execution
|
|||||||
then
|
then
|
||||||
l_manager.append_content_as_html_to_page (l_node, Current)
|
l_manager.append_content_as_html_to_page (l_node, Current)
|
||||||
end
|
end
|
||||||
|
set_modification_date (l_node.modification_date)
|
||||||
elseif revision > 0 then
|
elseif revision > 0 then
|
||||||
set_main_content ("Missing revision node!")
|
set_main_content ("Missing revision node!")
|
||||||
else
|
else
|
||||||
@@ -64,8 +65,6 @@ feature -- Execution
|
|||||||
if l_node /= Void and revision > 0 then
|
if l_node /= Void and revision > 0 then
|
||||||
set_title ("Revision #" + revision.out + " of " + html_encoded (l_node.title))
|
set_title ("Revision #" + revision.out + " of " + html_encoded (l_node.title))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -120,13 +120,6 @@ feature -- Access
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
node_author (a_node: CMS_NODE): detachable CMS_USER
|
|
||||||
-- Node's author. if any.
|
|
||||||
require
|
|
||||||
valid_node: a_node.has_id
|
|
||||||
deferred
|
|
||||||
end
|
|
||||||
|
|
||||||
nodes_of_type (a_node_type: CMS_CONTENT_TYPE): LIST [CMS_NODE]
|
nodes_of_type (a_node_type: CMS_CONTENT_TYPE): LIST [CMS_NODE]
|
||||||
-- List of nodes of type `a_node_type'.
|
-- List of nodes of type `a_node_type'.
|
||||||
--| Redefine to optimize!
|
--| Redefine to optimize!
|
||||||
|
|||||||
@@ -75,17 +75,6 @@ feature -- Access: node
|
|||||||
do
|
do
|
||||||
end
|
end
|
||||||
|
|
||||||
node_author (a_node: CMS_NODE): detachable CMS_USER
|
|
||||||
-- Node's author. if any.
|
|
||||||
do
|
|
||||||
end
|
|
||||||
|
|
||||||
node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER]
|
|
||||||
-- Possible list of node's collaborator.
|
|
||||||
do
|
|
||||||
create {ARRAYED_LIST [CMS_USER]} Result.make (0)
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Access: outline
|
feature -- Access: outline
|
||||||
|
|
||||||
children (a_node: CMS_NODE): detachable LIST [CMS_NODE]
|
children (a_node: CMS_NODE): detachable LIST [CMS_NODE]
|
||||||
|
|||||||
@@ -206,23 +206,6 @@ feature -- Access
|
|||||||
sql_finalize
|
sql_finalize
|
||||||
end
|
end
|
||||||
|
|
||||||
node_author (a_node: CMS_NODE): detachable CMS_USER
|
|
||||||
-- Node's author for the given node id.
|
|
||||||
local
|
|
||||||
l_parameters: STRING_TABLE [ANY]
|
|
||||||
do
|
|
||||||
error_handler.reset
|
|
||||||
write_information_log (generator + ".node_author")
|
|
||||||
create l_parameters.make (2)
|
|
||||||
l_parameters.put (a_node.id, "nid")
|
|
||||||
l_parameters.put (a_node.revision, "revision")
|
|
||||||
sql_query (Select_user_author, l_parameters)
|
|
||||||
if not has_error and not sql_after then
|
|
||||||
Result := fetch_author
|
|
||||||
end
|
|
||||||
sql_finalize
|
|
||||||
end
|
|
||||||
|
|
||||||
last_inserted_node_id: INTEGER_64
|
last_inserted_node_id: INTEGER_64
|
||||||
-- Last insert node id.
|
-- Last insert node id.
|
||||||
do
|
do
|
||||||
@@ -589,11 +572,6 @@ feature {NONE} -- Queries
|
|||||||
sql_delete_node_revisions: STRING = "DELETE FROM node_revisions WHERE nid=:nid;"
|
sql_delete_node_revisions: STRING = "DELETE FROM node_revisions WHERE nid=:nid;"
|
||||||
|
|
||||||
|
|
||||||
feature {NONE} -- Sql Queries: USER_ROLES collaborators, author
|
|
||||||
|
|
||||||
Select_user_author: STRING = "SELECT uid, name, password, salt, email, users.status, users.created, signed FROM nodes INNER JOIN users ON nodes.author=users.uid AND nodes.nid = :nid AND nodes.revision = :revision;"
|
|
||||||
|
|
||||||
-- Select_node_author: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed FROM users INNER JOIN nodes ON nodes.author=users.uid AND nodes.nid =:nid;"
|
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
@@ -638,23 +616,4 @@ feature {NONE} -- Implementation
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fetch_author: detachable CMS_USER
|
|
||||||
do
|
|
||||||
if attached sql_read_string_32 (2) as l_name and then not l_name.is_whitespace then
|
|
||||||
create Result.make (l_name)
|
|
||||||
if attached sql_read_integer_32 (1) as l_id then
|
|
||||||
Result.set_id (l_id)
|
|
||||||
end
|
|
||||||
if attached sql_read_string (3) as l_password then
|
|
||||||
-- FIXME: should we return the password here ???
|
|
||||||
Result.set_hashed_password (l_password)
|
|
||||||
end
|
|
||||||
if attached sql_read_string (5) as l_email then
|
|
||||||
Result.set_email (l_email)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
check expected_valid_user: False end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class
|
|||||||
CMS_OAUTH_20_API
|
CMS_OAUTH_20_API
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
CMS_MODULE_API
|
CMS_AUTH_API_I
|
||||||
|
|
||||||
REFACTORING_HELPER
|
REFACTORING_HELPER
|
||||||
|
|
||||||
@@ -97,7 +97,6 @@ feature -- Access: Consumers OAuth20
|
|||||||
|
|
||||||
feature -- Change: User OAuth20
|
feature -- Change: User OAuth20
|
||||||
|
|
||||||
|
|
||||||
new_user_oauth2 (a_token: READABLE_STRING_GENERAL; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer: READABLE_STRING_GENERAL)
|
new_user_oauth2 (a_token: READABLE_STRING_GENERAL; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer: READABLE_STRING_GENERAL)
|
||||||
-- Add a new user with oauth20 using the consumer `a_consumer'.
|
-- Add a new user with oauth20 using the consumer `a_consumer'.
|
||||||
require
|
require
|
||||||
@@ -124,6 +123,4 @@ feature -- Change: User OAuth20
|
|||||||
oauth_20_storage.remove_user_oauth2 (a_user, a_consumer_table)
|
oauth_20_storage.remove_user_oauth2 (a_user, a_consumer_table)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ class
|
|||||||
CMS_OAUTH_20_MODULE
|
CMS_OAUTH_20_MODULE
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
CMS_MODULE
|
CMS_AUTH_MODULE_I
|
||||||
rename
|
rename
|
||||||
module_api as oauth20_api
|
module_api as oauth20_api
|
||||||
redefine
|
redefine
|
||||||
|
make,
|
||||||
filters,
|
filters,
|
||||||
setup_hooks,
|
setup_hooks,
|
||||||
initialize,
|
initialize,
|
||||||
@@ -22,12 +23,6 @@ inherit
|
|||||||
|
|
||||||
CMS_HOOK_BLOCK
|
CMS_HOOK_BLOCK
|
||||||
|
|
||||||
CMS_HOOK_AUTO_REGISTER
|
|
||||||
|
|
||||||
CMS_HOOK_MENU_SYSTEM_ALTER
|
|
||||||
|
|
||||||
CMS_HOOK_VALUE_TABLE_ALTER
|
|
||||||
|
|
||||||
SHARED_EXECUTION_ENVIRONMENT
|
SHARED_EXECUTION_ENVIRONMENT
|
||||||
export
|
export
|
||||||
{NONE} all
|
{NONE} all
|
||||||
@@ -35,10 +30,6 @@ inherit
|
|||||||
|
|
||||||
REFACTORING_HELPER
|
REFACTORING_HELPER
|
||||||
|
|
||||||
SHARED_LOGGER
|
|
||||||
|
|
||||||
CMS_REQUEST_UTIL
|
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
@@ -47,11 +38,9 @@ feature {NONE} -- Initialization
|
|||||||
make
|
make
|
||||||
-- Create current module
|
-- Create current module
|
||||||
do
|
do
|
||||||
|
Precursor
|
||||||
version := "1.0"
|
version := "1.0"
|
||||||
description := "OAuth20 module"
|
description := "OAuth20 module"
|
||||||
package := "authentication"
|
|
||||||
|
|
||||||
add_dependency ({CMS_AUTHENTICATION_MODULE})
|
|
||||||
|
|
||||||
create root_dir.make_current
|
create root_dir.make_current
|
||||||
cache_duration := 0
|
cache_duration := 0
|
||||||
@@ -135,7 +124,7 @@ feature {CMS_API} -- Module management
|
|||||||
end
|
end
|
||||||
l_sql_storage.sql_finalize
|
l_sql_storage.sql_finalize
|
||||||
|
|
||||||
Precursor {CMS_MODULE}(api) -- Marked as installed.
|
Precursor {CMS_AUTH_MODULE_I}(api) -- Marked as installed.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -151,8 +140,8 @@ feature -- Filters
|
|||||||
filters (a_api: CMS_API): detachable LIST [WSF_FILTER]
|
filters (a_api: CMS_API): detachable LIST [WSF_FILTER]
|
||||||
-- Possibly list of Filter's module.
|
-- Possibly list of Filter's module.
|
||||||
do
|
do
|
||||||
create {ARRAYED_LIST [WSF_FILTER]} Result.make (1)
|
|
||||||
if attached oauth20_api as l_oauth_api then
|
if attached oauth20_api as l_oauth_api then
|
||||||
|
create {ARRAYED_LIST [WSF_FILTER]} Result.make (1)
|
||||||
Result.extend (create {CMS_OAUTH_20_FILTER}.make (a_api, l_oauth_api))
|
Result.extend (create {CMS_OAUTH_20_FILTER}.make (a_api, l_oauth_api))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -172,27 +161,48 @@ feature -- Access: docs
|
|||||||
Result := cache_duration = 0
|
Result := cache_duration = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Access: auth strategy
|
||||||
|
|
||||||
|
login_title: STRING = "OAuth"
|
||||||
|
-- Module specific login title.
|
||||||
|
|
||||||
|
login_location: STRING = "account/auth/roc-oauth-login"
|
||||||
|
|
||||||
|
logout_location: STRING = "account/auth/roc-oauth-logout"
|
||||||
|
|
||||||
|
is_authenticating (a_response: CMS_RESPONSE): BOOLEAN
|
||||||
|
-- <Precursor>
|
||||||
|
do
|
||||||
|
if
|
||||||
|
a_response.is_authenticated and then
|
||||||
|
attached oauth20_api as l_oauth20_api and then
|
||||||
|
attached a_response.request.cookie (l_oauth20_api.session_token)
|
||||||
|
then
|
||||||
|
Result := True
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Router
|
feature -- Router
|
||||||
|
|
||||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
if attached oauth20_api as l_oauth_api then
|
if attached oauth20_api as l_oauth_api then
|
||||||
a_router.handle ("/account/roc-oauth-login",
|
a_router.handle ("/" + login_location,
|
||||||
create {WSF_URI_AGENT_HANDLER}.make (agent handle_login (a_api, ?, ?)), a_router.methods_head_get)
|
create {WSF_URI_AGENT_HANDLER}.make (agent handle_login (a_api, ?, ?)), a_router.methods_head_get)
|
||||||
a_router.handle ("/account/roc-oauth-logout",
|
a_router.handle ("/" + logout_location,
|
||||||
create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout (a_api, l_oauth_api, ?, ?)),
|
create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout (a_api, l_oauth_api, ?, ?)),
|
||||||
a_router.methods_get_post)
|
a_router.methods_get_post)
|
||||||
a_router.handle ("/account/login-with-oauth/{" + oauth_callback_path_parameter + "}",
|
a_router.handle ("/account/auth/login-with-oauth/{" + oauth_callback_path_parameter + "}",
|
||||||
create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_login_with_oauth (a_api, l_oauth_api, ?, ?)),
|
create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_login_with_oauth (a_api, l_oauth_api, ?, ?)),
|
||||||
a_router.methods_get_post)
|
a_router.methods_get_post)
|
||||||
a_router.handle ("/account/oauth-callback/{" + oauth_callback_path_parameter + "}",
|
a_router.handle ("/account/auth/oauth-callback/{" + oauth_callback_path_parameter + "}",
|
||||||
create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_callback_oauth (a_api, l_oauth_api, ?, ?)),
|
create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_callback_oauth (a_api, l_oauth_api, ?, ?)),
|
||||||
a_router.methods_get_post)
|
a_router.methods_get_post)
|
||||||
a_router.handle ("/account/oauth-associate",
|
a_router.handle ("/account/auth/oauth-associate",
|
||||||
create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_associate (a_api, l_oauth_api, ?, ?)),
|
create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_associate (a_api, l_oauth_api, ?, ?)),
|
||||||
a_router.methods_post)
|
a_router.methods_post)
|
||||||
a_router.handle ("/account/oauth-un-associate",
|
a_router.handle ("/account/auth/oauth-un-associate",
|
||||||
create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_un_associate (a_api, l_oauth_api, ?, ?)),
|
create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_un_associate (a_api, l_oauth_api, ?, ?)),
|
||||||
a_router.methods_post)
|
a_router.methods_post)
|
||||||
end
|
end
|
||||||
@@ -211,84 +221,22 @@ feature -- Hooks configuration
|
|||||||
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
|
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
|
||||||
-- Module hooks configuration.
|
-- Module hooks configuration.
|
||||||
do
|
do
|
||||||
auto_subscribe_to_hooks (a_hooks)
|
Precursor (a_hooks)
|
||||||
a_hooks.subscribe_to_block_hook (Current)
|
a_hooks.subscribe_to_block_hook (Current)
|
||||||
a_hooks.subscribe_to_value_table_alter_hook (Current)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Hooks
|
feature -- Hooks
|
||||||
|
|
||||||
value_table_alter (a_value: CMS_VALUE_TABLE; a_response: CMS_RESPONSE)
|
|
||||||
-- <Precursor>
|
|
||||||
do
|
|
||||||
if
|
|
||||||
attached a_response.user as u and then
|
|
||||||
attached oauth20_api as l_oauth20_api and then
|
|
||||||
attached a_response.request.cookie (l_oauth20_api.session_token)
|
|
||||||
then
|
|
||||||
a_value.force ("account/roc-oauth-logout", "auth_login_strategy")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)
|
|
||||||
-- Hook execution on collection of menu contained by `a_menu_system'
|
|
||||||
-- for related response `a_response'.
|
|
||||||
local
|
|
||||||
lnk: CMS_LOCAL_LINK
|
|
||||||
lnk2: detachable CMS_LINK
|
|
||||||
do
|
|
||||||
if
|
|
||||||
attached a_response.user as u and then
|
|
||||||
attached oauth20_api as l_oauth20_api and then
|
|
||||||
attached {WSF_STRING} a_response.request.cookie (l_oauth20_api.session_token) as l_roc_auth_session_token
|
|
||||||
then
|
|
||||||
across
|
|
||||||
a_menu_system.primary_menu.items as ic
|
|
||||||
until
|
|
||||||
lnk2 /= Void
|
|
||||||
loop
|
|
||||||
if
|
|
||||||
ic.item.location.same_string ("account/roc-logout") or else
|
|
||||||
ic.item.location.same_string ("basic_auth_logoff")
|
|
||||||
then
|
|
||||||
lnk2 := ic.item
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if lnk2 /= Void then
|
|
||||||
a_menu_system.primary_menu.remove (lnk2)
|
|
||||||
end
|
|
||||||
create lnk.make ("Logout", "account/roc-oauth-logout" )
|
|
||||||
a_menu_system.primary_menu.extend (lnk)
|
|
||||||
else
|
|
||||||
if a_response.location.starts_with ("account/") then
|
|
||||||
create lnk.make ("OAuth", "account/roc-oauth-login")
|
|
||||||
a_response.add_to_primary_tabs (lnk)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
||||||
local
|
|
||||||
l_string: STRING
|
|
||||||
do
|
do
|
||||||
Result := <<"login", "account">>
|
Result := <<"login", "account">>
|
||||||
debug ("roc")
|
|
||||||
create l_string.make_empty
|
|
||||||
across
|
|
||||||
Result as ic
|
|
||||||
loop
|
|
||||||
l_string.append (ic.item)
|
|
||||||
l_string.append_character (' ')
|
|
||||||
end
|
|
||||||
write_debug_log (generator + ".block_list:" + l_string )
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
||||||
do
|
do
|
||||||
if
|
if
|
||||||
a_block_id.is_case_insensitive_equal_general ("login") and then
|
a_block_id.is_case_insensitive_equal_general ("login") and then
|
||||||
a_response.location.starts_with ("account/roc-oauth-login")
|
a_response.location.starts_with (login_location)
|
||||||
then
|
then
|
||||||
get_block_view_login (a_block_id, a_response)
|
get_block_view_login (a_block_id, a_response)
|
||||||
elseif a_block_id.is_case_insensitive_equal_general ("account") and then
|
elseif a_block_id.is_case_insensitive_equal_general ("account") and then
|
||||||
@@ -299,6 +247,7 @@ feature -- Hooks
|
|||||||
attached a_response.user as l_user
|
attached a_response.user as l_user
|
||||||
then
|
then
|
||||||
associate_account (l_user, a_response.values)
|
associate_account (l_user, a_response.values)
|
||||||
|
l_tpl_block.set_weight (5)
|
||||||
a_response.add_block (l_tpl_block, "content")
|
a_response.add_block (l_tpl_block, "content")
|
||||||
else
|
else
|
||||||
debug ("cms")
|
debug ("cms")
|
||||||
@@ -313,7 +262,11 @@ feature -- Hooks
|
|||||||
r: CMS_RESPONSE
|
r: CMS_RESPONSE
|
||||||
do
|
do
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
r.set_value ("Login", "optional_content_type")
|
if r.is_authenticated then
|
||||||
|
r.add_error_message ("You are already signed in!")
|
||||||
|
else
|
||||||
|
r.set_value ("Login", "optional_content_type")
|
||||||
|
end
|
||||||
r.execute
|
r.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -323,7 +276,7 @@ feature -- Hooks
|
|||||||
l_cookie: WSF_COOKIE
|
l_cookie: WSF_COOKIE
|
||||||
do
|
do
|
||||||
if
|
if
|
||||||
attached {CMS_USER} current_user (req) as l_user and then
|
attached api.user as l_user and then
|
||||||
attached {WSF_STRING} req.cookie (a_oauth20_api.session_token) as l_cookie_token
|
attached {WSF_STRING} req.cookie (a_oauth20_api.session_token) as l_cookie_token
|
||||||
then
|
then
|
||||||
-- Logout OAuth
|
-- Logout OAuth
|
||||||
@@ -331,7 +284,7 @@ feature -- Hooks
|
|||||||
l_cookie.set_path ("/")
|
l_cookie.set_path ("/")
|
||||||
l_cookie.set_max_age (-1)
|
l_cookie.set_max_age (-1)
|
||||||
res.add_cookie (l_cookie)
|
res.add_cookie (l_cookie)
|
||||||
unset_current_user (req)
|
api.unset_current_user (req)
|
||||||
|
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
r.set_status_code ({HTTP_CONSTANTS}.found)
|
r.set_status_code ({HTTP_CONSTANTS}.found)
|
||||||
@@ -364,25 +317,6 @@ feature {NONE} -- Associate
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Helpers
|
|
||||||
|
|
||||||
template_block (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE): detachable CMS_SMARTY_TEMPLATE_BLOCK
|
|
||||||
-- Smarty content block for `a_block_id'
|
|
||||||
local
|
|
||||||
p: detachable PATH
|
|
||||||
do
|
|
||||||
create p.make_from_string ("templates")
|
|
||||||
p := p.extended ("block_").appended (a_block_id).appended_with_extension ("tpl")
|
|
||||||
p := a_response.api.module_theme_resource_location (Current, p)
|
|
||||||
if p /= Void then
|
|
||||||
if attached p.entry as e then
|
|
||||||
create Result.make (a_block_id, Void, p.parent, e)
|
|
||||||
else
|
|
||||||
create Result.make (a_block_id, Void, p.parent, p)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
feature {NONE} -- Block views
|
feature {NONE} -- Block views
|
||||||
|
|
||||||
get_block_view_login (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
get_block_view_login (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
||||||
@@ -392,7 +326,7 @@ feature {NONE} -- Block views
|
|||||||
if attached template_block (a_block_id, a_response) as l_tpl_block then
|
if attached template_block (a_block_id, a_response) as l_tpl_block then
|
||||||
create vals.make (1)
|
create vals.make (1)
|
||||||
-- add the variable to the block
|
-- add the variable to the block
|
||||||
value_table_alter (vals, a_response)
|
a_response.api.hooks.invoke_value_table_alter (vals, a_response)
|
||||||
across
|
across
|
||||||
vals as ic
|
vals as ic
|
||||||
loop
|
loop
|
||||||
@@ -507,10 +441,10 @@ feature -- OAuth2 Login with Provider
|
|||||||
l_cookie.set_max_age (l_access_token.expires_in)
|
l_cookie.set_max_age (l_access_token.expires_in)
|
||||||
l_cookie.set_path ("/")
|
l_cookie.set_path ("/")
|
||||||
res.add_cookie (l_cookie)
|
res.add_cookie (l_cookie)
|
||||||
set_current_user (req, l_user)
|
api.set_user (l_user)
|
||||||
|
api.record_user_login (l_user)
|
||||||
|
|
||||||
|
-- Send Email
|
||||||
-- Send Email
|
|
||||||
create es.make (create {CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS}.make (api))
|
create es.make (create {CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS}.make (api))
|
||||||
write_debug_log (generator + ".handle_callback_oauth: send_contact_welcome_email")
|
write_debug_log (generator + ".handle_callback_oauth: send_contact_welcome_email")
|
||||||
es.send_contact_welcome_email (l_email, l_user, req.absolute_script_url (""))
|
es.send_contact_welcome_email (l_email, l_user, req.absolute_script_url (""))
|
||||||
|
|||||||
@@ -10,15 +10,11 @@ class
|
|||||||
CMS_OAUTH_20_FILTER
|
CMS_OAUTH_20_FILTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
WSF_URI_TEMPLATE_HANDLER
|
CMS_AUTH_FILTER_I
|
||||||
|
|
||||||
CMS_HANDLER
|
|
||||||
rename
|
rename
|
||||||
make as make_handler
|
make as make_filter
|
||||||
end
|
end
|
||||||
|
|
||||||
WSF_FILTER
|
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
@@ -26,7 +22,7 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
make (a_api: CMS_API; a_user_oauth_api: CMS_OAUTH_20_API)
|
make (a_api: CMS_API; a_user_oauth_api: CMS_OAUTH_20_API)
|
||||||
do
|
do
|
||||||
make_handler (a_api)
|
make_filter (a_api)
|
||||||
oauth_api := a_user_oauth_api
|
oauth_api := a_user_oauth_api
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -34,21 +30,22 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
feature -- Basic operations
|
feature -- Basic operations
|
||||||
|
|
||||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
auth_strategy: STRING
|
||||||
-- Execute the filter.
|
do
|
||||||
|
Result := {CMS_OAUTH_20_MODULE}.logout_location
|
||||||
|
end
|
||||||
|
|
||||||
|
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
|
-- <Precursor>.
|
||||||
do
|
do
|
||||||
api.logger.put_debug (generator + ".execute ", Void)
|
|
||||||
-- A valid user
|
|
||||||
if
|
if
|
||||||
attached {WSF_STRING} req.cookie (oauth_api.session_token) as l_roc_auth_session_token
|
attached {WSF_STRING} req.cookie (oauth_api.session_token) as l_roc_auth_session_token
|
||||||
then
|
then
|
||||||
if attached oauth_api.user_oauth2_without_consumer_by_token (l_roc_auth_session_token.value) as l_user then
|
if attached oauth_api.user_oauth2_without_consumer_by_token (l_roc_auth_session_token.value) as l_user then
|
||||||
set_current_user (req, l_user)
|
set_current_user (l_user)
|
||||||
else
|
else
|
||||||
api.logger.put_error (generator + ".execute login_valid failed for: " + l_roc_auth_session_token.value , Void)
|
api.logger.put_error (generator + ".execute login_valid failed for: " + l_roc_auth_session_token.value , Void)
|
||||||
end
|
end
|
||||||
else
|
|
||||||
api.logger.put_debug (generator + ".execute without authentication", Void)
|
|
||||||
end
|
end
|
||||||
execute_next (req, res)
|
execute_next (req, res)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ feature -- Error Handling
|
|||||||
feature -- Access: Users
|
feature -- Access: Users
|
||||||
|
|
||||||
user_oauth2_by_id (a_uid: like {CMS_USER}.id; a_consumer_table: READABLE_STRING_GENERAL): detachable CMS_USER
|
user_oauth2_by_id (a_uid: like {CMS_USER}.id; a_consumer_table: READABLE_STRING_GENERAL): detachable CMS_USER
|
||||||
-- Retrieve a user by id `a_uid' for the consumer `a_consumer', if aby.
|
-- Retrieve a user by id `a_uid' for the consumer `a_consumer', if any.
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -45,23 +45,27 @@ feature -- Access User Outh
|
|||||||
local
|
local
|
||||||
l_parameters: STRING_TABLE [detachable ANY]
|
l_parameters: STRING_TABLE [detachable ANY]
|
||||||
l_string: STRING
|
l_string: STRING
|
||||||
|
l_uid: INTEGER_64
|
||||||
do
|
do
|
||||||
error_handler.reset
|
error_handler.reset
|
||||||
write_information_log (generator + ".user_oauth2_by_id")
|
write_information_log (generator + ".user_oauth2_by_id")
|
||||||
create l_parameters.make (1)
|
create l_parameters.make (1)
|
||||||
l_parameters.put (a_uid, "uid")
|
l_parameters.put (a_uid, "uid")
|
||||||
create l_string.make_from_string (select_user_oauth2_template_by_id)
|
create l_string.make_from_string (select_user_id_oauth2_template_by_id)
|
||||||
l_string.replace_substring_all ("$table_name", oauth2_sql_table_name (a_consumer))
|
l_string.replace_substring_all ("$table_name", oauth2_sql_table_name (a_consumer))
|
||||||
sql_query (l_string, l_parameters)
|
sql_query (l_string, l_parameters)
|
||||||
if not has_error and not sql_after then
|
if not has_error and not sql_after then
|
||||||
Result := fetch_user
|
l_uid := sql_read_integer_64 (1)
|
||||||
sql_forth
|
sql_forth
|
||||||
if not sql_after then
|
if not sql_after then
|
||||||
check no_more_than_one: False end
|
check no_more_than_one: False end
|
||||||
Result := Void
|
l_uid := 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sql_finalize
|
sql_finalize
|
||||||
|
if l_uid > 0 and attached api as l_cms_api then
|
||||||
|
Result := l_cms_api.user_api.user_by_id (l_uid)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
user_oauth2_by_email (a_email: like {CMS_USER}.email; a_consumer: READABLE_STRING_GENERAL): detachable CMS_USER
|
user_oauth2_by_email (a_email: like {CMS_USER}.email; a_consumer: READABLE_STRING_GENERAL): detachable CMS_USER
|
||||||
@@ -69,23 +73,27 @@ feature -- Access User Outh
|
|||||||
local
|
local
|
||||||
l_parameters: STRING_TABLE [detachable ANY]
|
l_parameters: STRING_TABLE [detachable ANY]
|
||||||
l_string: STRING
|
l_string: STRING
|
||||||
|
l_uid: INTEGER_64
|
||||||
do
|
do
|
||||||
error_handler.reset
|
error_handler.reset
|
||||||
write_information_log (generator + ".user_oauth2_by_email")
|
write_information_log (generator + ".user_oauth2_by_email")
|
||||||
create l_parameters.make (1)
|
create l_parameters.make (1)
|
||||||
l_parameters.put (a_email, "email")
|
l_parameters.put (a_email, "email")
|
||||||
create l_string.make_from_string (select_user_oauth2_template_by_email)
|
create l_string.make_from_string (select_user_id_oauth2_template_by_email)
|
||||||
l_string.replace_substring_all ("$table_name", oauth2_sql_table_name (a_consumer))
|
l_string.replace_substring_all ("$table_name", oauth2_sql_table_name (a_consumer))
|
||||||
sql_query (l_string, l_parameters)
|
sql_query (l_string, l_parameters)
|
||||||
if not has_error and not sql_after then
|
if not has_error and not sql_after then
|
||||||
Result := fetch_user
|
l_uid := sql_read_integer_64 (1)
|
||||||
sql_forth
|
sql_forth
|
||||||
if not sql_after then
|
if not sql_after then
|
||||||
check no_more_than_one: False end
|
check no_more_than_one: False end
|
||||||
Result := Void
|
l_uid := 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sql_finalize
|
sql_finalize
|
||||||
|
if l_uid > 0 and attached api as l_cms_api then
|
||||||
|
Result := l_cms_api.user_api.user_by_id (l_uid)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
user_oauth2_by_token (a_token: READABLE_STRING_GENERAL; a_consumer: READABLE_STRING_GENERAL): detachable CMS_USER
|
user_oauth2_by_token (a_token: READABLE_STRING_GENERAL; a_consumer: READABLE_STRING_GENERAL): detachable CMS_USER
|
||||||
@@ -93,26 +101,29 @@ feature -- Access User Outh
|
|||||||
local
|
local
|
||||||
l_parameters: STRING_TABLE [detachable ANY]
|
l_parameters: STRING_TABLE [detachable ANY]
|
||||||
l_string: STRING
|
l_string: STRING
|
||||||
|
l_uid: INTEGER_64
|
||||||
do
|
do
|
||||||
error_handler.reset
|
error_handler.reset
|
||||||
write_information_log (generator + ".user_by_oauth2_token")
|
write_information_log (generator + ".user_by_oauth2_token")
|
||||||
create l_parameters.make (1)
|
create l_parameters.make (1)
|
||||||
l_parameters.put (a_token, "token")
|
l_parameters.put (a_token, "token")
|
||||||
create l_string.make_from_string (select_user_by_oauth2_template_token)
|
create l_string.make_from_string (select_user_id_by_oauth2_template_token)
|
||||||
l_string.replace_substring_all ("$table_name", oauth2_sql_table_name (a_consumer))
|
l_string.replace_substring_all ("$table_name", oauth2_sql_table_name (a_consumer))
|
||||||
sql_query (l_string, l_parameters)
|
sql_query (l_string, l_parameters)
|
||||||
if not has_error and not sql_after then
|
if not has_error and not sql_after then
|
||||||
Result := fetch_user
|
l_uid := sql_read_integer_64 (1)
|
||||||
sql_forth
|
sql_forth
|
||||||
if not sql_after then
|
if not sql_after then
|
||||||
check no_more_than_one: False end
|
check no_more_than_one: False end
|
||||||
Result := Void
|
l_uid := 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sql_finalize
|
sql_finalize
|
||||||
|
if l_uid > 0 and attached api as l_cms_api then
|
||||||
|
Result := l_cms_api.user_api.user_by_id (l_uid)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature --Access: Consumers
|
feature --Access: Consumers
|
||||||
|
|
||||||
oauth2_consumers: LIST [STRING]
|
oauth2_consumers: LIST [STRING]
|
||||||
@@ -286,45 +297,6 @@ feature {NONE} -- Implementation OAuth Consumer
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation: User
|
|
||||||
|
|
||||||
fetch_user: detachable CMS_USER
|
|
||||||
local
|
|
||||||
l_id: INTEGER_64
|
|
||||||
l_name: detachable READABLE_STRING_32
|
|
||||||
do
|
|
||||||
if attached sql_read_integer_64 (1) as i then
|
|
||||||
l_id := i
|
|
||||||
end
|
|
||||||
if attached sql_read_string_32 (2) as s and then not s.is_whitespace then
|
|
||||||
l_name := s
|
|
||||||
end
|
|
||||||
|
|
||||||
if l_name /= Void then
|
|
||||||
create Result.make (l_name)
|
|
||||||
if l_id > 0 then
|
|
||||||
Result.set_id (l_id)
|
|
||||||
end
|
|
||||||
elseif l_id > 0 then
|
|
||||||
create Result.make_with_id (l_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
if Result /= Void then
|
|
||||||
if attached sql_read_string (3) as l_password then
|
|
||||||
-- FIXME: should we return the password here ???
|
|
||||||
Result.set_hashed_password (l_password)
|
|
||||||
end
|
|
||||||
if attached sql_read_string (5) as l_email then
|
|
||||||
Result.set_email (l_email)
|
|
||||||
end
|
|
||||||
if attached sql_read_integer_32 (6) as l_status then
|
|
||||||
Result.set_status (l_status)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
check expected_valid_user: False end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
feature {NONE} -- User OAuth2
|
feature {NONE} -- User OAuth2
|
||||||
|
|
||||||
oauth2_sql_table_name (a_consumer: READABLE_STRING_GENERAL): STRING_8
|
oauth2_sql_table_name (a_consumer: READABLE_STRING_GENERAL): STRING_8
|
||||||
@@ -353,12 +325,20 @@ feature {NONE} -- User OAuth2
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Select_user_by_oauth2_template_token: STRING = "SELECT u.* FROM users as u JOIN $table_name as og ON og.uid = u.uid and og.access_token = :token;"
|
Select_user_id_by_oauth2_template_token: STRING = "SELECT uid FROM $table_name WHERE access_token = :token;"
|
||||||
--| FIXME: replace the u.* by a list of field names, to avoid breaking `featch_user' if two fieds are swiped.
|
--| User id for access token :token
|
||||||
|
|
||||||
Select_user_oauth2_template_by_id: STRING = "SELECT u.* FROM users as u JOIN $table_name as og ON og.uid = u.uid and og.uid = :uid;"
|
Select_user_id_oauth2_template_by_id: STRING = "SELECT uid FROM $table_name WHERE uid = :uid;"
|
||||||
|
|
||||||
Select_user_oauth2_template_by_email: STRING = "SELECT u.* FROM users as u JOIN $table_name as og ON og.uid = u.uid and og.email = :email;"
|
Select_user_id_oauth2_template_by_email: STRING = "SELECT uid FROM $table_name WHERE email = :email;"
|
||||||
|
|
||||||
|
|
||||||
|
-- Select_user_by_oauth2_template_token: STRING = "SELECT u.* FROM users as u JOIN $table_name as og ON og.uid = u.uid and og.access_token = :token;"
|
||||||
|
-- --| FIXME: replace the u.* by a list of field names, to avoid breaking `featch_user' if two fieds are swiped.
|
||||||
|
|
||||||
|
-- Select_user_oauth2_template_by_id: STRING = "SELECT u.* FROM users as u JOIN $table_name as og ON og.uid = u.uid and og.uid = :uid;"
|
||||||
|
|
||||||
|
-- Select_user_oauth2_template_by_email: STRING = "SELECT u.* FROM users as u JOIN $table_name as og ON og.uid = u.uid and og.email = :email;"
|
||||||
|
|
||||||
Sql_insert_oauth2_template: STRING = "INSERT INTO $table_name (uid, access_token, details, created, email) VALUES (:uid, :token, :profile, :utc_date, :email);"
|
Sql_insert_oauth2_template: STRING = "INSERT INTO $table_name (uid, access_token, details, created, email) VALUES (:uid, :token, :profile, :utc_date, :email);"
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class
|
|||||||
CMS_OPENID_API
|
CMS_OPENID_API
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
CMS_MODULE_API
|
CMS_AUTH_API_I
|
||||||
|
|
||||||
REFACTORING_HELPER
|
REFACTORING_HELPER
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ feature {NONE} -- Initialization
|
|||||||
make (a_api)
|
make (a_api)
|
||||||
|
|
||||||
-- Initialize openid related settings.
|
-- Initialize openid related settings.
|
||||||
s := a_api.setup.string_8_item ("auth.openid.token")
|
s := a_api.setup.string_8_item ("auth." + {CMS_OPENID_MODULE}.name + ".token")
|
||||||
if s = Void then
|
if s = Void then
|
||||||
s := a_api.setup.site_id + default_session_token_suffix
|
s := a_api.setup.site_id + default_session_token_suffix
|
||||||
end
|
end
|
||||||
@@ -40,7 +40,7 @@ feature {NONE} -- Initialization
|
|||||||
session_max_age := 3600 --| one hour: *60(min) *60(sec)
|
session_max_age := 3600 --| one hour: *60(min) *60(sec)
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
openid_storage_set: openid_storage = a_openid_storage
|
openid_storage_set: openid_storage = a_openid_storage
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {CMS_MODULE} -- Access: User openid storage.
|
feature {CMS_MODULE} -- Access: User openid storage.
|
||||||
@@ -87,7 +87,6 @@ feature -- Access: Consumers OAuth20
|
|||||||
|
|
||||||
feature -- Change: User Openid
|
feature -- Change: User Openid
|
||||||
|
|
||||||
|
|
||||||
new_user_openid (a_identity: READABLE_STRING_GENERAL; a_user: CMS_USER)
|
new_user_openid (a_identity: READABLE_STRING_GENERAL; a_user: CMS_USER)
|
||||||
-- Add a new user with openid using the identity `a_identity'.
|
-- Add a new user with openid using the identity `a_identity'.
|
||||||
require
|
require
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ class
|
|||||||
CMS_OPENID_MODULE
|
CMS_OPENID_MODULE
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
CMS_MODULE
|
CMS_AUTH_MODULE_I
|
||||||
rename
|
rename
|
||||||
module_api as openid_api
|
module_api as openid_api
|
||||||
redefine
|
redefine
|
||||||
|
make,
|
||||||
filters,
|
filters,
|
||||||
setup_hooks,
|
setup_hooks,
|
||||||
initialize,
|
initialize,
|
||||||
@@ -20,15 +21,8 @@ inherit
|
|||||||
openid_api
|
openid_api
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
CMS_HOOK_BLOCK
|
CMS_HOOK_BLOCK
|
||||||
|
|
||||||
CMS_HOOK_AUTO_REGISTER
|
|
||||||
|
|
||||||
CMS_HOOK_MENU_SYSTEM_ALTER
|
|
||||||
|
|
||||||
CMS_HOOK_VALUE_TABLE_ALTER
|
|
||||||
|
|
||||||
SHARED_EXECUTION_ENVIRONMENT
|
SHARED_EXECUTION_ENVIRONMENT
|
||||||
export
|
export
|
||||||
{NONE} all
|
{NONE} all
|
||||||
@@ -36,11 +30,6 @@ inherit
|
|||||||
|
|
||||||
REFACTORING_HELPER
|
REFACTORING_HELPER
|
||||||
|
|
||||||
SHARED_LOGGER
|
|
||||||
|
|
||||||
CMS_REQUEST_UTIL
|
|
||||||
|
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
@@ -49,10 +38,9 @@ feature {NONE} -- Initialization
|
|||||||
make
|
make
|
||||||
-- Create current module
|
-- Create current module
|
||||||
do
|
do
|
||||||
|
Precursor
|
||||||
version := "1.0"
|
version := "1.0"
|
||||||
description := "Openid module"
|
description := "Openid module"
|
||||||
package := "authentication"
|
|
||||||
add_dependency ({CMS_AUTHENTICATION_MODULE})
|
|
||||||
|
|
||||||
create root_dir.make_current
|
create root_dir.make_current
|
||||||
cache_duration := 0
|
cache_duration := 0
|
||||||
@@ -111,7 +99,7 @@ feature {CMS_API} -- Module management
|
|||||||
if l_sql_storage.has_error then
|
if l_sql_storage.has_error then
|
||||||
api.logger.put_error ("Could not initialize openid items for module [" + name + "]", generating_type)
|
api.logger.put_error ("Could not initialize openid items for module [" + name + "]", generating_type)
|
||||||
else
|
else
|
||||||
Precursor {CMS_MODULE}(api) -- Mark it installed.
|
Precursor {CMS_AUTH_MODULE_I}(api) -- Mark it installed.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -149,22 +137,43 @@ feature -- Access: docs
|
|||||||
Result := cache_duration = 0
|
Result := cache_duration = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Access: auth strategy
|
||||||
|
|
||||||
|
login_title: STRING = "OpenID"
|
||||||
|
-- Module specific login title.
|
||||||
|
|
||||||
|
login_location: STRING = "account/auth/roc-openid-login"
|
||||||
|
|
||||||
|
logout_location: STRING = "account/auth/roc-openid-logout"
|
||||||
|
|
||||||
|
is_authenticating (a_response: CMS_RESPONSE): BOOLEAN
|
||||||
|
-- <Precursor>
|
||||||
|
do
|
||||||
|
if
|
||||||
|
a_response.is_authenticated and then
|
||||||
|
attached openid_api as l_openid_api and then
|
||||||
|
attached {WSF_STRING} a_response.request.cookie (l_openid_api.session_token)
|
||||||
|
then
|
||||||
|
Result := True
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Router
|
feature -- Router
|
||||||
|
|
||||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
if attached openid_api as l_openid_api then
|
if attached openid_api as l_openid_api then
|
||||||
a_router.handle ("/account/roc-openid-login",
|
a_router.handle ("/" + login_location,
|
||||||
create {WSF_URI_AGENT_HANDLER}.make (agent handle_openid_login (a_api, ?, ?)),
|
create {WSF_URI_AGENT_HANDLER}.make (agent handle_login (a_api, ?, ?)),
|
||||||
a_router.methods_get_post)
|
a_router.methods_get_post)
|
||||||
a_router.handle ("/account/roc-openid-logout",
|
a_router.handle ("/" + logout_location,
|
||||||
create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout (a_api, l_openid_api, ?, ?)),
|
create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout (a_api, l_openid_api, ?, ?)),
|
||||||
a_router.methods_get_post)
|
a_router.methods_get_post)
|
||||||
a_router.handle ("/account/login-with-openid/{" + openid_consumer_path_parameter + "}",
|
a_router.handle ("/account/auth/login-with-openid/{" + openid_consumer_path_parameter + "}",
|
||||||
create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_login_with_openid (a_api, l_openid_api, ?, ?)),
|
create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_login_with_openid (a_api, l_openid_api, ?, ?)),
|
||||||
a_router.methods_get_post)
|
a_router.methods_get_post)
|
||||||
a_router.handle ("/account/openid-callback",
|
a_router.handle ("/account/auth/openid-callback",
|
||||||
create {WSF_URI_AGENT_HANDLER}.make (agent handle_callback_openid (a_api, l_openid_api, ?, ?)),
|
create {WSF_URI_AGENT_HANDLER}.make (agent handle_callback_openid (a_api, l_openid_api, ?, ?)),
|
||||||
a_router.methods_get_post)
|
a_router.methods_get_post)
|
||||||
end
|
end
|
||||||
@@ -178,105 +187,45 @@ feature -- Hooks configuration
|
|||||||
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
|
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
|
||||||
-- Module hooks configuration.
|
-- Module hooks configuration.
|
||||||
do
|
do
|
||||||
auto_subscribe_to_hooks (a_hooks)
|
Precursor (a_hooks)
|
||||||
a_hooks.subscribe_to_block_hook (Current)
|
a_hooks.subscribe_to_block_hook (Current)
|
||||||
a_hooks.subscribe_to_value_table_alter_hook (Current)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Hooks
|
feature -- Hooks
|
||||||
|
|
||||||
value_table_alter (a_value: CMS_VALUE_TABLE; a_response: CMS_RESPONSE)
|
|
||||||
-- <Precursor>
|
|
||||||
do
|
|
||||||
if
|
|
||||||
attached a_response.user as u and then
|
|
||||||
attached openid_api as l_openid_api and then
|
|
||||||
attached {WSF_STRING} a_response.request.cookie (l_openid_api.session_token)
|
|
||||||
then
|
|
||||||
a_value.force ("account/roc-openid-logout", "auth_login_strategy")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)
|
|
||||||
-- Hook execution on collection of menu contained by `a_menu_system'
|
|
||||||
-- for related response `a_response'.
|
|
||||||
local
|
|
||||||
lnk: CMS_LOCAL_LINK
|
|
||||||
lnk2: detachable CMS_LINK
|
|
||||||
do
|
|
||||||
if
|
|
||||||
attached a_response.user as u and then
|
|
||||||
attached openid_api as l_openid_api and then
|
|
||||||
attached {WSF_STRING} a_response.request.cookie (l_openid_api.session_token) as l_roc_auth_session_token
|
|
||||||
then
|
|
||||||
across
|
|
||||||
a_menu_system.primary_menu.items as ic
|
|
||||||
until
|
|
||||||
lnk2 /= Void
|
|
||||||
loop
|
|
||||||
if
|
|
||||||
ic.item.location.same_string ("account/roc-logout") or else
|
|
||||||
ic.item.location.same_string ("basic_auth_logoff")
|
|
||||||
then
|
|
||||||
lnk2 := ic.item
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if lnk2 /= Void then
|
|
||||||
a_menu_system.primary_menu.remove (lnk2)
|
|
||||||
end
|
|
||||||
create lnk.make ("Logout", "account/roc-openid-logout" )
|
|
||||||
a_menu_system.primary_menu.extend (lnk)
|
|
||||||
else
|
|
||||||
if a_response.location.starts_with ("account/") then
|
|
||||||
create lnk.make ("Openid", "account/roc-openid-login")
|
|
||||||
a_response.add_to_primary_tabs (lnk)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
||||||
local
|
|
||||||
l_string: STRING
|
|
||||||
do
|
do
|
||||||
Result := <<"login">>
|
Result := <<"login">>
|
||||||
debug ("roc")
|
|
||||||
create l_string.make_empty
|
|
||||||
across
|
|
||||||
Result as ic
|
|
||||||
loop
|
|
||||||
l_string.append (ic.item)
|
|
||||||
l_string.append_character (' ')
|
|
||||||
end
|
|
||||||
write_debug_log (generator + ".block_list:" + l_string )
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
||||||
do
|
do
|
||||||
if
|
if
|
||||||
a_block_id.is_case_insensitive_equal_general ("login") and then
|
a_block_id.is_case_insensitive_equal_general ("login") and then
|
||||||
a_response.location.starts_with ("account/roc-openid-login")
|
a_response.location.starts_with (login_location)
|
||||||
then
|
then
|
||||||
get_block_view_login (a_block_id, a_response)
|
get_block_view_login (a_block_id, a_response)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
handle_openid_login (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
handle_login (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
local
|
local
|
||||||
r: CMS_RESPONSE
|
r: CMS_RESPONSE
|
||||||
o: OPENID_CONSUMER
|
o: OPENID_CONSUMER
|
||||||
s: STRING
|
s: STRING
|
||||||
do
|
do
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
if req.is_get_request_method then
|
if api.user_is_authenticated then
|
||||||
|
r.add_error_message ("You are already signed in!")
|
||||||
|
elseif req.is_get_request_method then
|
||||||
r.set_value ("Login", "optional_content_type")
|
r.set_value ("Login", "optional_content_type")
|
||||||
r.execute
|
|
||||||
|
|
||||||
elseif req.is_post_request_method then
|
elseif req.is_post_request_method then
|
||||||
create s.make_empty
|
create s.make_empty
|
||||||
if attached req.string_item ("openid") as p_openid then
|
if attached req.string_item ("openid") as p_openid then
|
||||||
s.append ("Check openID: " + p_openid)
|
s.append ("Check openID: " + p_openid)
|
||||||
create o.make (req.absolute_script_url ("/account/login-with-openid"))
|
create o.make (req.absolute_script_url ("/account/auth/login-with-openid"))
|
||||||
o.ask_email (True)
|
o.ask_email (True)
|
||||||
o.ask_all_info (False)
|
o.ask_all_info (False)
|
||||||
if attached o.auth_url (p_openid) as l_url then
|
if attached o.auth_url (p_openid) as l_url then
|
||||||
@@ -285,10 +234,10 @@ feature -- Hooks
|
|||||||
s.append (" Failure")
|
s.append (" Failure")
|
||||||
r.set_status_code ({HTTP_CONSTANTS}.bad_request)
|
r.set_status_code ({HTTP_CONSTANTS}.bad_request)
|
||||||
r.values.force (s, "error")
|
r.values.force (s, "error")
|
||||||
r.execute
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
r.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
handle_logout (api: CMS_API; a_openid_api: CMS_OPENID_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
handle_logout (api: CMS_API; a_openid_api: CMS_OPENID_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
@@ -297,7 +246,7 @@ feature -- Hooks
|
|||||||
l_cookie: WSF_COOKIE
|
l_cookie: WSF_COOKIE
|
||||||
do
|
do
|
||||||
if
|
if
|
||||||
attached {CMS_USER} current_user (req) as l_user and then
|
attached {CMS_USER} api.user as l_user and then
|
||||||
attached {WSF_STRING} req.cookie (a_openid_api.session_token) as l_cookie_token
|
attached {WSF_STRING} req.cookie (a_openid_api.session_token) as l_cookie_token
|
||||||
then
|
then
|
||||||
-- Logout OAuth
|
-- Logout OAuth
|
||||||
@@ -305,7 +254,7 @@ feature -- Hooks
|
|||||||
l_cookie.set_path ("/")
|
l_cookie.set_path ("/")
|
||||||
l_cookie.set_max_age (-1)
|
l_cookie.set_max_age (-1)
|
||||||
res.add_cookie (l_cookie)
|
res.add_cookie (l_cookie)
|
||||||
unset_current_user (req)
|
api.unset_current_user (req)
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
r.set_status_code ({HTTP_CONSTANTS}.found)
|
r.set_status_code ({HTTP_CONSTANTS}.found)
|
||||||
r.set_redirection (req.absolute_script_url (""))
|
r.set_redirection (req.absolute_script_url (""))
|
||||||
@@ -315,25 +264,6 @@ feature -- Hooks
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Helpers
|
|
||||||
|
|
||||||
template_block (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE): detachable CMS_SMARTY_TEMPLATE_BLOCK
|
|
||||||
-- Smarty content block for `a_block_id'
|
|
||||||
local
|
|
||||||
p: detachable PATH
|
|
||||||
do
|
|
||||||
create p.make_from_string ("templates")
|
|
||||||
p := p.extended ("block_").appended (a_block_id).appended_with_extension ("tpl")
|
|
||||||
p := a_response.api.module_theme_resource_location (Current, p)
|
|
||||||
if p /= Void then
|
|
||||||
if attached p.entry as e then
|
|
||||||
create Result.make (a_block_id, Void, p.parent, e)
|
|
||||||
else
|
|
||||||
create Result.make (a_block_id, Void, p.parent, p)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
feature {NONE} -- Block views
|
feature {NONE} -- Block views
|
||||||
|
|
||||||
get_block_view_login (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
get_block_view_login (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
||||||
@@ -343,7 +273,7 @@ feature {NONE} -- Block views
|
|||||||
if attached template_block (a_block_id, a_response) as l_tpl_block then
|
if attached template_block (a_block_id, a_response) as l_tpl_block then
|
||||||
create vals.make (1)
|
create vals.make (1)
|
||||||
-- add the variable to the block
|
-- add the variable to the block
|
||||||
value_table_alter (vals, a_response)
|
a_response.api.hooks.invoke_value_table_alter (vals, a_response)
|
||||||
across
|
across
|
||||||
vals as ic
|
vals as ic
|
||||||
loop
|
loop
|
||||||
@@ -380,7 +310,7 @@ feature -- Openid Login
|
|||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
create b.make_empty
|
create b.make_empty
|
||||||
b.append ("Check openID: " + p_openid.value)
|
b.append ("Check openID: " + p_openid.value)
|
||||||
create o.make (req.absolute_script_url ("/account/openid-callback"))
|
create o.make (req.absolute_script_url ("/account/auth/openid-callback"))
|
||||||
o.ask_email (True)
|
o.ask_email (True)
|
||||||
o.ask_all_info (False)
|
o.ask_all_info (False)
|
||||||
if attached o.auth_url (l_oc.endpoint) as l_url then
|
if attached o.auth_url (l_oc.endpoint) as l_url then
|
||||||
@@ -433,6 +363,7 @@ feature -- Openid Login
|
|||||||
l_cookie.set_max_age (a_openid_api.session_max_age)
|
l_cookie.set_max_age (a_openid_api.session_max_age)
|
||||||
l_cookie.set_path ("/")
|
l_cookie.set_path ("/")
|
||||||
res.add_cookie (l_cookie)
|
res.add_cookie (l_cookie)
|
||||||
|
api.record_user_login (p_user)
|
||||||
else
|
else
|
||||||
|
|
||||||
create {ARRAYED_LIST [CMS_USER_ROLE]} l_roles.make (1)
|
create {ARRAYED_LIST [CMS_USER_ROLE]} l_roles.make (1)
|
||||||
|
|||||||
@@ -9,15 +9,11 @@ class
|
|||||||
CMS_OPENID_FILTER
|
CMS_OPENID_FILTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
WSF_URI_TEMPLATE_HANDLER
|
CMS_AUTH_FILTER_I
|
||||||
|
|
||||||
CMS_HANDLER
|
|
||||||
rename
|
rename
|
||||||
make as make_handler
|
make as make_filter
|
||||||
end
|
end
|
||||||
|
|
||||||
WSF_FILTER
|
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
@@ -25,7 +21,7 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
make (a_api: CMS_API; a_openid_api: CMS_OPENID_API)
|
make (a_api: CMS_API; a_openid_api: CMS_OPENID_API)
|
||||||
do
|
do
|
||||||
make_handler (a_api)
|
make_filter (a_api)
|
||||||
openid_api := a_openid_api
|
openid_api := a_openid_api
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -33,15 +29,19 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
feature -- Basic operations
|
feature -- Basic operations
|
||||||
|
|
||||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
auth_strategy: STRING
|
||||||
-- Execute the filter.
|
do
|
||||||
|
Result := {CMS_OPENID_MODULE}.logout_location
|
||||||
|
end
|
||||||
|
|
||||||
|
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
|
-- <Precursor>.
|
||||||
do
|
do
|
||||||
-- A valid user
|
|
||||||
if
|
if
|
||||||
attached {WSF_STRING} req.cookie (openid_api.session_token) as l_roc_openid_session_token
|
attached {WSF_STRING} req.cookie (openid_api.session_token) as l_roc_openid_session_token
|
||||||
then
|
then
|
||||||
if attached openid_api.user_openid_by_identity (l_roc_openid_session_token.value) as l_user then
|
if attached openid_api.user_openid_by_identity (l_roc_openid_session_token.value) as l_user then
|
||||||
set_current_user (req, l_user)
|
set_current_user (l_user)
|
||||||
else
|
else
|
||||||
api.logger.put_error (generator + ".execute login_valid failed for: " + l_roc_openid_session_token.value , Void)
|
api.logger.put_error (generator + ".execute login_valid failed for: " + l_roc_openid_session_token.value , Void)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,45 +26,53 @@ feature -- Access User Outh
|
|||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
l_parameters: STRING_TABLE [detachable ANY]
|
l_parameters: STRING_TABLE [detachable ANY]
|
||||||
|
l_uid: INTEGER_64
|
||||||
do
|
do
|
||||||
error_handler.reset
|
error_handler.reset
|
||||||
write_information_log (generator + ".user_openid_by_userid_identity")
|
write_information_log (generator + ".user_openid_by_userid_identity")
|
||||||
create l_parameters.make (1)
|
create l_parameters.make (1)
|
||||||
l_parameters.put (a_uid, "uid")
|
l_parameters.put (a_uid, "uid")
|
||||||
l_parameters.put (a_identity, "identity")
|
l_parameters.put (a_identity, "identity")
|
||||||
sql_query (Select_user_openid_by_id, l_parameters)
|
sql_query (Select_user_id_openid_by_id, l_parameters)
|
||||||
if not has_error and not sql_after then
|
if not has_error and not sql_after then
|
||||||
Result := fetch_user
|
l_uid := sql_read_integer_64 (1)
|
||||||
sql_forth
|
sql_forth
|
||||||
if not sql_after then
|
if not sql_after then
|
||||||
check no_more_than_one: False end
|
check no_more_than_one: False end
|
||||||
Result := Void
|
l_uid := 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sql_finalize
|
sql_finalize
|
||||||
|
if l_uid > 0 and attached api as l_cms_api then
|
||||||
|
Result := l_cms_api.user_api.user_by_id (l_uid)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
user_openid_by_identity (a_identity: READABLE_STRING_GENERAL): detachable CMS_USER
|
user_openid_by_identity (a_identity: READABLE_STRING_GENERAL): detachable CMS_USER
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
l_parameters: STRING_TABLE [detachable ANY]
|
l_parameters: STRING_TABLE [detachable ANY]
|
||||||
|
l_uid: INTEGER_64
|
||||||
do
|
do
|
||||||
error_handler.reset
|
error_handler.reset
|
||||||
write_information_log (generator + ".user_openid_by_identity")
|
write_information_log (generator + ".user_openid_by_identity")
|
||||||
create l_parameters.make (1)
|
create l_parameters.make (1)
|
||||||
l_parameters.put (a_identity, "identity")
|
l_parameters.put (a_identity, "identity")
|
||||||
sql_query (Select_user_by_openid_identity, l_parameters)
|
sql_query (Select_user_id_by_openid_identity, l_parameters)
|
||||||
if not has_error and not sql_after then
|
if not has_error and not sql_after then
|
||||||
Result := fetch_user
|
l_uid := sql_read_integer_64 (1)
|
||||||
sql_forth
|
sql_forth
|
||||||
if not sql_after then
|
if not sql_after then
|
||||||
check no_more_than_one: False end
|
check no_more_than_one: False end
|
||||||
Result := Void
|
l_uid := 0
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
check no_more_than_one: False end
|
check no_more_than_one: False end
|
||||||
end
|
end
|
||||||
sql_finalize
|
sql_finalize
|
||||||
|
if l_uid > 0 and attached api as l_cms_api then
|
||||||
|
Result := l_cms_api.user_api.user_by_id (l_uid)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature --Access: Consumers
|
feature --Access: Consumers
|
||||||
@@ -148,52 +156,11 @@ feature {NONE} -- Implementation OAuth Consumer
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation: User
|
|
||||||
|
|
||||||
fetch_user: detachable CMS_USER
|
|
||||||
local
|
|
||||||
l_id: INTEGER_64
|
|
||||||
l_name: detachable READABLE_STRING_32
|
|
||||||
do
|
|
||||||
if attached sql_read_integer_64 (1) as i then
|
|
||||||
l_id := i
|
|
||||||
end
|
|
||||||
if attached sql_read_string_32 (2) as s and then not s.is_whitespace then
|
|
||||||
l_name := s
|
|
||||||
end
|
|
||||||
|
|
||||||
if l_name /= Void then
|
|
||||||
create Result.make (l_name)
|
|
||||||
if l_id > 0 then
|
|
||||||
Result.set_id (l_id)
|
|
||||||
end
|
|
||||||
elseif l_id > 0 then
|
|
||||||
create Result.make_with_id (l_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
if Result /= Void then
|
|
||||||
if attached sql_read_string (3) as l_password then
|
|
||||||
-- FIXME: should we return the password here ???
|
|
||||||
Result.set_hashed_password (l_password)
|
|
||||||
end
|
|
||||||
if attached sql_read_string (5) as l_email then
|
|
||||||
Result.set_email (l_email)
|
|
||||||
end
|
|
||||||
if attached sql_read_integer_32 (6) as l_status then
|
|
||||||
Result.set_status (l_status)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
check expected_valid_user: False end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
feature {NONE} -- User OpenID
|
feature {NONE} -- User OpenID
|
||||||
|
|
||||||
|
Select_user_id_by_openid_identity: STRING = "SELECT uid FROM openid_items WHERE identity = :identity;"
|
||||||
|
|
||||||
Select_user_by_openid_identity: STRING = "SELECT u.* FROM users as u JOIN openid_items as og ON og.uid = u.uid and og.identity = :identity;"
|
Select_user_id_openid_by_id: STRING = "SELECT uid FROM openid_items WHERE uid = :uid and identity = :identity;"
|
||||||
--| FIXME: replace the u.* by a list of field names, to avoid breaking `featch_user' if two fieds are swiped.
|
|
||||||
|
|
||||||
Select_user_openid_by_id: STRING = "SELECT u.* FROM users as u JOIN openid_items as og ON og.uid = u.uid and og.uid = :uid and og.identity = :identity;"
|
|
||||||
|
|
||||||
Sql_insert_openid: STRING = "INSERT INTO openid_items (uid, identity, created) VALUES (:uid, :identity, :utc_date);"
|
Sql_insert_openid: STRING = "INSERT INTO openid_items (uid, identity, created) VALUES (:uid, :identity, :utc_date);"
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class
|
|||||||
CMS_SESSION_API
|
CMS_SESSION_API
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
CMS_MODULE_API
|
CMS_AUTH_API_I
|
||||||
|
|
||||||
REFACTORING_HELPER
|
REFACTORING_HELPER
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ class
|
|||||||
CMS_SESSION_AUTH_MODULE
|
CMS_SESSION_AUTH_MODULE
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
CMS_MODULE
|
CMS_AUTH_MODULE_I
|
||||||
rename
|
rename
|
||||||
module_api as session_api
|
module_api as session_api
|
||||||
redefine
|
redefine
|
||||||
|
make,
|
||||||
filters,
|
filters,
|
||||||
setup_hooks,
|
setup_hooks,
|
||||||
initialize,
|
initialize,
|
||||||
@@ -21,19 +22,8 @@ inherit
|
|||||||
session_api
|
session_api
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
CMS_HOOK_AUTO_REGISTER
|
|
||||||
|
|
||||||
CMS_HOOK_BLOCK
|
CMS_HOOK_BLOCK
|
||||||
|
|
||||||
CMS_HOOK_MENU_SYSTEM_ALTER
|
|
||||||
|
|
||||||
CMS_HOOK_VALUE_TABLE_ALTER
|
|
||||||
|
|
||||||
SHARED_LOGGER
|
|
||||||
|
|
||||||
CMS_REQUEST_UTIL
|
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
@@ -41,10 +31,9 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
make
|
make
|
||||||
do
|
do
|
||||||
|
Precursor
|
||||||
version := "1.0"
|
version := "1.0"
|
||||||
description := "Service to manage cookie based authentication"
|
description := "Service to manage cookie based authentication"
|
||||||
package := "authentication"
|
|
||||||
add_dependency ({CMS_AUTHENTICATION_MODULE})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
@@ -87,7 +76,7 @@ feature {CMS_API} -- Module management
|
|||||||
if l_sql_storage.has_error then
|
if l_sql_storage.has_error then
|
||||||
api.logger.put_error ("Could not initialize database for module [" + name + "]", generating_type)
|
api.logger.put_error ("Could not initialize database for module [" + name + "]", generating_type)
|
||||||
else
|
else
|
||||||
Precursor {CMS_MODULE} (api) -- Mark it as installed.
|
Precursor {CMS_AUTH_MODULE_I} (api) -- Mark it as installed.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -95,7 +84,28 @@ feature {CMS_API} -- Module management
|
|||||||
feature {CMS_API} -- Access: API
|
feature {CMS_API} -- Access: API
|
||||||
|
|
||||||
session_api: detachable CMS_SESSION_API
|
session_api: detachable CMS_SESSION_API
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
|
|
||||||
|
feature -- Access: auth strategy
|
||||||
|
|
||||||
|
login_title: STRING = "Session"
|
||||||
|
-- Module specific login title.
|
||||||
|
|
||||||
|
login_location: STRING = "account/auth/roc-session-login"
|
||||||
|
|
||||||
|
logout_location: STRING = "account/auth/roc-session-logout"
|
||||||
|
|
||||||
|
is_authenticating (a_response: CMS_RESPONSE): BOOLEAN
|
||||||
|
-- <Precursor>
|
||||||
|
do
|
||||||
|
if
|
||||||
|
a_response.is_authenticated and then
|
||||||
|
attached session_api as l_session_api and then
|
||||||
|
attached a_response.request.cookie (l_session_api.session_token)
|
||||||
|
then
|
||||||
|
Result := True
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Access: router
|
feature -- Access: router
|
||||||
|
|
||||||
@@ -103,9 +113,9 @@ feature -- Access: router
|
|||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
if attached session_api as l_session_api then
|
if attached session_api as l_session_api then
|
||||||
a_router.handle ("/account/roc-session-login", create {WSF_URI_AGENT_HANDLER}.make (agent handle_login (a_api, ?, ?)), a_router.methods_head_get)
|
a_router.handle ("/" + login_location, create {WSF_URI_AGENT_HANDLER}.make (agent handle_login (a_api, ?, ?)), a_router.methods_head_get)
|
||||||
a_router.handle ("/account/roc-session-logout", create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout (a_api, l_session_api, ?, ?)), a_router.methods_get_post)
|
a_router.handle ("/" + logout_location, create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout (a_api, l_session_api, ?, ?)), a_router.methods_get_post)
|
||||||
a_router.handle ("/account/login-with-session", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_login_with_session (a_api,session_api, ?, ?)), a_router.methods_get_post)
|
a_router.handle ("/account/auth/roc-session-login", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_login_with_session (a_api,session_api, ?, ?)), a_router.methods_get_post)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -114,8 +124,8 @@ feature -- Access: filter
|
|||||||
filters (a_api: CMS_API): detachable LIST [WSF_FILTER]
|
filters (a_api: CMS_API): detachable LIST [WSF_FILTER]
|
||||||
-- Possibly list of Filter's module.
|
-- Possibly list of Filter's module.
|
||||||
do
|
do
|
||||||
create {ARRAYED_LIST [WSF_FILTER]} Result.make (1)
|
|
||||||
if attached session_api as l_session_api then
|
if attached session_api as l_session_api then
|
||||||
|
create {ARRAYED_LIST [WSF_FILTER]} Result.make (1)
|
||||||
Result.extend (create {CMS_SESSION_AUTH_FILTER}.make (a_api, l_session_api))
|
Result.extend (create {CMS_SESSION_AUTH_FILTER}.make (a_api, l_session_api))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -124,9 +134,29 @@ feature {NONE} -- Implementation: routes
|
|||||||
|
|
||||||
handle_login (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
handle_login (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
local
|
local
|
||||||
|
vals: CMS_VALUE_TABLE
|
||||||
r: CMS_RESPONSE
|
r: CMS_RESPONSE
|
||||||
do
|
do
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
|
if api.user_is_authenticated then
|
||||||
|
r.add_error_message ("You are already signed in!")
|
||||||
|
else
|
||||||
|
if attached template_block ("login", r) as l_tpl_block then
|
||||||
|
create vals.make (1)
|
||||||
|
-- add the variable to the block
|
||||||
|
l_tpl_block.set_value (api.user, "user")
|
||||||
|
l_tpl_block.set_value (r.url ("", Void), "site_url")
|
||||||
|
api.hooks.invoke_value_table_alter (vals, r)
|
||||||
|
across
|
||||||
|
vals as ic
|
||||||
|
loop
|
||||||
|
l_tpl_block.set_value (ic.item, ic.key)
|
||||||
|
end
|
||||||
|
r.add_block (l_tpl_block, "content")
|
||||||
|
else
|
||||||
|
r.add_error_message ("Error: missing block [login]")
|
||||||
|
end
|
||||||
|
end
|
||||||
r.execute
|
r.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -139,14 +169,14 @@ feature {NONE} -- Implementation: routes
|
|||||||
tok := a_session_api.session_token
|
tok := a_session_api.session_token
|
||||||
if
|
if
|
||||||
attached {WSF_STRING} req.cookie (tok) as l_cookie_token and then
|
attached {WSF_STRING} req.cookie (tok) as l_cookie_token and then
|
||||||
attached {CMS_USER} current_user (req) as l_user
|
attached api.user as l_user
|
||||||
then
|
then
|
||||||
-- Logout Session
|
-- Logout Session
|
||||||
create l_cookie.make (tok, l_cookie_token.value) -- FIXME: unicode issue?
|
create l_cookie.make (tok, l_cookie_token.value) -- FIXME: unicode issue?
|
||||||
l_cookie.set_path ("/")
|
l_cookie.set_path ("/")
|
||||||
l_cookie.set_max_age (-1)
|
l_cookie.set_max_age (-1)
|
||||||
res.add_cookie (l_cookie)
|
res.add_cookie (l_cookie)
|
||||||
unset_current_user (req)
|
api.unset_user
|
||||||
|
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
r.set_status_code ({HTTP_CONSTANTS}.found)
|
r.set_status_code ({HTTP_CONSTANTS}.found)
|
||||||
@@ -166,25 +196,39 @@ feature {NONE} -- Implementation: routes
|
|||||||
if
|
if
|
||||||
attached a_session_api as l_session_api and then
|
attached a_session_api as l_session_api and then
|
||||||
attached {WSF_STRING} req.form_parameter ("username") as l_username and then
|
attached {WSF_STRING} req.form_parameter ("username") as l_username and then
|
||||||
attached {WSF_STRING} req.form_parameter ("password") as l_password and then
|
attached {WSF_STRING} req.form_parameter ("password") as l_password
|
||||||
api.user_api.is_valid_credential (l_username.value, l_password.value) and then
|
|
||||||
attached api.user_api.user_by_name (l_username.value) as l_user
|
|
||||||
then
|
then
|
||||||
l_token := generate_token
|
|
||||||
if
|
if
|
||||||
a_session_api.has_user_token (l_user)
|
api.user_api.is_valid_credential (l_username.value, l_password.value) and then
|
||||||
|
attached api.user_api.user_by_name (l_username.value) as l_user
|
||||||
then
|
then
|
||||||
l_session_api.update_user_session_auth (l_token, l_user)
|
l_token := generate_token
|
||||||
|
if a_session_api.has_user_token (l_user) then
|
||||||
|
l_session_api.update_user_session_auth (l_token, l_user)
|
||||||
|
else
|
||||||
|
l_session_api.new_user_session_auth (l_token, l_user)
|
||||||
|
end
|
||||||
|
create l_cookie.make (a_session_api.session_token, l_token)
|
||||||
|
l_cookie.set_max_age (a_session_api.session_max_age)
|
||||||
|
l_cookie.set_path ("/")
|
||||||
|
res.add_cookie (l_cookie)
|
||||||
|
api.set_user (l_user)
|
||||||
|
api.record_user_login (l_user)
|
||||||
|
|
||||||
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
|
if attached {WSF_STRING} req.query_parameter ("destination") as p_destination then
|
||||||
|
r.set_redirection (p_destination.url_encoded_value)
|
||||||
|
else
|
||||||
|
r.set_redirection ("")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
l_session_api.new_user_session_auth (l_token, l_user)
|
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||||
|
if attached template_block ("login", r) as l_tpl_block then
|
||||||
|
l_tpl_block.set_value (l_username.value, "username")
|
||||||
|
l_tpl_block.set_value ("Wrong: Username or password ", "error")
|
||||||
|
r.add_block (l_tpl_block, "content")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
create l_cookie.make (a_session_api.session_token, l_token)
|
|
||||||
l_cookie.set_max_age (a_session_api.session_max_age)
|
|
||||||
l_cookie.set_path ("/")
|
|
||||||
res.add_cookie (l_cookie)
|
|
||||||
set_current_user (req, l_user)
|
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
|
||||||
r.set_redirection (req.absolute_script_url (""))
|
|
||||||
r.execute
|
r.execute
|
||||||
else
|
else
|
||||||
create {BAD_REQUEST_ERROR_CMS_RESPONSE} r.make (req, res, api)
|
create {BAD_REQUEST_ERROR_CMS_RESPONSE} r.make (req, res, api)
|
||||||
@@ -204,108 +248,24 @@ feature -- Hooks configuration
|
|||||||
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
|
setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
|
||||||
-- Module hooks configuration.
|
-- Module hooks configuration.
|
||||||
do
|
do
|
||||||
auto_subscribe_to_hooks (a_hooks)
|
Precursor (a_hooks)
|
||||||
a_hooks.subscribe_to_block_hook (Current)
|
a_hooks.subscribe_to_block_hook (Current)
|
||||||
a_hooks.subscribe_to_value_table_alter_hook (Current)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Hooks
|
feature -- Hooks
|
||||||
|
|
||||||
value_table_alter (a_value: CMS_VALUE_TABLE; a_response: CMS_RESPONSE)
|
|
||||||
-- <Precursor>
|
|
||||||
do
|
|
||||||
if
|
|
||||||
attached a_response.user as u and then
|
|
||||||
attached session_api as l_session_api and then
|
|
||||||
attached a_response.request.cookie (l_session_api.session_token)
|
|
||||||
then
|
|
||||||
a_value.force ("account/roc-session-logout", "auth_login_strategy")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)
|
|
||||||
-- Hook execution on collection of menu contained by `a_menu_system'
|
|
||||||
-- for related response `a_response'.
|
|
||||||
local
|
|
||||||
lnk: CMS_LOCAL_LINK
|
|
||||||
lnk2: detachable CMS_LINK
|
|
||||||
do
|
|
||||||
if attached a_response.user as u then
|
|
||||||
if
|
|
||||||
attached session_api as l_session_api and then
|
|
||||||
attached a_response.request.cookie (l_session_api.session_token)
|
|
||||||
then
|
|
||||||
across
|
|
||||||
a_menu_system.primary_menu.items as ic
|
|
||||||
until
|
|
||||||
lnk2 /= Void
|
|
||||||
loop
|
|
||||||
if
|
|
||||||
ic.item.location.same_string ("account/roc-logout")
|
|
||||||
or else ic.item.location.same_string ("basic_auth_logoff")
|
|
||||||
then
|
|
||||||
lnk2 := ic.item
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if lnk2 /= Void then
|
|
||||||
a_menu_system.primary_menu.remove (lnk2)
|
|
||||||
end
|
|
||||||
create lnk.make ("Logout", "account/roc-session-logout" )
|
|
||||||
a_menu_system.primary_menu.extend (lnk)
|
|
||||||
end
|
|
||||||
elseif a_response.location.starts_with ("account/") then
|
|
||||||
create lnk.make ("Session", "account/roc-session-login")
|
|
||||||
a_response.add_to_primary_tabs (lnk)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
block_list: ITERABLE [like {CMS_BLOCK}.name]
|
||||||
local
|
|
||||||
l_string: STRING
|
|
||||||
do
|
do
|
||||||
Result := <<"login">>
|
Result := <<"?login">>
|
||||||
debug ("roc")
|
|
||||||
create l_string.make_empty
|
|
||||||
across
|
|
||||||
Result as ic
|
|
||||||
loop
|
|
||||||
l_string.append (ic.item)
|
|
||||||
l_string.append_character (' ')
|
|
||||||
end
|
|
||||||
write_debug_log (generator + ".block_list:" + l_string )
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
||||||
do
|
do
|
||||||
if
|
if a_block_id.is_case_insensitive_equal_general ("login") then
|
||||||
a_block_id.is_case_insensitive_equal_general ("login") and then
|
|
||||||
a_response.location.starts_with ("account/roc-session-login")
|
|
||||||
then
|
|
||||||
get_block_view_login (a_block_id, a_response)
|
get_block_view_login (a_block_id, a_response)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Helpers
|
|
||||||
|
|
||||||
template_block (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE): detachable CMS_SMARTY_TEMPLATE_BLOCK
|
|
||||||
-- Smarty content block for `a_block_id'
|
|
||||||
local
|
|
||||||
p: detachable PATH
|
|
||||||
do
|
|
||||||
create p.make_from_string ("templates")
|
|
||||||
p := p.extended ("block_").appended (a_block_id).appended_with_extension ("tpl")
|
|
||||||
|
|
||||||
p := a_response.api.module_theme_resource_location (Current, p)
|
|
||||||
if p /= Void then
|
|
||||||
if attached p.entry as e then
|
|
||||||
create Result.make (a_block_id, Void, p.parent, e)
|
|
||||||
else
|
|
||||||
create Result.make (a_block_id, Void, p.parent, p)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
feature {NONE} -- Block views
|
feature {NONE} -- Block views
|
||||||
|
|
||||||
get_block_view_login (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
get_block_view_login (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
|
||||||
@@ -315,7 +275,7 @@ feature {NONE} -- Block views
|
|||||||
if attached template_block (a_block_id, a_response) as l_tpl_block then
|
if attached template_block (a_block_id, a_response) as l_tpl_block then
|
||||||
create vals.make (1)
|
create vals.make (1)
|
||||||
-- add the variable to the block
|
-- add the variable to the block
|
||||||
value_table_alter (vals, a_response)
|
a_response.api.hooks.invoke_value_table_alter (vals, a_response)
|
||||||
across
|
across
|
||||||
vals as ic
|
vals as ic
|
||||||
loop
|
loop
|
||||||
@@ -347,4 +307,5 @@ feature {NONE} -- Block views
|
|||||||
end
|
end
|
||||||
Result := l_token
|
Result := l_token
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,15 +9,11 @@ class
|
|||||||
CMS_SESSION_AUTH_FILTER
|
CMS_SESSION_AUTH_FILTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
WSF_URI_TEMPLATE_HANDLER
|
CMS_AUTH_FILTER_I
|
||||||
|
|
||||||
CMS_HANDLER
|
|
||||||
rename
|
rename
|
||||||
make as make_handler
|
make as make_filter
|
||||||
end
|
end
|
||||||
|
|
||||||
WSF_FILTER
|
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
@@ -25,7 +21,7 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
make (a_api: CMS_API; a_session_api: CMS_SESSION_API)
|
make (a_api: CMS_API; a_session_api: CMS_SESSION_API)
|
||||||
do
|
do
|
||||||
make_handler (a_api)
|
make_filter (a_api)
|
||||||
session_api := a_session_api
|
session_api := a_session_api
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -33,15 +29,19 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
feature -- Basic operations
|
feature -- Basic operations
|
||||||
|
|
||||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
auth_strategy: STRING
|
||||||
-- Execute the filter.
|
do
|
||||||
|
Result := {CMS_SESSION_AUTH_MODULE}.logout_location
|
||||||
|
end
|
||||||
|
|
||||||
|
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
|
-- <Precursor>.
|
||||||
do
|
do
|
||||||
-- A valid user
|
|
||||||
if
|
if
|
||||||
attached {WSF_STRING} req.cookie (session_api.session_token) as l_roc_auth_session_token
|
attached {WSF_STRING} req.cookie (session_api.session_token) as l_roc_auth_session_token
|
||||||
then
|
then
|
||||||
if attached session_api.user_by_session_token (l_roc_auth_session_token.value) as l_user then
|
if attached session_api.user_by_session_token (l_roc_auth_session_token.value) as l_user then
|
||||||
set_current_user (req, l_user)
|
set_current_user (l_user)
|
||||||
else
|
else
|
||||||
api.logger.put_error (generator + ".execute login_valid failed for: " + l_roc_auth_session_token.value , Void)
|
api.logger.put_error (generator + ".execute login_valid failed for: " + l_roc_auth_session_token.value , Void)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ feature -- Change User token
|
|||||||
|
|
||||||
feature {NONE} -- SQL statements
|
feature {NONE} -- SQL statements
|
||||||
|
|
||||||
Select_user_id_by_token: STRING = "SELECT u.uid FROM users as u JOIN auth_session as og ON og.uid = u.uid AND og.access_token = :token;"
|
Select_user_id_by_token: STRING = "SELECT uid FROM auth_session WHERE access_token = :token;"
|
||||||
|
|
||||||
sql_insert_session_auth: STRING = "INSERT INTO auth_session (uid, access_token, created) VALUES (:uid, :token, :utc_date);"
|
sql_insert_session_auth: STRING = "INSERT INTO auth_session (uid, access_token, created) VALUES (:uid, :token, :utc_date);"
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +1,23 @@
|
|||||||
<div class="primary-tabs">
|
{unless isset="$user"}
|
||||||
{unless isset="$user"}
|
<div class="login-box">
|
||||||
<h3>Login or <a href="{$site_url/}account/roc-register">Register</a></h3>
|
<div class="description">The "Session" is the standard authentication system. (based on cookie)</div>
|
||||||
<div>
|
<h3>Login or <a href="{$site_url/}account/roc-register">Register</a></h3>
|
||||||
<div>
|
<div>
|
||||||
<form name="cms_session_auth" action="{$site_url/}account/login-with-session" method="POST">
|
<form name="cms_session_auth" action="{$site_url/}account/auth/roc-session-login" method="POST">
|
||||||
<div>
|
|
||||||
<input type="text" name="username" id="username" required value="{$username/}">
|
|
||||||
<label>Username</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<input type="password" name="password" id="password" required >
|
|
||||||
<label>Password</label>
|
|
||||||
</div>
|
|
||||||
<button type="submit">Login</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div>
|
<div>
|
||||||
<p>
|
<input type="text" name="username" id="username" required value="{$username/}">
|
||||||
<a href="{$site_url/}account/new-password">Forgot password?</a>
|
<label>Username</label>
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{/unless}
|
|
||||||
{if isset=$error}
|
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<input type="password" name="password" id="password" required >
|
||||||
<p>
|
<label>Password</label>
|
||||||
<strong>{$error/}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<button type="submit">Login</button>
|
||||||
{/if}
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<a href="{$site_url/}account/new-password">Forgot password?</a>
|
||||||
|
</div>
|
||||||
|
{if isset="$error"}<div class="error">{$error/}</div>{/if}
|
||||||
|
</div>
|
||||||
|
{/unless}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ feature -- HTTP Methods
|
|||||||
l_typename: READABLE_STRING_GENERAL
|
l_typename: READABLE_STRING_GENERAL
|
||||||
s: STRING
|
s: STRING
|
||||||
do
|
do
|
||||||
if not api.user_has_permission (current_user (req), "admin taxonomy") then
|
if not api.has_permission ("admin taxonomy") then
|
||||||
send_access_denied (req, res)
|
send_access_denied (req, res)
|
||||||
else
|
else
|
||||||
if attached {WSF_STRING} req.form_parameter ("op") as p_op then
|
if attached {WSF_STRING} req.form_parameter ("op") as p_op then
|
||||||
@@ -161,7 +161,7 @@ feature -- HTTP Methods
|
|||||||
local
|
local
|
||||||
tid: INTEGER_64
|
tid: INTEGER_64
|
||||||
do
|
do
|
||||||
if not api.user_has_permission (current_user (req), "admin taxonomy") then
|
if not api.has_permission ("admin taxonomy") then
|
||||||
send_access_denied (req, res)
|
send_access_denied (req, res)
|
||||||
else
|
else
|
||||||
if attached {WSF_STRING} req.path_parameter ("vocid") as p_vocid then
|
if attached {WSF_STRING} req.path_parameter ("vocid") as p_vocid then
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ class
|
|||||||
|
|
||||||
inherit
|
inherit
|
||||||
CMS_BLOCK
|
CMS_BLOCK
|
||||||
|
redefine
|
||||||
|
append_to_html
|
||||||
|
end
|
||||||
|
|
||||||
create
|
create
|
||||||
make_with_block
|
make_with_block
|
||||||
@@ -47,6 +50,12 @@ feature -- Status report
|
|||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
|
append_to_html (a_theme: CMS_THEME; a_output: STRING_8)
|
||||||
|
-- Append HTML representation of Current block to `a_output'.
|
||||||
|
do
|
||||||
|
origin.append_to_html (a_theme, a_output)
|
||||||
|
end
|
||||||
|
|
||||||
to_html (a_theme: CMS_THEME): STRING_8
|
to_html (a_theme: CMS_THEME): STRING_8
|
||||||
-- HTML representation of Current block.
|
-- HTML representation of Current block.
|
||||||
do
|
do
|
||||||
@@ -54,6 +63,6 @@ feature -- Conversion
|
|||||||
end
|
end
|
||||||
|
|
||||||
;note
|
;note
|
||||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -82,6 +82,12 @@ feature -- Element change
|
|||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
|
append_to_html (a_theme: CMS_THEME; a_output: STRING_8)
|
||||||
|
-- Append HTML representation of Current block to `a_output'.
|
||||||
|
do
|
||||||
|
a_output.append (to_html (a_theme))
|
||||||
|
end
|
||||||
|
|
||||||
to_html (a_theme: CMS_THEME): STRING_8
|
to_html (a_theme: CMS_THEME): STRING_8
|
||||||
-- HTML representation of Current block.
|
-- HTML representation of Current block.
|
||||||
deferred
|
deferred
|
||||||
@@ -112,6 +118,6 @@ feature -- Status report
|
|||||||
end
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ feature -- Conversion
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
note
|
note
|
||||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -27,6 +27,16 @@ feature -- Encoders
|
|||||||
Result := html_encoder.general_encoded_string (a_string)
|
Result := html_encoder.general_encoded_string (a_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
safe_html_encoded (a_string: detachable READABLE_STRING_GENERAL): STRING_8
|
||||||
|
-- `a_string' encoded for html output or empty string.
|
||||||
|
do
|
||||||
|
if a_string /= Void then
|
||||||
|
Result := html_encoded (a_string)
|
||||||
|
else
|
||||||
|
Result := ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
url_encoded,
|
url_encoded,
|
||||||
percent_encoded (a_string: READABLE_STRING_GENERAL): STRING_8
|
percent_encoded (a_string: READABLE_STRING_GENERAL): STRING_8
|
||||||
-- `a_string' encoded with percent encoding, mainly used for url.
|
-- `a_string' encoded with percent encoding, mainly used for url.
|
||||||
@@ -34,4 +44,7 @@ feature -- Encoders
|
|||||||
Result := percent_encoder.percent_encoded_string (a_string)
|
Result := percent_encoder.percent_encoded_string (a_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
note
|
||||||
|
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -190,6 +190,6 @@ feature -- Debug
|
|||||||
Result.append ("%N}")
|
Result.append ("%N}")
|
||||||
end
|
end
|
||||||
note
|
note
|
||||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -118,33 +118,8 @@ feature -- Change: user
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Access: roles and permissions
|
feature -- Access: roles and permissions
|
||||||
|
|
||||||
-- user_has_permission (u: detachable CMS_USER; s: detachable READABLE_STRING_8): BOOLEAN
|
|
||||||
-- -- Anonymous or user `u' has permission for `s' ?
|
|
||||||
-- --| `s' could be "create page",
|
|
||||||
-- do
|
|
||||||
---- if s = Void then
|
|
||||||
---- Result := True
|
|
||||||
---- elseif u = Void then
|
|
||||||
------ Result := user_role_has_permission (anonymous_user_role, s)
|
|
||||||
---- else
|
|
||||||
---- Result := user_role_has_permission (authenticated_user_role, s)
|
|
||||||
---- if not Result and attached u.roles as l_roles then
|
|
||||||
---- across
|
|
||||||
---- l_roles as r
|
|
||||||
---- until
|
|
||||||
---- Result
|
|
||||||
---- loop
|
|
||||||
---- if attached user_role_by_id (r.item) as ur then
|
|
||||||
---- Result := user_role_has_permission (ur, s)
|
|
||||||
---- end
|
|
||||||
---- end
|
|
||||||
---- end
|
|
||||||
---- end
|
|
||||||
-- end
|
|
||||||
|
|
||||||
user_role_has_permission (a_role: CMS_USER_ROLE; s: READABLE_STRING_8): BOOLEAN
|
user_role_has_permission (a_role: CMS_USER_ROLE; s: READABLE_STRING_8): BOOLEAN
|
||||||
do
|
do
|
||||||
Result := a_role.has_permission (s)
|
Result := a_role.has_permission (s)
|
||||||
|
|||||||
@@ -76,7 +76,6 @@ feature -- Change: user
|
|||||||
do
|
do
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Access: roles and permissions
|
feature -- Access: roles and permissions
|
||||||
|
|
||||||
user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE
|
user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE
|
||||||
|
|||||||
@@ -267,13 +267,14 @@ feature -- Change: user
|
|||||||
sql_begin_transaction
|
sql_begin_transaction
|
||||||
|
|
||||||
write_information_log (generator + ".update_user")
|
write_information_log (generator + ".update_user")
|
||||||
create l_parameters.make (6)
|
create l_parameters.make (7)
|
||||||
l_parameters.put (a_user.id, "uid")
|
l_parameters.put (a_user.id, "uid")
|
||||||
l_parameters.put (a_user.name, "name")
|
l_parameters.put (a_user.name, "name")
|
||||||
l_parameters.put (l_password_hash, "password")
|
l_parameters.put (l_password_hash, "password")
|
||||||
l_parameters.put (l_password_salt, "salt")
|
l_parameters.put (l_password_salt, "salt")
|
||||||
l_parameters.put (l_email, "email")
|
l_parameters.put (l_email, "email")
|
||||||
l_parameters.put (a_user.status, "status")
|
l_parameters.put (a_user.status, "status")
|
||||||
|
l_parameters.put (a_user.last_login_date, "signed")
|
||||||
|
|
||||||
sql_modify (sql_update_user, l_parameters)
|
sql_modify (sql_update_user, l_parameters)
|
||||||
sql_finalize
|
sql_finalize
|
||||||
@@ -307,6 +308,8 @@ feature -- Change: user
|
|||||||
sql_finalize
|
sql_finalize
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Change: roles
|
||||||
|
|
||||||
update_user_roles (a_user: CMS_USER)
|
update_user_roles (a_user: CMS_USER)
|
||||||
-- Update roles of `a_user'
|
-- Update roles of `a_user'
|
||||||
require
|
require
|
||||||
@@ -847,6 +850,9 @@ feature {NONE} -- Implementation: User
|
|||||||
if attached sql_read_integer_32 (6) as l_status then
|
if attached sql_read_integer_32 (6) as l_status then
|
||||||
Result.set_status (l_status)
|
Result.set_status (l_status)
|
||||||
end
|
end
|
||||||
|
if attached sql_read_date_time (8) as l_signed_date then
|
||||||
|
Result.set_last_login_date (l_signed_date)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
check expected_valid_user: False end
|
check expected_valid_user: False end
|
||||||
end
|
end
|
||||||
@@ -903,7 +909,7 @@ feature {NONE} -- Sql Queries: USER
|
|||||||
sql_insert_user: STRING = "INSERT INTO users (name, password, salt, email, created, status) VALUES (:name, :password, :salt, :email, :created, :status);"
|
sql_insert_user: STRING = "INSERT INTO users (name, password, salt, email, created, status) VALUES (:name, :password, :salt, :email, :created, :status);"
|
||||||
-- SQL Insert to add a new user.
|
-- SQL Insert to add a new user.
|
||||||
|
|
||||||
sql_update_user: STRING = "UPDATE users SET name=:name, password=:password, salt=:salt, email=:email, status=:status WHERE uid=:uid;"
|
sql_update_user: STRING = "UPDATE users SET name=:name, password=:password, salt=:salt, email=:email, status=:status, signed=:signed WHERE uid=:uid;"
|
||||||
-- SQL update to update an existing user.
|
-- SQL update to update an existing user.
|
||||||
|
|
||||||
sql_delete_user: STRING = "DELETE FROM users WHERE uid=:uid;"
|
sql_delete_user: STRING = "DELETE FROM users WHERE uid=:uid;"
|
||||||
|
|||||||
@@ -9,22 +9,24 @@ class
|
|||||||
inherit
|
inherit
|
||||||
ANY
|
ANY
|
||||||
|
|
||||||
|
CMS_ENCODERS
|
||||||
|
|
||||||
CMS_HOOK_EXPORT
|
CMS_HOOK_EXPORT
|
||||||
|
|
||||||
CMS_EXPORT_JSON_UTILITIES
|
CMS_EXPORT_JSON_UTILITIES
|
||||||
|
|
||||||
REFACTORING_HELPER
|
REFACTORING_HELPER
|
||||||
|
|
||||||
CMS_REQUEST_UTIL
|
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature {NONE} -- Initialize
|
feature {NONE} -- Initialize
|
||||||
|
|
||||||
make (a_setup: CMS_SETUP)
|
make (a_setup: CMS_SETUP; req: WSF_REQUEST)
|
||||||
-- Create the API service with a setup `a_setup'
|
-- Create the API service with a setup `a_setup'
|
||||||
|
-- and request `req'.
|
||||||
do
|
do
|
||||||
|
request := req
|
||||||
setup := a_setup
|
setup := a_setup
|
||||||
create error_handler.make
|
create error_handler.make
|
||||||
create {CMS_ENV_LOGGER} logger.make
|
create {CMS_ENV_LOGGER} logger.make
|
||||||
@@ -168,6 +170,12 @@ feature -- Access
|
|||||||
storage: CMS_STORAGE
|
storage: CMS_STORAGE
|
||||||
-- Default persistence storage.
|
-- Default persistence storage.
|
||||||
|
|
||||||
|
feature {NONE} -- Access: request
|
||||||
|
|
||||||
|
request: WSF_REQUEST
|
||||||
|
-- Associated http request.
|
||||||
|
--| note: here for the sole purpose of CMS_API.
|
||||||
|
|
||||||
feature -- Content
|
feature -- Content
|
||||||
|
|
||||||
content_types: ARRAYED_LIST [CMS_CONTENT_TYPE]
|
content_types: ARRAYED_LIST [CMS_CONTENT_TYPE]
|
||||||
@@ -375,6 +383,13 @@ feature {NONE} -- Emails implementation
|
|||||||
|
|
||||||
feature -- Permissions system
|
feature -- Permissions system
|
||||||
|
|
||||||
|
has_permission (a_permission: detachable READABLE_STRING_GENERAL): BOOLEAN
|
||||||
|
-- Anonymous or user `user' has permission for `a_permission'?
|
||||||
|
--| `a_permission' could be for instance "create page".
|
||||||
|
do
|
||||||
|
Result := user_api.user_has_permission (user, a_permission)
|
||||||
|
end
|
||||||
|
|
||||||
user_has_permission (a_user: detachable CMS_USER; a_permission: detachable READABLE_STRING_GENERAL): BOOLEAN
|
user_has_permission (a_user: detachable CMS_USER; a_permission: detachable READABLE_STRING_GENERAL): BOOLEAN
|
||||||
-- Anonymous or user `a_user' has permission for `a_permission'?
|
-- Anonymous or user `a_user' has permission for `a_permission'?
|
||||||
--| `a_permission' could be for instance "create page".
|
--| `a_permission' could be for instance "create page".
|
||||||
@@ -866,6 +881,113 @@ feature -- Hook
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Access: active user
|
||||||
|
|
||||||
|
user_is_authenticated: BOOLEAN
|
||||||
|
-- Is user authenticated?
|
||||||
|
do
|
||||||
|
Result := user /= Void
|
||||||
|
ensure
|
||||||
|
Result implies user /= Void
|
||||||
|
end
|
||||||
|
|
||||||
|
user: detachable CMS_USER
|
||||||
|
-- Current user or Void in case of visitor.
|
||||||
|
note
|
||||||
|
EIS: "eiffel:?class=CMS_BASIC_AUTH_FILTER&feature=execute"
|
||||||
|
do
|
||||||
|
Result := current_user (request)
|
||||||
|
end
|
||||||
|
|
||||||
|
set_user (a_user: CMS_USER)
|
||||||
|
-- Set `a_user' as current `user'.
|
||||||
|
require
|
||||||
|
a_user_attached: a_user /= Void
|
||||||
|
do
|
||||||
|
set_current_user (request, a_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
unset_user
|
||||||
|
-- Unset `user'.
|
||||||
|
do
|
||||||
|
unset_current_user (request)
|
||||||
|
end
|
||||||
|
|
||||||
|
record_user_login (a_user: CMS_USER)
|
||||||
|
-- Record login event for `a_user'.
|
||||||
|
require
|
||||||
|
user_has_id: a_user.has_id
|
||||||
|
do
|
||||||
|
a_user.set_last_login_date_now
|
||||||
|
user_api.update_user (a_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Request utilities
|
||||||
|
|
||||||
|
execution_variable (a_name: READABLE_STRING_GENERAL): detachable ANY
|
||||||
|
-- Execution variable related to `a_name'
|
||||||
|
require
|
||||||
|
a_name_valid: a_name /= Void and then not a_name.is_empty
|
||||||
|
do
|
||||||
|
Result := request.execution_variable (a_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
set_execution_variable (a_name: READABLE_STRING_GENERAL; a_value: detachable ANY)
|
||||||
|
do
|
||||||
|
request.set_execution_variable (a_name, a_value)
|
||||||
|
ensure
|
||||||
|
param_set: execution_variable (a_name) = a_value
|
||||||
|
end
|
||||||
|
|
||||||
|
unset_execution_variable (a_name: READABLE_STRING_GENERAL)
|
||||||
|
do
|
||||||
|
request.unset_execution_variable (a_name)
|
||||||
|
ensure
|
||||||
|
param_unset: execution_variable (a_name) = Void
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
feature {CMS_API_ACCESS, CMS_RESPONSE, CMS_MODULE} -- Request utilities
|
||||||
|
|
||||||
|
current_user (req: WSF_REQUEST): detachable CMS_USER
|
||||||
|
-- Current user or Void in case of Guest user.
|
||||||
|
do
|
||||||
|
check req = request end
|
||||||
|
if attached {CMS_USER} execution_variable (cms_execution_variable_name ("user")) as l_user then
|
||||||
|
Result := l_user
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
set_current_user (req: WSF_REQUEST; a_user: CMS_USER)
|
||||||
|
-- Set `a_user' as `current_user'.
|
||||||
|
do
|
||||||
|
check req = request end
|
||||||
|
set_execution_variable (cms_execution_variable_name ("user"), a_user)
|
||||||
|
ensure
|
||||||
|
user_set: current_user (req) ~ a_user
|
||||||
|
end
|
||||||
|
|
||||||
|
unset_current_user (req: WSF_REQUEST)
|
||||||
|
-- Unset current user.
|
||||||
|
do
|
||||||
|
check req = request end
|
||||||
|
req.unset_execution_variable (cms_execution_variable_name ("user"))
|
||||||
|
ensure
|
||||||
|
user_unset: current_user (req) = Void
|
||||||
|
end
|
||||||
|
|
||||||
|
feature {NONE} -- Implementation: current user
|
||||||
|
|
||||||
|
cms_execution_variable_name (a_name: READABLE_STRING_GENERAL): READABLE_STRING_GENERAL
|
||||||
|
-- Execution variable name for `a_name'.
|
||||||
|
local
|
||||||
|
s32: STRING_32
|
||||||
|
do
|
||||||
|
create s32.make_from_string_general (once "_roccms_.")
|
||||||
|
s32.append_string_general (a_name)
|
||||||
|
Result := s32
|
||||||
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ feature {NONE} -- Initialization
|
|||||||
l_setup := initial_cms_setup
|
l_setup := initial_cms_setup
|
||||||
setup_storage (l_setup)
|
setup_storage (l_setup)
|
||||||
setup_modules (l_setup)
|
setup_modules (l_setup)
|
||||||
create api.make (l_setup)
|
create api.make (l_setup, request)
|
||||||
modules := api.enabled_modules
|
modules := api.enabled_modules
|
||||||
|
|
||||||
initialize_cms
|
initialize_cms
|
||||||
@@ -314,7 +314,7 @@ feature -- Execution
|
|||||||
end
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ deferred class
|
|||||||
inherit
|
inherit
|
||||||
REFACTORING_HELPER
|
REFACTORING_HELPER
|
||||||
|
|
||||||
|
CMS_ENCODERS
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
is_enabled: BOOLEAN
|
is_enabled: BOOLEAN
|
||||||
@@ -193,6 +195,6 @@ invariant
|
|||||||
version_set: not version.is_whitespace
|
version_set: not version.is_whitespace
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ deferred class
|
|||||||
inherit
|
inherit
|
||||||
WSF_HANDLER
|
WSF_HANDLER
|
||||||
|
|
||||||
CMS_REQUEST_UTIL
|
CMS_API_ACCESS
|
||||||
|
|
||||||
|
CMS_ENCODERS
|
||||||
|
|
||||||
REFACTORING_HELPER
|
REFACTORING_HELPER
|
||||||
|
|
||||||
@@ -93,4 +95,7 @@ feature -- Response helpers
|
|||||||
r.execute
|
r.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
|
note
|
||||||
|
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
note
|
|
||||||
description: "Set of helper features related to CMS Request needs."
|
|
||||||
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
|
|
||||||
revision: "$Revision: 96616 $"
|
|
||||||
|
|
||||||
deferred class
|
|
||||||
CMS_REQUEST_UTIL
|
|
||||||
|
|
||||||
inherit
|
|
||||||
CMS_ENCODERS
|
|
||||||
|
|
||||||
REFACTORING_HELPER
|
|
||||||
|
|
||||||
feature -- User
|
|
||||||
|
|
||||||
current_user_name (req: WSF_REQUEST): detachable READABLE_STRING_32
|
|
||||||
-- Current user name or Void in case of Guest users.
|
|
||||||
note
|
|
||||||
EIS: "src=eiffel:?class=AUTHENTICATION_FILTER&feature=execute"
|
|
||||||
do
|
|
||||||
if attached {CMS_USER} current_user (req) as l_user then
|
|
||||||
Result := l_user.name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
current_user (req: WSF_REQUEST): detachable CMS_USER
|
|
||||||
-- Current user or Void in case of Guest user.
|
|
||||||
-- note: if a CMS_RESPONSE is available, always prefer {CMS_RESPONSE}.user if relevant.
|
|
||||||
note
|
|
||||||
EIS: "eiffel:?class=AUTHENTICATION_FILTER&feature=execute"
|
|
||||||
do
|
|
||||||
if attached {CMS_USER} req.execution_variable (current_user_execution_variable_name) as l_user then
|
|
||||||
Result := l_user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Change
|
|
||||||
|
|
||||||
set_current_user (req: WSF_REQUEST; a_user: detachable CMS_USER)
|
|
||||||
-- Set `a_user' as `current_user'.
|
|
||||||
do
|
|
||||||
if a_user = Void then
|
|
||||||
req.unset_execution_variable (current_user_execution_variable_name)
|
|
||||||
else
|
|
||||||
req.set_execution_variable (current_user_execution_variable_name, a_user)
|
|
||||||
end
|
|
||||||
ensure
|
|
||||||
user_set: current_user (req) ~ a_user
|
|
||||||
end
|
|
||||||
|
|
||||||
unset_current_user (req: WSF_REQUEST)
|
|
||||||
-- Unset current user.
|
|
||||||
do
|
|
||||||
req.unset_execution_variable (current_user_execution_variable_name)
|
|
||||||
ensure
|
|
||||||
user_unset: current_user (req) = Void
|
|
||||||
end
|
|
||||||
|
|
||||||
feature {NONE} -- Implementation: current user
|
|
||||||
|
|
||||||
current_user_execution_variable_name: STRING = "_cms_active_user_"
|
|
||||||
-- Execution variable name used to keep current user data.
|
|
||||||
|
|
||||||
feature -- Media Type
|
|
||||||
|
|
||||||
current_media_type (req: WSF_REQUEST): detachable READABLE_STRING_32
|
|
||||||
-- Current media type or Void if it's not acceptable.
|
|
||||||
do
|
|
||||||
if attached {STRING} req.execution_variable ("media_type") as l_type then
|
|
||||||
Result := l_type
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
note
|
|
||||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
|
||||||
end
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
note
|
note
|
||||||
description: "Summary description for {CMS_URL_UTILITIES}."
|
description: "Collection of helper routines to manipulate URL for CMS."
|
||||||
author: ""
|
|
||||||
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
|
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
|
||||||
revision: "$Revision: 96616 $"
|
revision: "$Revision: 96616 $"
|
||||||
|
|
||||||
@@ -8,7 +7,7 @@ deferred class
|
|||||||
CMS_URL_UTILITIES
|
CMS_URL_UTILITIES
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
CMS_REQUEST_UTIL
|
CMS_ENCODERS
|
||||||
|
|
||||||
feature -- Core
|
feature -- Core
|
||||||
|
|
||||||
@@ -43,12 +42,16 @@ feature -- Core
|
|||||||
feature -- Link
|
feature -- Link
|
||||||
|
|
||||||
link (a_text: detachable READABLE_STRING_GENERAL; a_path: READABLE_STRING_8; opts: detachable CMS_API_OPTIONS): STRING
|
link (a_text: detachable READABLE_STRING_GENERAL; a_path: READABLE_STRING_8; opts: detachable CMS_API_OPTIONS): STRING
|
||||||
|
-- HTML link with title `a_text' and href `a_path'.
|
||||||
|
-- `opts' is used for additional settings.
|
||||||
do
|
do
|
||||||
create Result.make (32)
|
create Result.make (32)
|
||||||
append_link_to_html (a_text, a_path, opts, Result)
|
append_link_to_html (a_text, a_path, opts, Result)
|
||||||
end
|
end
|
||||||
|
|
||||||
link_with_raw_text (a_raw_text: detachable READABLE_STRING_8; a_path: READABLE_STRING_8; opts: detachable CMS_API_OPTIONS): STRING
|
link_with_raw_text (a_raw_text: detachable READABLE_STRING_8; a_path: READABLE_STRING_8; opts: detachable CMS_API_OPTIONS): STRING
|
||||||
|
-- HTML link with title the html code `a_raw_text' and href `a_path'.
|
||||||
|
-- `opts' is used for additional settings.
|
||||||
do
|
do
|
||||||
create Result.make (32)
|
create Result.make (32)
|
||||||
append_link_with_raw_text_to_html (a_raw_text, a_path, opts, Result)
|
append_link_with_raw_text_to_html (a_raw_text, a_path, opts, Result)
|
||||||
@@ -180,6 +183,7 @@ feature -- Url
|
|||||||
|
|
||||||
checked_url (a_url: READABLE_STRING_8): READABLE_STRING_8
|
checked_url (a_url: READABLE_STRING_8): READABLE_STRING_8
|
||||||
do
|
do
|
||||||
|
-- FIXME: implement a way to check if `a_url' is safe, and does not reveal security issue.
|
||||||
Result := a_url
|
Result := a_url
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -189,6 +193,6 @@ feature -- Url
|
|||||||
end
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -116,6 +116,9 @@ feature -- Access: metadata
|
|||||||
redirection: detachable READABLE_STRING_8
|
redirection: detachable READABLE_STRING_8
|
||||||
-- Location for eventual redirection.
|
-- Location for eventual redirection.
|
||||||
|
|
||||||
|
redirection_delay: NATURAL
|
||||||
|
-- Optional redirection delay in seconds.
|
||||||
|
|
||||||
feature -- Access: query
|
feature -- Access: query
|
||||||
|
|
||||||
location: STRING_8
|
location: STRING_8
|
||||||
@@ -196,8 +199,23 @@ feature -- User access
|
|||||||
end
|
end
|
||||||
|
|
||||||
user: detachable CMS_USER
|
user: detachable CMS_USER
|
||||||
|
-- Active user if authenticated.
|
||||||
do
|
do
|
||||||
Result := current_user (request)
|
Result := api.user
|
||||||
|
end
|
||||||
|
|
||||||
|
set_user (u: CMS_USER)
|
||||||
|
-- Set active user to `u'.
|
||||||
|
require
|
||||||
|
attached_u: u /= Void
|
||||||
|
do
|
||||||
|
api.set_user (u)
|
||||||
|
end
|
||||||
|
|
||||||
|
unset_user
|
||||||
|
-- Unset active user.
|
||||||
|
do
|
||||||
|
api.unset_user
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Permission
|
feature -- Permission
|
||||||
@@ -356,6 +374,11 @@ feature -- Element change
|
|||||||
redirection := a_location
|
redirection := a_location
|
||||||
end
|
end
|
||||||
|
|
||||||
|
set_redirection_delay (nb_secs: NATURAL)
|
||||||
|
do
|
||||||
|
redirection_delay := nb_secs
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Logging
|
feature -- Logging
|
||||||
|
|
||||||
log (a_category: READABLE_STRING_8; a_message: READABLE_STRING_8; a_level: INTEGER; a_link: detachable CMS_LINK)
|
log (a_category: READABLE_STRING_8; a_message: READABLE_STRING_8; a_level: INTEGER; a_link: detachable CMS_LINK)
|
||||||
@@ -1212,8 +1235,8 @@ feature -- Generation
|
|||||||
page.register_variable (absolute_url ("", Void), "site_url")
|
page.register_variable (absolute_url ("", Void), "site_url")
|
||||||
page.register_variable (absolute_url ("", Void), "host") -- Same as `site_url'.
|
page.register_variable (absolute_url ("", Void), "host") -- Same as `site_url'.
|
||||||
page.register_variable (request.is_https, "is_https")
|
page.register_variable (request.is_https, "is_https")
|
||||||
if attached current_user_name (request) as l_user then
|
if attached user as l_user then
|
||||||
page.register_variable (l_user, "user")
|
page.register_variable (l_user.name, "user")
|
||||||
end
|
end
|
||||||
page.register_variable (title, "site_title")
|
page.register_variable (title, "site_title")
|
||||||
page.set_is_front (is_front)
|
page.set_is_front (is_front)
|
||||||
@@ -1326,16 +1349,40 @@ feature -- Helpers: cms link
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
user_html_link (u: CMS_USER): like link
|
feature -- Helpers: html links
|
||||||
|
|
||||||
|
user_html_link (u: CMS_USER): STRING
|
||||||
do
|
do
|
||||||
Result := link (u.name, "user/" + u.id.out, Void)
|
Result := link (u.name, "user/" + u.id.out, Void)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Helpers: URLs
|
||||||
|
|
||||||
|
location_absolute_url (a_location: READABLE_STRING_8; opts: detachable CMS_API_OPTIONS): STRING
|
||||||
|
-- Absolute URL for `a_location'.
|
||||||
|
--| Options `opts' could be
|
||||||
|
--| - absolute: True|False => return absolute url
|
||||||
|
--| - query: string => append "?query"
|
||||||
|
--| - fragment: string => append "#fragment"
|
||||||
|
do
|
||||||
|
Result := absolute_url (a_location, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
location_url (a_location: READABLE_STRING_8; opts: detachable CMS_API_OPTIONS): STRING
|
||||||
|
-- URL for `a_location'.
|
||||||
|
--| Options `opts' could be
|
||||||
|
--| - absolute: True|False => return absolute url
|
||||||
|
--| - query: string => append "?query"
|
||||||
|
--| - fragment: string => append "#fragment"
|
||||||
|
do
|
||||||
|
Result := url (a_location, opts)
|
||||||
|
end
|
||||||
|
|
||||||
user_url (u: CMS_USER): like url
|
user_url (u: CMS_USER): like url
|
||||||
require
|
require
|
||||||
u_with_id: u.has_id
|
u_with_id: u.has_id
|
||||||
do
|
do
|
||||||
Result := url ("user/" + u.id.out, Void)
|
Result := location_url ("user/" + u.id.out, Void)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Execution
|
feature -- Execution
|
||||||
@@ -1363,8 +1410,22 @@ feature {NONE} -- Execution
|
|||||||
page: CMS_HTML_PAGE_RESPONSE
|
page: CMS_HTML_PAGE_RESPONSE
|
||||||
utf: UTF_CONVERTER
|
utf: UTF_CONVERTER
|
||||||
h: HTTP_HEADER
|
h: HTTP_HEADER
|
||||||
l_new_location: READABLE_STRING_8
|
l_new_location: detachable READABLE_STRING_8
|
||||||
|
l_redirection_delay: like redirection_delay
|
||||||
do
|
do
|
||||||
|
if attached redirection as l_location then
|
||||||
|
-- FIXME: find out if this is safe or not.
|
||||||
|
if l_location.has_substring ("://") then
|
||||||
|
l_new_location := l_location
|
||||||
|
else
|
||||||
|
l_new_location := location_absolute_url (l_location, Void)
|
||||||
|
end
|
||||||
|
l_redirection_delay := redirection_delay
|
||||||
|
if l_redirection_delay > 0 then
|
||||||
|
add_additional_head_line ("<meta http-equiv=%"refresh%" content=%"" + l_redirection_delay.out + ";url=" + l_new_location + "%" />", True)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if attached {READABLE_STRING_GENERAL} values.item ("optional_content_type") as l_type then
|
if attached {READABLE_STRING_GENERAL} values.item ("optional_content_type") as l_type then
|
||||||
create cms_page.make_typed (utf.utf_32_string_to_utf_8_string_8 (l_type))
|
create cms_page.make_typed (utf.utf_32_string_to_utf_8_string_8 (l_type))
|
||||||
else
|
else
|
||||||
@@ -1376,14 +1437,7 @@ feature {NONE} -- Execution
|
|||||||
h := page.header
|
h := page.header
|
||||||
h.put_content_length (page.html.count)
|
h.put_content_length (page.html.count)
|
||||||
h.put_current_date
|
h.put_current_date
|
||||||
if attached redirection as l_location then
|
if l_new_location /= Void and l_redirection_delay = 0 then
|
||||||
-- FIXME: find out if this is safe or not.
|
|
||||||
if l_location.has_substring ("://") then
|
|
||||||
l_new_location := l_location
|
|
||||||
else
|
|
||||||
l_new_location := absolute_url (l_location, Void)
|
|
||||||
end
|
|
||||||
-- h.put_location (l_new_location)
|
|
||||||
response.redirect_now (l_new_location)
|
response.redirect_now (l_new_location)
|
||||||
else
|
else
|
||||||
h.put_header_object (header)
|
h.put_header_object (header)
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ feature -- Execution
|
|||||||
do
|
do
|
||||||
set_title ("Not Found")
|
set_title ("Not Found")
|
||||||
set_page_title ("Not Found")
|
set_page_title ("Not Found")
|
||||||
set_main_content ("<em>The requested page could not be found.</em>")
|
set_main_content ("<em>The requested page %"" + request.request_uri + "%"could not be found.</em>")
|
||||||
end
|
end
|
||||||
note
|
note
|
||||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ inherit
|
|||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access: user
|
||||||
|
|
||||||
user_by_id (a_id: like {CMS_USER}.id): detachable CMS_USER
|
user_by_id (a_id: like {CMS_USER}.id): detachable CMS_USER
|
||||||
-- User by id `a_id', if any.
|
-- User by id `a_id', if any.
|
||||||
@@ -58,6 +58,44 @@ feature -- Access
|
|||||||
Result := storage.recent_users (params.offset.to_integer_32, params.size.to_integer_32)
|
Result := storage.recent_users (params.offset.to_integer_32, params.size.to_integer_32)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Change User
|
||||||
|
|
||||||
|
new_user (a_user: CMS_USER)
|
||||||
|
-- Add a new user `a_user'.
|
||||||
|
require
|
||||||
|
no_id: not a_user.has_id
|
||||||
|
no_hashed_password: a_user.hashed_password = Void
|
||||||
|
do
|
||||||
|
reset_error
|
||||||
|
if
|
||||||
|
attached a_user.email as l_email
|
||||||
|
then
|
||||||
|
storage.new_user (a_user)
|
||||||
|
error_handler.append (storage.error_handler)
|
||||||
|
else
|
||||||
|
error_handler.add_custom_error (0, "bad new user request", "Missing password or email to create new user!")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
update_user (a_user: CMS_USER)
|
||||||
|
-- Update user `a_user'.
|
||||||
|
require
|
||||||
|
has_id: a_user.has_id
|
||||||
|
do
|
||||||
|
reset_error
|
||||||
|
storage.update_user (a_user)
|
||||||
|
error_handler.append (storage.error_handler)
|
||||||
|
end
|
||||||
|
|
||||||
|
delete_user (a_user: CMS_USER)
|
||||||
|
-- Delete user `a_user'.
|
||||||
|
require
|
||||||
|
has_id: a_user.has_id
|
||||||
|
do
|
||||||
|
reset_error
|
||||||
|
storage.delete_user (a_user)
|
||||||
|
error_handler.append (storage.error_handler)
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
@@ -241,45 +279,6 @@ feature -- Change User role
|
|||||||
error_handler.append (storage.error_handler)
|
error_handler.append (storage.error_handler)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Change User
|
|
||||||
|
|
||||||
new_user (a_user: CMS_USER)
|
|
||||||
-- Add a new user `a_user'.
|
|
||||||
require
|
|
||||||
no_id: not a_user.has_id
|
|
||||||
no_hashed_password: a_user.hashed_password = Void
|
|
||||||
do
|
|
||||||
reset_error
|
|
||||||
if
|
|
||||||
attached a_user.email as l_email
|
|
||||||
then
|
|
||||||
storage.new_user (a_user)
|
|
||||||
error_handler.append (storage.error_handler)
|
|
||||||
else
|
|
||||||
error_handler.add_custom_error (0, "bad new user request", "Missing password or email to create new user!")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
update_user (a_user: CMS_USER)
|
|
||||||
-- Update user `a_user'.
|
|
||||||
require
|
|
||||||
has_id: a_user.has_id
|
|
||||||
do
|
|
||||||
reset_error
|
|
||||||
storage.update_user (a_user)
|
|
||||||
error_handler.append (storage.error_handler)
|
|
||||||
end
|
|
||||||
|
|
||||||
delete_user (a_user: CMS_USER)
|
|
||||||
-- Delete user `a_user'.
|
|
||||||
require
|
|
||||||
has_id: a_user.has_id
|
|
||||||
do
|
|
||||||
reset_error
|
|
||||||
storage.delete_user (a_user)
|
|
||||||
error_handler.append (storage.error_handler)
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- User Activation
|
feature -- User Activation
|
||||||
|
|
||||||
new_activation (a_token: READABLE_STRING_32; a_id: INTEGER_64)
|
new_activation (a_token: READABLE_STRING_32; a_id: INTEGER_64)
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ CREATE TABLE `users_password_recovery` (
|
|||||||
CONSTRAINT `token` UNIQUE (`token`)
|
CONSTRAINT `token` UNIQUE (`token`)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE `auth_temp_users` (
|
CREATE TABLE `auth_temp_users` (
|
||||||
`uid` INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
`uid` INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
||||||
`name` VARCHAR(100) NOT NULL,
|
`name` VARCHAR(100) NOT NULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user