Ejemplo n.º 1
0
 function register_user($projectid, $email, $firstName, $lastName, $repositoryCredential)
 {
     include "cdash/config.php";
     $UserProject = new UserProject();
     $UserProject->ProjectId = $projectid;
     // Check if the user is already registered
     $user = pdo_query("SELECT id FROM " . qid("user") . " WHERE email='{$email}'");
     if (pdo_num_rows($user) > 0) {
         // Check if the user has been registered to the project
         $user_array2 = pdo_fetch_array($user);
         $userid = $user_array2["id"];
         $user = pdo_query("SELECT userid FROM user2project WHERE userid='{$userid}' AND projectid='{$projectid}'");
         if (pdo_num_rows($user) == 0) {
             // We register the user to the project
             pdo_query("INSERT INTO user2project (userid,projectid,role,emailtype)\n                                  VALUES ('{$userid}','{$projectid}','0','1')");
             // We add the credentials if not already added
             $UserProject->UserId = $userid;
             $UserProject->AddCredential($repositoryCredential);
             $UserProject->ProjectId = 0;
             $UserProject->AddCredential($email);
             // Add the email by default
             echo pdo_error();
             return false;
         }
         return "<error>User " . $email . " already registered.</error>";
     }
     // already registered
     // Check if the repositoryCredential exists for this project
     $UserProject->RepositoryCredential = $repositoryCredential;
     if ($UserProject->FillFromRepositoryCredential() === true) {
         return "<error>" . $repositoryCredential . " was already registered for this project under a different email address</error>";
     }
     // Register the user
     // Create a new password
     $keychars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
     $length = 10;
     srand(make_seed_recoverpass());
     $pass = "";
     $max = strlen($keychars) - 1;
     for ($i = 0; $i <= $length; $i++) {
         $pass .= substr($keychars, rand(0, $max), 1);
     }
     $encrypted = md5($pass);
     pdo_query("INSERT INTO " . qid("user") . " (email,password,firstname,lastname,institution,admin)\n                 VALUES ('{$email}','{$encrypted}','{$firstName}','{$lastName}','','0')");
     add_last_sql_error("register_user");
     $userid = pdo_insert_id("user");
     // Insert the user into the project
     pdo_query("INSERT INTO user2project (userid,projectid,role,emailtype)\n                                VALUES ('{$userid}','{$projectid}','0','1')");
     add_last_sql_error("register_user");
     // We add the credentials if not already added
     $UserProject->UserId = $userid;
     $UserProject->AddCredential($repositoryCredential);
     $UserProject->ProjectId = 0;
     $UserProject->AddCredential($email);
     // Add the email by default
     $currentURI = get_server_URI();
     $prefix = "";
     if (strlen($firstName) > 0) {
         $prefix = " ";
     }
     $project = pdo_query("SELECT name FROM project WHERE id='{$projectid}'");
     $project_array = pdo_fetch_array($project);
     $projectname = $project_array['name'];
     // Send the email
     $text = "Hello" . $prefix . $firstName . ",<br><br>";
     $text .= "You have been registered to CDash because you have CVS/SVN access to the repository for " . $projectname . " <br>";
     $text .= "To access your CDash account: " . $currentURI . "/user.php<br>";
     $text .= "Your login is: " . $email . "<br>";
     $text .= "Your password is: " . $pass . "<br>";
     $text .= "<br>Generated by CDash.";
     if (@cdashmail("{$email}", "CDash - " . $projectname . " : Subscription", "{$text}", "From: {$CDASH_EMAILADMIN}\nReply-To: no-reply\nContent-type: text/plain; charset=utf-8\nX-Mailer: PHP/" . phpversion() . "\nMIME-Version: 1.0\nContent-type: text/html; charset=UTF-8")) {
         echo "Email sent to: " . $email . "<br>";
     }
     return true;
 }
Ejemplo n.º 2
0
                 // Update the repository credential
                 $UserProject = new UserProject();
                 $UserProject->ProjectId = $projectid;
                 $UserProject->UserId = $userid;
                 $UserProject->UpdateCredentials($Credentials);
                 if ($Role == 0) {
                     // Remove the claim sites for this project if they are only part of this project
                     pdo_query("DELETE FROM site2user WHERE userid='{$userid}'\n                 AND siteid NOT IN\n                (SELECT build.siteid FROM build,user2project as up WHERE\n                 up.projectid = build.projectid AND up.userid='{$userid}' AND up.role>0\n                 GROUP BY build.siteid)");
                 }
             } else {
                 pdo_query("INSERT INTO user2project (role,userid,projectid,emailtype,emailcategory,emailsuccess,\n                                           emailmissingsites)\n                 VALUES ('{$Role}','{$userid}','{$projectid}','{$EmailType}','{$EmailCategory}',\n                         '{$EmailSuccess}','{$EmailMissingSites}')");
                 $UserProject = new UserProject();
                 $UserProject->ProjectId = $projectid;
                 $UserProject->UserId = $userid;
                 foreach ($Credentials as $credential) {
                     $UserProject->AddCredential($credential);
                 }
             }
             header('location: user.php?note=subscribedtoproject');
         }
     }
 }
 // XML
 // Show the current credentials for the user
 $query = pdo_query("SELECT credential,projectid FROM user2repository WHERE userid='" . $userid . "'\n                      AND (projectid='" . $projectid . "' OR projectid=0)");
 $credential_num = 0;
 while ($credential_array = pdo_fetch_array($query)) {
     if ($credential_array['projectid'] == 0) {
         $xml .= add_XML_value("global_credential", $credential_array['credential']);
     } else {
         $xml .= add_XML_value("credential_" . $credential_num++, $credential_array['credential']);
Ejemplo n.º 3
0
 function register_user($projectid, $email, $firstName, $lastName, $repositoryCredential)
 {
     include dirname(__DIR__) . '/config/config.php';
     $UserProject = new UserProject();
     $UserProject->ProjectId = $projectid;
     // Check if the user is already registered
     $user = pdo_query('SELECT id FROM ' . qid('user') . " WHERE email='{$email}'");
     if (pdo_num_rows($user) > 0) {
         // Check if the user has been registered to the project
         $user_array2 = pdo_fetch_array($user);
         $userid = $user_array2['id'];
         $user = pdo_query("SELECT userid FROM user2project WHERE userid='{$userid}' AND projectid='{$projectid}'");
         if (pdo_num_rows($user) == 0) {
             // not registered
             // We register the user to the project
             pdo_query("INSERT INTO user2project (userid,projectid,role,emailtype)\n                                  VALUES ('{$userid}','{$projectid}','0','1')");
             // We add the credentials if not already added
             $UserProject->UserId = $userid;
             $UserProject->AddCredential($repositoryCredential);
             $UserProject->ProjectId = 0;
             $UserProject->AddCredential($email);
             // Add the email by default
             echo pdo_error();
             return false;
         }
         return '<error>User ' . $email . ' already registered.</error>';
     }
     // already registered
     // Check if the repositoryCredential exists for this project
     $UserProject->RepositoryCredential = $repositoryCredential;
     if ($UserProject->FillFromRepositoryCredential() === true) {
         return '<error>' . $repositoryCredential . ' was already registered for this project under a different email address</error>';
     }
     // Register the user
     // Create a new password
     $keychars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
     $length = 10;
     $pass = '';
     $max = strlen($keychars) - 1;
     for ($i = 0; $i <= $length; $i++) {
         // random_int is available in PHP 7 and the random_compat PHP 5.x
         // polyfill included in the Composer package.json dependencies.
         $pass .= substr($keychars, random_int(0, $max), 1);
     }
     $encrypted = md5($pass);
     pdo_query('INSERT INTO ' . qid('user') . " (email,password,firstname,lastname,institution,admin)\n                 VALUES ('{$email}','{$encrypted}','{$firstName}','{$lastName}','','0')");
     add_last_sql_error('register_user');
     $userid = pdo_insert_id('user');
     // Insert the user into the project
     pdo_query("INSERT INTO user2project (userid,projectid,role,emailtype)\n                                VALUES ('{$userid}','{$projectid}','0','1')");
     add_last_sql_error('register_user');
     // We add the credentials if not already added
     $UserProject->UserId = $userid;
     $UserProject->AddCredential($repositoryCredential);
     $UserProject->ProjectId = 0;
     $UserProject->AddCredential($email);
     // Add the email by default
     $currentURI = get_server_URI();
     $prefix = '';
     if (strlen($firstName) > 0) {
         $prefix = ' ';
     }
     $project = pdo_query("SELECT name FROM project WHERE id='{$projectid}'");
     $project_array = pdo_fetch_array($project);
     $projectname = $project_array['name'];
     // Send the email
     $text = 'Hello' . $prefix . $firstName . ",\n\n";
     $text .= 'You have been registered to CDash because you have CVS/SVN access to the repository for ' . $projectname . "\n";
     $text .= 'To access your CDash account: ' . $currentURI . "/user.php\n";
     $text .= 'Your login is: ' . $email . "\n";
     $text .= 'Your password is: ' . $pass . "\n\n";
     $text .= 'Generated by CDash.';
     if (cdashmail("{$email}", 'CDash - ' . $projectname . ' : Subscription', "{$text}")) {
         echo 'Email sent to: ' . $email . '<br>';
     } else {
         add_log("cannot send email to: {$email}", 'register_user', LOG_ERR);
     }
     return true;
 }