Commit 9bd24b07 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

No commit message

No commit message
parent b5c5baf7
......@@ -497,16 +497,17 @@ class tx_nG6_eid {
}
$c_user_id = tx_nG6_db::get_user_id_by_username($user_name);
$user = tx_nG6_db::select_user_by_username($user_name);
// if user not exists in DB
if(!isset($c_user_id)){
if(!isset($user)){
$create_user_email = trim(t3lib_div::_GP('create_user_email'));
$create_user_title = trim(t3lib_div::_GP('create_user_title'));
tx_nG6_db::create_new_user($user_name, $first_name, $last_name, $email, $password, $cruser_id, $group_id, $pid);
$res_code = tx_nG6_db::create_new_user($user_name, $first_name, $last_name, $email, $password, $cruser_id, $group_id, $pid);
if ($res_code == 0) {
// find the new user id
$new_id = tx_nG6_db::get_user_id_by_username($user_name);
......@@ -524,10 +525,18 @@ class tx_nG6_eid {
$message = implode("\n", $msg_table);
mail($email, $create_user_title, $message, "From: <".$from_email.">");
}
print '2';
print '2'; // ok
} else if ($res_code == 1) {
print '4'; // username exists
} else if ($res_code == 2) {
print '5'; // email exists
}
// user exists in DB
}else{
} else if ($user["username"] != $user_name || $user["email"] != $email || $user["first_name"] != $first_name || $user["last_name"] != $last_name) {
// there is difference between information provided and the user account
print '3';
} else {
// can user access to the project ?
if(tx_nG6_db::get_user_right_on_project($c_user_id, $project_id) == -1){
......
......@@ -1527,10 +1527,10 @@ class tx_nG6_db {
return $res_tab;
}
function get_user_id_by_username($username){
$uid = null;
function select_user_by_username($username){
$res_tab = null;
$queryParts = Array(
'SELECT' => 'fe_users.uid',
'SELECT' => 'fe_users.uid, fe_users.username, fe_users.first_name, fe_users.last_name, fe_users.email',
'FROM' => 'fe_users',
'WHERE' => 'fe_users.username LIKE "'.$username.'" ',
'GROUPBY' => '',
......@@ -1538,19 +1538,49 @@ class tx_nG6_db {
'LIMIT' => '',
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$res_tab = array(
'uid' => $res_row['uid'],
'username' => $res_row['username'],
'first_name' => $res_row['first_name'],
'last_name' => $res_row['last_name'],
'email' => $res_row['email'],
);
}
return $res_tab;
}
function user_field_exist ($field, $value){
$queryParts = Array(
'SELECT' => 'fe_users.uid',
'FROM' => 'fe_users',
'WHERE' => 'fe_users.' . $field . ' LIKE "'.$value.'" ',
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => '',
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$uid = null;
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$uid = $res_row['uid'];
}
return $uid;
return isset($uid);
}
/**
* Create a new user in the DB.
*
* @param array $user_datas the user array
* @return 0: ok, 1: username exists, 2: email exists
*/
function create_new_user($user_name, $first_name, $last_name, $email, $password, $cruser_id, $group_id, $pid){
// first check if username or email are unique
if (user_field_exist("username", $user_name)) {
return 1;
} else if (user_field_exist("email", $email)) {
return 2;
} else {
// Create new user
$user_datas = array(
'username' => $user_name,
......@@ -1565,6 +1595,8 @@ class tx_nG6_db {
'crdate' => time()
);
$GLOBALS['TYPO3_DB']->exec_INSERTquery('fe_users', $user_datas);
return 0;
}
}
......
......@@ -27,6 +27,8 @@
<label index="manage_users">Users</label>
<label index="delete_user_btn">Delete</label>
<label index="add_user_btn">Add</label>
<label index="error_dialog_email_exist">Cannot create this user account, ###USERNAME### already exists</label>
<label index="error_dialog_username_exist">Cannot create this user account, ###EMAIL### already exists</label>
<label index="create_user_title">[NG6] Account creation</label>
<label index="send_an_email">Send an email to the user</label>
<label index="create_user_email">Dear ###USER_FIRST_NAME### ###USER_LAST_NAME###,\nPlease find bellow your login/password required to log into the NG6 system (###PROJECT_LINK###): \n - login: ###USER_LOGIN###\n - password: ###USER_PASSWORD###\nThe NG6 team\nPS: this is an automatic e-mail message generated by the NG6 system. Please DO NOT RESPOND to this e-mail because the mail box is unattended.</label>
......@@ -460,6 +462,8 @@
<label index="manage_users">Utilisateurs</label>
<label index="delete_user_btn">Supprimer</label>
<label index="add_user_btn">Ajouter</label>
<label index="error_dialog_email_exist">Impossible de créer ce compte utilisateur, ###USERNAME### existe déjà</label>
<label index="error_dialog_username_exist">Impossible de créer ce compte utilisateur, ###EMAIL### existe déjà</label>
<label index="create_user_title">[NG6] Création de compte</label>
<label index="send_an_email">Envoyer un email à l'utilisateur</label>
<label index="create_user_email">###USER_FIRST_NAME### ###USER_LAST_NAME###,\nVeuillez trouver ci-joint votre login/mot de passe nécessaire afin de se loguer à NG6 (###PROJECT_LINK###): \n - login: ###USER_LOGIN###\n - mot de passe: ###USER_PASSWORD###\nL'équipe NG6\nPS: ceci est un mail généré automatiquement par NG6. Veuillez ne repondez pas à cet e-mail.</label>
......
......@@ -49,7 +49,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<input type="hidden" id="error_dialog_empty_password" value="{$llang.error_dialog_empty_password}" />
<input type="hidden" id="user_login" value="{$llang.user_login}" />
<input type="hidden" id="user_login" value="{$llang.user_login}" />
<input type="hidden" id="error_dialog_username_exist" value="{$llang.error_dialog_username_exist}" />
<input type="hidden" id="error_dialog_email_exist" value="{$llang.error_dialog_email_exist}" />
<input type="hidden" id="add_user_email" value="{$llang.add_user_email}" />
<input type="hidden" id="add_user_title" value="{$llang.add_user_title}" />
<input type="hidden" id="create_user_email" value="{$llang.create_user_email}" />
......
......@@ -1185,12 +1185,25 @@ $(function () {
url: val_url,
success: function(val, status, xhr) {
if(val == '1'){
if (val == '1') {
// user has already access to this project
var res_access = '<tr><td id="error_td" colspan="2" class="new_user_error">';
res_access += $("#error_dialog_already_access").val().replace('###USERNAME###', " '"+$("#user_name_val").val()+"'");
res_access += '</td></tr>';
$("#new_member tbody").append(res_access);
hasError = true;
} else if (val == '4') {
// username exists in database cannot create
var res_access = '<tr><td id="error_td" colspan="2" class="new_user_error">';
res_access += $("#error_dialog_username_exist").val().replace('###USERNAME###', " '"+$("#user_name_val").val()+"'");
res_access += '</td></tr>';
$("#new_member tbody").append(res_access);
hasError = true;
} else if (val == '5') {
// email exists in database cannot create
var res_access = '<tr><td id="error_td" colspan="2" class="new_user_error">';
res_access += $("#error_dialog_email_exist").val().replace('###EMAIL###', " '"+$("#user_email_val").val()+"'");
res_access += '</td></tr>';
$("#new_member tbody").append(res_access);
hasError = true;
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment