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

No commit message

No commit message
parent b5c5baf7
...@@ -497,37 +497,46 @@ class tx_nG6_eid { ...@@ -497,37 +497,46 @@ 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 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_email = trim(t3lib_div::_GP('create_user_email'));
$create_user_title = trim(t3lib_div::_GP('create_user_title')); $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);
// find the new user id if ($res_code == 0) {
$new_id = tx_nG6_db::get_user_id_by_username($user_name); // find the new user id
$new_id = tx_nG6_db::get_user_id_by_username($user_name);
// authorize new access
tx_nG6_db::add_access_to_project($new_id, $project_id, $right_id); // authorize new access
tx_nG6_db::add_access_to_project($new_id, $project_id, $right_id);
if ($send_an_email) {
// send an email to the new user if ($send_an_email) {
$message = str_replace("###USER_FIRST_NAME###", $first_name, $create_user_email); // send an email to the new user
$message = str_replace("###USER_LAST_NAME###", $last_name, $message); $message = str_replace("###USER_FIRST_NAME###", $first_name, $create_user_email);
$message = str_replace("###USER_LOGIN###", $user_name, $message); $message = str_replace("###USER_LAST_NAME###", $last_name, $message);
$message = str_replace("###USER_PASSWORD###", $clearpassword, $message); $message = str_replace("###USER_LOGIN###", $user_name, $message);
$message = str_replace("###PROJECT_LINK###", $project_url, $message); $message = str_replace("###USER_PASSWORD###", $clearpassword, $message);
$msg_table = explode('\n', $message); $message = str_replace("###PROJECT_LINK###", $project_url, $message);
$message = implode("\n", $msg_table); $msg_table = explode('\n', $message);
mail($email, $create_user_title, $message, "From: <".$from_email.">"); $message = implode("\n", $msg_table);
mail($email, $create_user_title, $message, "From: <".$from_email.">");
}
print '2'; // ok
} else if ($res_code == 1) {
print '4'; // username exists
} else if ($res_code == 2) {
print '5'; // email exists
} }
print '2';
// user exists in DB // 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 ? // can user access to the project ?
if(tx_nG6_db::get_user_right_on_project($c_user_id, $project_id) == -1){ if(tx_nG6_db::get_user_right_on_project($c_user_id, $project_id) == -1){
......
...@@ -1527,10 +1527,10 @@ class tx_nG6_db { ...@@ -1527,10 +1527,10 @@ class tx_nG6_db {
return $res_tab; return $res_tab;
} }
function get_user_id_by_username($username){ function select_user_by_username($username){
$uid = null; $res_tab = null;
$queryParts = Array( $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', 'FROM' => 'fe_users',
'WHERE' => 'fe_users.username LIKE "'.$username.'" ', 'WHERE' => 'fe_users.username LIKE "'.$username.'" ',
'GROUPBY' => '', 'GROUPBY' => '',
...@@ -1538,33 +1538,65 @@ class tx_nG6_db { ...@@ -1538,33 +1538,65 @@ class tx_nG6_db {
'LIMIT' => '', 'LIMIT' => '',
); );
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts); $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)) { while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$uid = $res_row['uid']; $uid = $res_row['uid'];
} }
return $uid; return isset($uid);
} }
/** /**
* Create a new user in the DB. * Create a new user in the DB.
* *
* @param array $user_datas the user array * @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){ function create_new_user($user_name, $first_name, $last_name, $email, $password, $cruser_id, $group_id, $pid){
// Create new user // first check if username or email are unique
$user_datas = array( if (user_field_exist("username", $user_name)) {
'username' => $user_name, return 1;
'pid' => $pid, } else if (user_field_exist("email", $email)) {
'first_name' => $first_name, return 2;
'last_name' => $last_name, } else {
'email' => $email, // Create new user
'password' => $password, $user_datas = array(
'cruser_id' => $cruser_id, 'username' => $user_name,
'usergroup' => $group_id, 'pid' => $pid,
'tstamp' => time(), 'first_name' => $first_name,
'crdate' => time() 'last_name' => $last_name,
); 'email' => $email,
$GLOBALS['TYPO3_DB']->exec_INSERTquery('fe_users', $user_datas); 'password' => $password,
'cruser_id' => $cruser_id,
'usergroup' => $group_id,
'tstamp' => time(),
'crdate' => time()
);
$GLOBALS['TYPO3_DB']->exec_INSERTquery('fe_users', $user_datas);
return 0;
}
} }
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
<label index="manage_users">Users</label> <label index="manage_users">Users</label>
<label index="delete_user_btn">Delete</label> <label index="delete_user_btn">Delete</label>
<label index="add_user_btn">Add</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="create_user_title">[NG6] Account creation</label>
<label index="send_an_email">Send an email to the user</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> <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 @@ ...@@ -460,6 +462,8 @@
<label index="manage_users">Utilisateurs</label> <label index="manage_users">Utilisateurs</label>
<label index="delete_user_btn">Supprimer</label> <label index="delete_user_btn">Supprimer</label>
<label index="add_user_btn">Ajouter</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="create_user_title">[NG6] Création de compte</label>
<label index="send_an_email">Envoyer un email à l'utilisateur</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> <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/>. ...@@ -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="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="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_email" value="{$llang.add_user_email}" />
<input type="hidden" id="add_user_title" value="{$llang.add_user_title}" /> <input type="hidden" id="add_user_title" value="{$llang.add_user_title}" />
<input type="hidden" id="create_user_email" value="{$llang.create_user_email}" /> <input type="hidden" id="create_user_email" value="{$llang.create_user_email}" />
......
...@@ -1185,12 +1185,25 @@ $(function () { ...@@ -1185,12 +1185,25 @@ $(function () {
url: val_url, url: val_url,
success: function(val, status, xhr) { success: function(val, status, xhr) {
if(val == '1'){ if (val == '1') {
// user has already access to this project // user has already access to this project
var res_access = '<tr><td id="error_td" colspan="2" class="new_user_error">'; 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 += $("#error_dialog_already_access").val().replace('###USERNAME###', " '"+$("#user_name_val").val()+"'");
res_access += '</td></tr>'; 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); $("#new_member tbody").append(res_access);
hasError = true; hasError = true;
} else { } 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