Skip to content

Commit

Permalink
Merge pull request #251 from Geoportail-Luxembourg/lux_authentication
Browse files Browse the repository at this point in the history
Add authentication and login panel
  • Loading branch information
rmichaelis committed Feb 10, 2015
2 parents e11ec8d + baf280e commit 08f7b43
Show file tree
Hide file tree
Showing 15 changed files with 534 additions and 14 deletions.
2 changes: 2 additions & 0 deletions development.ini.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ mako.directories = geoportailv3:templates
app.cfg = %(here)s/.build/config.yaml
elastic.servers = ${search_host}
elastic.index = ${search_index}
authtkt_secret = ${authtkt_secret}
authtkt_cookie_name = ${authtkt_cookie_name}

# pyramid_closure configuration
pyramid_closure.roots =
Expand Down
2 changes: 2 additions & 0 deletions geoportailv3.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ PRINT3 = FALSE

DISABLE_BUILD_RULES = test-packages test-packages-ngeo

CONFIG_VARS += ldap

include CONST_Makefile

DEV_REQUIREMENTS += git+https://github.com/transifex/transifex-client.git@fix-proxies#egg=transifex-client-proxies
Expand Down
28 changes: 27 additions & 1 deletion geoportailv3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
from pyramid.config import Configurator
from pyramid.settings import asbool
from c2cgeoportal import locale_negotiator, \
add_interface, INTERFACE_TYPE_NGEO_CATALOGUE
add_interface, INTERFACE_TYPE_NGEO_CATALOGUE, \
set_user_validator
from c2cgeoportal.resources import FAModels
from c2cgeoportal.lib.authentication import create_authentication
from geoportailv3.resources import Root
from geoportailv3.views.authentication import ldap_user_validator, \
get_user_from_request
import ldap


def main(global_config, **settings):
Expand All @@ -22,6 +26,27 @@ def main(global_config, **settings):

config.include('c2cgeoportal')
config.include('pyramid_closure')
config.include('pyramid_ldap')

"""Config the ldap connection.
"""
ldap_settings = config.get_settings()['ldap']

config.ldap_setup(
ldap_settings['url'],
ldap_settings['bind'],
ldap_settings['passwd'],
)

config.ldap_set_login_query(
ldap_settings['base_dn'],
filter_tmpl='(login=%(login)s)',
scope=ldap.SCOPE_SUBTREE,
)

config.set_request_property(get_user_from_request, name='user', reify=True)

set_user_validator(config, ldap_user_validator)

config.add_translation_dirs('geoportailv3:locale/')

Expand Down Expand Up @@ -50,5 +75,6 @@ def main(global_config, **settings):
config.add_static_view('node_modules', settings.get('node_modules_path'))
config.add_static_view('closure', settings.get('closure_library_path'))

config.add_route('getuserinfo', '/getuserinfo')
config.add_route('wms', '/wms')
return config.make_wsgi_app()
3 changes: 2 additions & 1 deletion geoportailv3/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
goog.provide('app_main');

goog.require('app.MainController');
goog.require('app.UserController');
goog.require('app.backgroundlayerDirective');
goog.require('app.catalogDirective');
goog.require('app.layermanagerDirective');
goog.require('app.layerinfoDirective');
goog.require('app.layermanagerDirective');
goog.require('app.scalelineDirective');
goog.require('ngeo.btngroupDirective');
goog.require('ngeo.resizemapDirective');
9 changes: 7 additions & 2 deletions geoportailv3/static/js/maincontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ app.MainController = function($scope, gettextCatalog, langUrlTemplate,
*/
this['shareOpen'] = false;

/**
* @type {Boolean}
*/
this['userOpen'] = false;

/**
* @type {Array}
*/
Expand All @@ -113,7 +118,8 @@ app.MainController.prototype.setMap_ = function() {
this['map'] = new ol.Map({
controls: [
new ol.control.Zoom({zoomInLabel: '\ue031', zoomOutLabel: '\ue025'}),
new ol.control.ZoomToExtent({label: '\ue01b', extent: this.defaultExtent_}),
new ol.control.ZoomToExtent({label: '\ue01b',
extent: this.defaultExtent_}),
new ol.control.FullScreen({label: '\ue01c', labelActive: '\ue02b'})
],
view: new ol.View({
Expand Down Expand Up @@ -186,5 +192,4 @@ app.MainController.prototype.showTab = function(selector) {
$(selector).tab('show');
};


app.module.controller('MainController', app.MainController);
191 changes: 191 additions & 0 deletions geoportailv3/static/js/usercontroller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/**
* @fileoverview This file defines the controller class for the application's
* user controller.
*
*/
goog.provide('app.UserController');

goog.require('app');



/**
* @param {angular.$http} $http Htpp.
* @constructor
* @export
* @ngInject
*/
app.UserController = function($http) {

/**
* @type {object}
* @private
*/
this['credentials'] = {
'login' : null,
'password' : null
};

/**
* @type {angular.$http}
* @private
*/
this['http_'] = $http;

/**
* @type {string}
*/
this['login'] = null;


/**
* @type {string}
*/
this['email'] = null;


/**
* @type {string}
*/
this['role'] = null;

/**
* @type {number}
*/
this['role_id'] = 0;

/**
* @type {string}
*/
this['name'] = null;

/**
* @type {boolean}
*/
this['isError'] = false;

this.getUserInfo();
};


/**
* @param {Object} credentials Credentials.
* @export
*/
app.UserController.prototype.authenticate = function(credentials) {

var that = this;
this['http_']({
method: 'POST',
url: 'login',
data: $.param({
'login': credentials['login'],
'password': credentials['password']
}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data, status, headers, config) {

if (status == 200) {
that.getUserInfo();
that['isError'] = false;
}else {
that['isError'] = true;
}

}). error(function(data, status, headers, config) {
that['isError'] = true;
});
};


/**
* @export
*/
app.UserController.prototype.logout = function() {
var that = this;
this['http_']({
method: 'POST',
url: 'logout',
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data, status, headers, config) {
if (status == 200) {
that.getUserInfo();
that['isError'] = false;
}else {
that.getUserInfo();
that['isError'] = true;
}
}). error(function(data, status, headers, config) {
that.getUserInfo();
that['isError'] = true;
});
};


/**
* @export
*/
app.UserController.prototype.getUserInfo = function() {
var that = this;
this['http_']({
method: 'POST',
url: 'getuserinfo'
}).success(function(data, status, headers, config) {

if (status == 200) {
that.setUserInfo(
data['login'],
data['role'],
data['role_id'],
data['mail'],
data['sn']
);
}else {
that.setUserInfo(null, null, null, null, null);
}

}).error(function(data, status, headers, config) {
that.setUserInfo(null, null, null, null, null);
});
};


/**
* @return {boolean}
* @export
*/
app.UserController.prototype.isAuthenticated = function() {
if (this['login'] != null && this['login'].length > 0) {
return true;
}
return false;
};


/**
* @return {boolean}
* @export
*/
app.UserController.prototype.hasError = function() {
return this['isError'];
};


/**
* @param {?string} login Login.
* @param {?string} role Role.
* @param {?number} role_id Role id.
* @param {?string} mail Mail.
* @param {?string} name Name.
*/
app.UserController.prototype.setUserInfo = function(
login, role, role_id, mail, name) {
this['login'] = login;
this['role'] = role;
this['role_id'] = role_id;
this['mail'] = mail;
this['name'] = name;
};


app.module.controller('UserController', app.UserController);
11 changes: 8 additions & 3 deletions geoportailv3/static/less/icons.less
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ li.icon a {
}

&:after {
font-family: "geoportail-icons" !important;
font-family: "geoportail-icons" !important;
position: absolute;
top: 8px;
left: 0;
Expand All @@ -40,8 +40,8 @@ li.icon a {
top: 10px;
}
}

}

button.icon:after {
top: -10px;
}
Expand Down Expand Up @@ -80,13 +80,18 @@ button.icon.search:after,
.icon.share a:after {
content: '\e02a';
}
.icon.user a:after {
.icon.user > a:after {
content: '\e02d';
}
.icon.lang > a:after {
content: '\e012';
}

.icon.active > a:after {
content:'\e02b';
}


#catalog,
#mylayers {
.fa-info {
Expand Down
Loading

0 comments on commit 08f7b43

Please sign in to comment.