'use strict';

var _ = require('lodash');
var mail = require('../mail');
var utils = require('../utils');
var conf = require('../conf');

exports.getShibAttrs = function(req, _sv) {
    var v = _.mapValues(conf.shibboleth.header_map, function (headerName) {
	return req.header(headerName);
    });
    console.log("action getShibAttrs:", v);
    return Promise.resolve({ v: v });
};

exports.createCompte = function(req, sv) {
    var v = sv.v;
    console.log("action createCompte:", v);
    return utils.popen(JSON.stringify(v), 'createCompte', []).then(function (data) {

	if (v.supannMailPerso) {
	    mail.sendWithTemplate('warn_user_account_created.html', { to: v.supannMailPerso, v: v });
	}
	return { v: v };
    });
};

exports.sendValidationEmail = function(req, sv) {
    var v = sv.v;
    console.log("action sendValidationEmail");
    mail.sendWithTemplate('validation.html', { conf: conf, to: v.supannMailPerso, id: sv.id, v: v });
    return Promise.resolve({ v: v });
};

@@ -95,24 +95,69 @@
 ../utils');%0A
+var search_ldap = require('../search_ldap');%0A
 var conf = r
@@ -759,32 +759,250 @@
  %7D;%0A    %7D);%0A%7D;%0A%0A
+exports.genLogin = function (req, sv) %7B%0A    return search_ldap.genLogin(sv.v.sn, sv.v.givenName).then(function (login) %7B%0A%09var v = _.assign(%7B uid: login %7D, sv.v);%0A%09return %7B v: v, response: %7Blogin: login%7D %7D;%0A    %7D);%0A%7D;%0A%0A
 exports.sendVali

add action genLogin: adds uid in "v" + respond the generated login to client-side