Dependency injection on migration functions (uid parameter).
This commit is contained in:
1 parent
2c64cd1d27
commit
3942e0535c
7 files changed
+23
-24
No files matched your search
@@ -857,7 +857,7 @@ private function logError($username, $error)
|
||||
/* Push the user to LDAP (nikolark) */
|
||||
$migrated = ldap_add_user($user->username, $user->firstname, $user->lastname, $user->email, $user->password, Array('dns-alle'));
|
||||
_log($migrated);
|
||||
set_migrated();
|
||||
set_migrated($user->id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -803,7 +803,7 @@ possibly include it instead? --Thomas Misund, 26. Oct 2009
|
||||
$form->display("horizontal");
|
||||
}
|
||||
// Migration LDAP (nikolark)
|
||||
if( !is_migrated() ) {
|
||||
if( !is_migrated(getCurrentUser()) ) {
|
||||
?>
|
||||
<div id="infomodal">
|
||||
<div class="ui-widget">
|
||||
|
||||
+6
-7
@@ -78,13 +78,12 @@ class User {
|
||||
return false;
|
||||
}
|
||||
$this->password = $data['password1'];
|
||||
if (!isAdmin()) {
|
||||
switch (checkForumUsername($data['username'], $this->password)) {
|
||||
case "wrong-password" :
|
||||
notify("Brukernavnet er allerede i bruk på forumet. " . "Om du selv har dette brukernavnet må du oppgi " . "riktig passord.");
|
||||
$this->id = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Does the username chosen exist in the forum allready? */
|
||||
if (!isAdmin() && checkForumUsername($data['username'], $this->password) == "wrong-password") {
|
||||
notify("Brukernavnet er allerede i bruk på forumet. Om du selv har dette brukernavnet må du oppgi riktig passord.");
|
||||
$this->id = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->addresstype = isset ($data['addresstype']) ? "int" : "no";
|
||||
|
||||
@@ -138,6 +138,7 @@ function getUseridFromPhone($phoneno) {
|
||||
function checkForumUsername($username, $password) {
|
||||
$conn = db_connect("forum");
|
||||
$sql = sprintf("SELECT user_id FROM phpbb_users u " . "WHERE username_clean = '%s' ", strtolower($username));
|
||||
/* TODO: What happends if the forum db does not exist? How do you print the error? */
|
||||
$result = & $conn->query($sql);
|
||||
if ($result->numRows() == 0) {
|
||||
return "not-used";
|
||||
@@ -1565,9 +1566,8 @@ function getStickerPeriod($time)
|
||||
// Migration (nikolark)
|
||||
|
||||
/* Returns true if the current logged in user have the migrated flag. */
|
||||
function is_migrated() {
|
||||
function is_migrated($uid) {
|
||||
$conn = db_connect();
|
||||
$uid = getCurrentUser();
|
||||
|
||||
$sql = sprintf("SELECT migrated FROM din_user WHERE id=%s AND migrated IS NOT NULL", $uid);
|
||||
$result = $conn->query($sql);
|
||||
@@ -1579,9 +1579,8 @@ function is_migrated() {
|
||||
return $result->numRows() > 0;
|
||||
}
|
||||
/* Update the migration status */
|
||||
function set_migrated() {
|
||||
function set_migrated($uid) {
|
||||
$conn = db_connect();
|
||||
$uid = getCurrentUser();
|
||||
|
||||
$sql = sprintf("UPDATE din_user SET migrated=NOW() WHERE id=%s", $uid);
|
||||
$result = $conn->query($sql);
|
||||
@@ -1592,9 +1591,8 @@ function set_migrated() {
|
||||
return true;
|
||||
}
|
||||
/* Find a users groups */
|
||||
function find_groups() {
|
||||
function find_groups($uid) {
|
||||
$conn = db_connect();
|
||||
$uid = getCurrentUser();
|
||||
$sql = "SELECT g.posix_group
|
||||
FROM din_usergrouprelationship ugr, din_user u, din_group g
|
||||
WHERE ugr.user_id = $uid
|
||||
|
||||
@@ -33,11 +33,13 @@ function user_exists($username) {
|
||||
|
||||
return $userExists;
|
||||
}
|
||||
/* Update the migration status */
|
||||
/*
|
||||
* Update the migration status.
|
||||
* Note: copied from functions.php
|
||||
*/
|
||||
if( !function_exists('set_migrated') ) {
|
||||
function set_migrated() {
|
||||
function set_migrated($uid) {
|
||||
$conn = db_connect();
|
||||
$uid = getCurrentUser();
|
||||
|
||||
$sql = sprintf("UPDATE din_user SET migrated=NOW() WHERE id=%s", $uid);
|
||||
$result = $conn->query($sql);
|
||||
@@ -49,9 +51,8 @@ function set_migrated() {
|
||||
}
|
||||
/* Note: copied from functions.php */
|
||||
if( !function_exists('is_migrated') ) {
|
||||
function is_migrated() {
|
||||
function is_migrated($uid) {
|
||||
$conn = db_connect();
|
||||
$uid = getCurrentUser();
|
||||
|
||||
$sql = sprintf("SELECT migrated FROM din_user WHERE id=%s AND migrated IS NOT NULL", $uid);
|
||||
$result = $conn->query($sql);
|
||||
@@ -63,10 +64,10 @@ if( !function_exists('is_migrated') ) {
|
||||
return $result->numRows() > 0;
|
||||
}
|
||||
}
|
||||
/* Note: copied from functions.php */
|
||||
if( !function_exists('find_groups') ) {
|
||||
function find_groups() {
|
||||
function find_groups($uid) {
|
||||
$conn = db_connect();
|
||||
$uid = getCurrentUser();
|
||||
$sql = "SELECT g.posix_group
|
||||
FROM din_usergrouprelationship ugr, din_user u, din_group g
|
||||
WHERE ugr.user_id = $uid
|
||||
|
||||
@@ -30,3 +30,4 @@ Added chrisoa to cn=dns-aktiv,ou=Groups,dc=neuf,dc=no
|
||||
Added chrisoa to cn=dns-administrator,ou=Groups,dc=neuf,dc=no
|
||||
Added chrisoa to cn=dns-kak,ou=Groups,dc=neuf,dc=no
|
||||
'
|
||||
[2011-08-19 15:12:11.000000]'API_KEY is invalid.'
|
||||
@@ -33,13 +33,13 @@ if ( !isset($result) ) {
|
||||
/* find user info */
|
||||
$user = new User(getCurrentUser());
|
||||
/* find groups */
|
||||
$groups = find_groups();
|
||||
$groups = find_groups(getCurrentUser());
|
||||
|
||||
/* migrated? */
|
||||
$migrated = ldap_add_user($_POST['username'], $user->firstname, $user->lastname, $user->email, $_POST['password'], $groups);
|
||||
/* Note: Assume success every time, but log result of migrated anyway. */
|
||||
_log($migrated);
|
||||
set_migrated();
|
||||
set_migrated(getCurrentUser());
|
||||
echo json_encode( Array('result' => 'success', 'groups' => $groups) );
|
||||
} else {
|
||||
echo json_encode( Array('result' => 'error', 'errors' => Array('database' => 'User not migrated.')) );
|
||||
|
||||
Reference in new issue
Block a user