<commit_before><?php 

 /**
  *  YunoHost - Self-hosting for all
  *  Copyright (C) 2012  Kload <<EMAIL>>
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU Affero General Public License as
  *  published by the Free Software Foundation, either version 3 of the
  *  License, or (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU Affero General Public License for more details.
  *
  *  You should have received a copy of the GNU Affero General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  
/**
 * GET /user
 */
function user() {
  redirect_to('/user/list');
}

/**
 * GET /user/list
 */
function listUser() {
  global $ldap;

  // Fetch users
  $ldap->setSearchPath(array('ou' => 'users'));
  $ldap->setAttributesToFetch(array("mail", "uid", "cn", "dn"));
  $users = $ldap->findAll('(objectClass=inetOrgPerson)');

  // Fetch admin list
  $ldap->populateAdmin(array('cn' => 'admin'));
  $adminsDn = $ldap->getAdminMember();

  set('users', $users);
  set('adminsDn', $adminsDn);
  set('title', T_('List users'));        
  return render("listUser.html.php");
}

/**
 * GET /user/add
 */
function addUserForm () {
  global $ldap;
  $domains = $ldap->findAll('(objectClass=mailDomain)');
  set('domains', $domains);
  set('title', T_('Add user'));
  return render("addUserForm.html.php");
}

/**
 * POST /user/add
 */
function addUser () {
  global $ldap;

  $_SESSION['first-install'] = false;

  $ajax = isset($_POST['ajax']);

  $username = htmlspecialchars($_POST["username"]);
  $password = '{MD5}'.base64_encode(pack('H*',md5($_POST["password"])));
  $firstname = htmlspecialchars($_POST["firstname"]);
  $lastname = htmlspecialchars($_POST["lastname"]);
  $mail = htmlspecialchars($_POST["mail"]);
  $admin = isset($_POST["isadmin"]);

  if ($_POST["password"] === $_POST["confirm"]) 
  {
    $ldap->setUserUid($username);
    $ldap->setUserGivenname($firstname);
    $ldap->setUserSn($lastname);
    $ldap->setUserMail($mail);
    $ldap->setUserUserpassword($password);
    if ($admin) $ldap->setUserDescription('admin');

    if ($ldap->saveUser()) 
    {
      if ($admin) $ldap->grantAdmin($username);
      flash('success', T_('User succefully created.'));
      $mailMessage = T_('Username:').' '.$username."\n".T_('Password:').' '.$_POST["password"];
      sendMail($mail, T_('Your account details'), $mailMessage);
      if ($ajax) return true; 
      else redirect_to('/user/list');
    } <commit_msg>Welcome mail<commit_after><?php 

 /**
  *  YunoHost - Self-hosting for all
  *  Copyright (C) 2012  Kload <<EMAIL>>
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU Affero General Public License as
  *  published by the Free Software Foundation, either version 3 of the
  *  License, or (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU Affero General Public License for more details.
  *
  *  You should have received a copy of the GNU Affero General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  
/**
 * GET /user
 */
function user() {
  redirect_to('/user/list');
}

/**
 * GET /user/list
 */
function listUser() {
  global $ldap;

  // Fetch users
  $ldap->setSearchPath(array('ou' => 'users'));
  $ldap->setAttributesToFetch(array("mail", "uid", "cn", "dn"));
  $users = $ldap->findAll('(objectClass=inetOrgPerson)');

  // Fetch admin list
  $ldap->populateAdmin(array('cn' => 'admin'));
  $adminsDn = $ldap->getAdminMember();

  set('users', $users);
  set('adminsDn', $adminsDn);
  set('title', T_('List users'));        
  return render("listUser.html.php");
}

/**
 * GET /user/add
 */
function addUserForm () {
  global $ldap;
  $domains = $ldap->findAll('(objectClass=mailDomain)');
  set('domains', $domains);
  set('title', T_('Add user'));
  return render("addUserForm.html.php");
}

/**
 * POST /user/add
 */
function addUser () {
  global $ldap;

  $_SESSION['first-install'] = false;

  $ajax = isset($_POST['ajax']);

  $domain = htmlspecialchars($_POST["domain"]);
  $username = htmlspecialchars($_POST["username"]);
  $password = '{<PASSWORD>}'.base64_encode(pack('H*',md5($_POST["password"])));
  $firstname = htmlspecialchars($_POST["firstname"]);
  $lastname = htmlspecialchars($_POST["lastname"]);
  $mail = htmlspecialchars($_POST["mail"]);
  $admin = isset($_POST["isadmin"]);

  if ($_POST["password"] === $_POST["confirm"]) 
  {
    $ldap->setUserUid($username);
    $ldap->setUserGivenname($firstname);
    $ldap->setUserSn($lastname);
    $ldap->setUserMail($mail);
    $ldap->setUserUserpassword($password);
    if ($admin) $ldap->setUserDescription('admin');

    if ($ldap->saveUser()) 
    {
      if ($admin) $ldap->grantAdmin($username);
      flash('success', T_('User succefully created.'));

      $welcomeMessage = T_('Welcome aboard! Here is your login and password to connect to your apps.');
      $welcomeMessage2 = T_('If you want to change your password, click on the link below:');

      $mailMessage = T_('Username:').' '.$username."\n".T_('Password:').' '.$_POST["password"];
      $htmlMessage = '<img src="http://wiki.yunohost.org/skins/common/images/cloud.png" />'.
                      '<br />'.
                      '<p>'.$welcomeMessage.'</p>'.
                      '<br />'.
                      '<div><strong>'.T_('Username:').'</strong> '.$username."</div>\n
                      <div><strong>".T_('Password:').'</strong> '.$_POST["password"].'</div>'.
                      '<br />'.
                      '<p>'.$welcomeMessage2.'</p>'.
                      '<a href="https://auth.'.$domain.'">https://auth.'.$domain.'</a>';
      sendMail($mail, T_('Your account details'), $mailMessage, $htmlMessage);
      if ($ajax) return true; 
      else redirect_to('/user/list');
    } 
{'fraction_non_alphanumeric': 0.1851675400984596, 'fraction_numerical': 0.0030173098300778148, 'mean_word_length': 3.42586085734364, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 60, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2600382', 'n_tokens_mistral': 2080, 'n_tokens_neox': 2022, 'n_words': 487}