public function execute() { global $CFG, $DB; require_once $CFG->dirroot . '/user/profile/lib.php'; require_once $CFG->libdir . '/csvlib.class.php'; $username = $this->arguments[0]; $filename = $this->expandedOptions['name']; $user = get_user_by_name($username); if (!$user) { cli_error("User not found."); } else { $userid = $user->id; } $fields = array('id' => 'id', 'username' => 'username', 'email' => 'email', 'firstname' => 'firstname', 'lastname' => 'lastname', 'idnumber' => 'idnumber', 'institution' => 'institution', 'department' => 'department', 'phone1' => 'phone1', 'phone2' => 'phone2', 'city' => 'city', 'url' => 'url', 'icq' => 'icq', 'skype' => 'skype', 'aim' => 'aim', 'yahoo' => 'yahoo', 'msn' => 'msn', 'country' => 'country'); if ($extrafields = $DB->get_records('user_info_field')) { foreach ($extrafields as $n => $v) { $fields['profile_field_' . $v->shortname] = 'profile_field_' . $v->shortname; } } $csvexport = new \csv_export_writer(); $csvexport->set_filename($filename); $csvexport->add_data($fields); $row = array(); profile_load_data($user); $userprofiledata = array(); foreach ($fields as $field => $unused) { if (is_array($user->{$field})) { $userprofiledata[] = reset($user->{$field}); } else { $userprofiledata[] = $user->{$field}; } } $csvexport->add_data($userprofiledata); file_put_contents($filename, $csvexport->print_csv_data(true)); echo "User " . $user->username . " successfully downloaded\n"; }
include "../includes/db_lib.php"; include "../includes/user_lib.php"; # Helper function to check email address validity function check_valid_email($email) { # TODO: # The following works for only >= PHP 5.2.0, hence not working on arc server. //return filter_var($email, FILTER_VALIDATE_EMAIL); return true; } $username = $_REQUEST['username']; $user_exists = check_user_exists($username); if ($user_exists == false) { $msg = "User <b>{$username}</b> not found. Please check the username entered."; } else { $user_profile = get_user_by_name($username); $email = $user_profile->email; # Remove the following line once get_user_profile works if (trim($email) == "") { $msg = "Email address not present for <b>{$username}</b>. Please contact sysadmin to reset your password."; } else { if (check_valid_email($email) === false) { $msg = "Email address <b>{$email}</b> not valid. Please contact sysadmin to reset your password."; } else { $new_password = get_random_password(); $password_changed = change_user_password($username, $new_password); if ($password_changed === false) { $msg = "Error while resetting password. Please try again."; } else { $subject = "[BLIS] New password for " . $username; $to_addr = $email;
function get_library_owner(&$ownerID) { $config =& get_config(); // Get the library owner ID if (!isset($config['library_owner_id'])) { if (!isset($config['library_owner_name'])) { log_message('warn', 'library owner not configured'); return false; } $userName = $config['library_owner_name']; $userInfo = get_user_by_name($userName); if (!$userInfo) { log_message('warn', sprintf('library owner not found %s', $userName)); return false; } $config['library_owner_id'] = $userInfo["UserID"]; } $ownerID = $config['library_owner_id']; return true; }
echo "Current working dir: " . $cwd . "\n"; echo "Relative Moodle dir: {$relative_dir}\n"; } $plugin_info = detect_plugin($relative_dir); $subcommand->setPluginInfo($plugin_info); $subcommand->topDir = $top_dir; $subcommand->relativeDir = $relative_dir; // Set up debugging. $CFG->debug = E_ALL; $CFG->debugdisplay = 1; @error_reporting(E_ALL); @ini_set('display_errors', '1'); if ($subcommand->bootstrapLevel() != MooshCommand::$BOOTSTRAP_CONFIG) { // By default set up $USER to admin user. if ($app_options->has('user')) { $user = get_user_by_name($app_options['user']->value); if (!$user) { echo "Error: No user account was found\n"; exit(1); } } else { $user = get_admin(); if (!$user) { echo "Error: No admin account was found\n"; exit(1); } } @complete_user_login($user); } } if ($app_options->has('verbose')) {
function create_user($name, $email, $password) { if (is_null(get_user_by_name($name))) { $user = new User(); $user->set_name($name)->set_email($email)->set_password($password); $mysqli = new mysqli(get_db_host(), get_db_user(), get_db_password(), get_db_database()); $stmt = $mysqli->prepare("INSERT INTO user(name, email, password_hash) VALUES (?, ?, ?)"); $stmt->bind_param("sss", $user->get_name(), $user->get_email(), $user->get_password_hash()); $stmt->execute(); $stmt->close(); } }
# Else, redirects to login.php # include "redirect.php"; require_once "includes/db_lib.php"; //include("includes/db_lib.php"); require_once "includes/user_lib.php"; # Start session if not already started if (session_id() == "") { session_start(); } $username = $_REQUEST['username']; $password = $_REQUEST['password']; $login_correct = check_user_password($username, $password); if ($login_correct) { #Set session variables $user = get_user_by_name($username); $_SESSION['username'] = $username; $_SESSION['user_id'] = $user->userId; $_SESSION['user_actualname'] = $user->actualName; $_SESSION['user_level'] = $user->level; $_SESSION['locale'] = $user->langId; if ($user->level == 17) { $combinedString = $_SESSION['doctorConfig'] = $user->rwoptions; $rwopts = '2,3,4,6,7'; $rwoptsarr = explode(" ", $rwopts); $_SESSION['rwoptionsarray'] = $rwoptsarr; } else { $rwopts = $user->rwoptions; $rwoptsarr = explode(" ", $rwopts); $_SESSION['rwoptionsarray'] = $rwoptsarr; }
<head> <title>Seventh Root - Sign up</title> <?php include '../includes/stylesheets.php'; ?> </head> <body> <div id="main"> <?php include '../includes/logo.php'; if (isset($_POST['username']) && isset($_POST['email']) && isset($_POST['password'])) { $username = $_POST['username']; $email = $_POST['email']; $password = $_POST['password']; $message = ''; if (!is_null(get_user_by_name($username))) { $message = 'A user by that name already exists. <a href="/signup">Choose a different username.</a>'; } else { create_user($username, $email, $password); $message = 'User created. You may now <a href="/login">login.</a>'; } } else { $message = 'Invalid request. Please <a href="/signup">try again</a>.'; } if (isset($_SESSION['user'])) { include '../includes/navigation.php'; } else { include '../includes/navigation_beforelogin.php'; } echo $message; ?>
function sn_update_user($id, $user_name = null, $user_pass = null, $user_email = null) { global $sn_sql; $id = (int) $id; if ($id == 0) { return false; } $error = array(); $user_pass = md5($user_pass); $user = get_user_by_id($id); // تحقق إذا لم يكن هناك مستخدم بذلك االمعرف id if (!$user) { array_push($error, 'there is no user with that id'); // send error massege at the end of the function return $error; } if (!check_empty($user_name) && !check_empty($user_pass) && !check_empty($user_email)) { return false; } $exist_user_name = get_user_by_name($user_name); $exist_user_email = get_user_by_email($user_email); if (!empty($exist_user_name) && $user->user_name != $user_name) { array_push($error, 'the name that you entred is used by another user'); } if (!empty($exist_user_email) && $user->user_email != $user_email) { array_push($error, 'the email that you entred is used by another user'); } if (!empty($error)) { return $error; } $fildes = array(); $sql_c = 'UPDATE `users` SET '; if (!empty($user_name)) { $user_name = strip_tags($user_name); array_push($fildes, "`user_name` = '{$user_name}' "); } if (!empty($user_pass)) { $user_name = strip_tags($user_pass); array_push($fildes, "`user_pass` = '{$user_pass}' "); } if (!empty($user_email)) { $user_name = strip_tags($user_email); array_push($fildes, "`user_email` = '{$user_email}' "); } $fcount = @count($fildes); if ($fcount == 1) { $sql_c .= $fildes['0'] . ' WHERE `id`=' . $id; $r = $sn_sql->query($sql_c); if (!$r) { return false; } else { return true; } } for ($i = 0; $i < $fcount; $i++) { $sql_c .= $fildes[$i]; if ($i != $fcount - 1) { $sql_c .= ' , '; } } $sql_c .= 'WHERE `id` =' . $id; $r = $sn_sql->query($sql_c); if (!$r) { return false; } else { return true; } }
$_SESSION['db_name'] = ""; } else { $_SESSION['lab_config_id'] = $user->labConfigId; $lab_config = get_lab_config_by_id($user->labConfigId); $_SESSION['db_name'] = $lab_config->dbName; } # Set session variables for recording latency/user props $_SESSION['PROPS_RECORDED'] = false; $_SESSION['DELAY_RECORDED'] = false; #TODO: Add other session variables here $_SESSION['user_role'] = "garbage"; } $page_access_map = array(); if (!isset($_SESSION['username']) && strpos($_SERVER['PHP_SELF'], 'login.php') === false && strpos($_SERVER['PHP_SELF'], 'password_reset.php') === false && strpos($_SERVER['PHP_SELF'], 'password_reset_confirm.php') === false) { #User not logged in header("Location:login.php?prompt"); } else { if (strpos($_SERVER['PHP_SELF'], 'login.php') === false && strpos($_SERVER['PHP_SELF'], 'password_reset.php') === false && strpos($_SERVER['PHP_SELF'], 'password_reset_confirm.php') === false) { # TODO: # This code is executed if the user is logged in # Check if user has access to $_SERVER['PHP_SELF'] if (isset($_SESSION['user_level'])) { } # ... # Fetch appropriate top menu options in an array if (isset($_SESSION['user_level'])) { $user = get_user_by_name($_SESSION['username']); $top_menu_options = get_top_menu_options($_SESSION['user_level'], $user->rwoptions); } } }
<?php require_once '../sn-loader.php'; $author_id = get_user_by_name($_COOKIE['user_name']); if (isset($_POST['draft_save'])) { $status = 0; $post_type = 'post'; } elseif (isset($_POST['draft_publish'])) { $status = 1; $post_type = 'note'; } else { $status = 0; } if (isset($_POST['draft_title']) && isset($_POST['draft_content'])) { $draft_array = array('title' => $_POST['draft_title'], 'content' => $_POST['draft_content'], 'status' => $status, 'type' => $post_type, 'sn_link' => $_POST['draft_title'], 'author' => $author_id->id); $new_post_id = sn_add_post($draft_array); var_dump($new_post_id); if (is_object($new_post_id)) { header("Location: edit-posts.php?id=" . $new_post_id->id); } else { header("Location: edit-posts.php?id={$new_post_id}"); } }
function get_uuid($method_name, $params, $user_data) { log_message('info', "[hypergrid] {$method_name} called"); $response = array(); $req = $params[0]; $fname = $req['first']; $lname = $req['last']; log_message('info', "[hypergrid] get_uuid with {$fname} and {$lname}"); $user = get_user_by_name("{$fname} {$lname}"); $response['UUID'] = $user['UserID']; return $response; }
global $username, $password, $email, $studentid; if (@$_POST['username'] and @$_POST['password'] and @$_POST['confpassword'] and @$_POST['email'] and @$_POST['studentid']) { if (@$_POST['password'] != @$_POST['confpassword']) { header("location: register.php?action=err&mes=注册失败!两次密码输入不一致!"); exit; } $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $studentid = $_POST['studentid']; if (get_user_by_name($username)) { header("location: register.php?action=err&mes=注册失败!用户名已存在!"); exit; } else { if (!is_numeric($studentid)) { header("location: register.php?action=err&mes=注册失败!学号不正确!"); exit; } else { if (!add_user($username, $password, $email, $studentid)) { header("location: register.php?action=err&mes=注册失败!请检查其他信息!"); exit; } else { $_SESSION['userid'] = get_user_by_name($username)['userid']; header("location: userdetails.php?action=succ&mes=注册成功!欢迎加入" . show_user_by_id($_SESSION['userid'])); exit; } } } } else { no_access('register.php'); }
<?php require_once __DIR__ . '/../Shared/Config.php'; require_once __DIR__ . '/../Shared/Util/Database.php'; require_once __DIR__ . '/../Shared/Util/Exceptions.php'; // TODO: memcache this? $FETCH_PASSWORD_OPTIONS = array('cost' => FETCH_PASSWORD_COST); $db_conn = open_database_connection(); $update_pass_query = $db_conn->prepare('UPDATE `users` SET PasswordHash = ? WHERE UserId = ?'); if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['username']) && isset($_POST['password'])) { $username = $_POST['username']; $password = $_POST['password']; $info = get_user_by_name($username); if ($info === false) { die(json_encode(array('OK' => false, 'error' => 'Invalid username or password'))); } else { $hash = $info["PasswordHash"]; if (password_verify($hash, $password)) { if (password_needs_rehash($hash, FETCH_PASSWORD_HASHING, $FETCH_PASSWORD_OPTIONS)) { $newHash = password_hash($password, FETCH_PASSWORD_HASHING, $FETCH_PASSWORD_OPTIONS); $update_pass_query->execute(array($newHash, $info["UserId"])); $update_pass_query->closeCursor(); // free resources } } else { die(json_encode(array('OK' => false, 'error' => 'Invalid username or password'))); } } } else { http_response_code(400);
public function start_session($username, $password) { session_start(); $sid = session_id(); //$_SESSION['tok'] = $sid; $user = get_user_by_name($username); $_SESSION['username'] = $username; $_SESSION['user_id'] = $user->userId; $_SESSION['user_actualname'] = $user->actualName; $_SESSION['user_level'] = $user->level; $_SESSION['level'] = $user->level; $_SESSION['locale'] = $user->langId; if ($user->level == 17) { $combinedString = $user->rwoptions; $_SESSION['doctorConfig'] = $combinedString; } if (is_admin_check($user)) { $lab_id = get_lab_config_id_admin($user->userId); $_SESSION['lab_config_id'] = $lab_id; $_SESSION['db_name'] = "blis_" . $lab_id; $_SESSION['dformat'] = $DEFAULT_DATE_FORMAT; $_SESSION['country'] = $user->country; } else { $_SESSION['lab_config_id'] = $user->labConfigId; echo $user->labConfigId; $_SESSION['country'] = $user->country; $lab_config = get_lab_config_by_id($user->labConfigId); $_SESSION['db_name'] = $lab_config->dbName; $_SESSION['dformat'] = $lab_config->dateFormat; $_SESSION['dnum_reset'] = $lab_config->dailyNumReset; $_SESSION['pnamehide'] = $lab_config->hidePatientName; # Config values for registration fields if ($user->level != 17) { $_SESSION['p_addl'] = $lab_config->patientAddl; $_SESSION['s_addl'] = $lab_config->specimenAddl; $_SESSION['dnum'] = $lab_config->dailyNum; $_SESSION['sid'] = $lab_config->sid; $_SESSION['pid'] = $lab_config->pid; $_SESSION['comm'] = $lab_config->comm; $_SESSION['age'] = $lab_config->age; $_SESSION['dob'] = $lab_config->dob; $_SESSION['rdate'] = $lab_config->rdate; $_SESSION['refout'] = $lab_config->refout; $_SESSION['pname'] = $lab_config->pname; $_SESSION['sex'] = $lab_config->sex; $_SESSION['doctor'] = $lab_config->doctor; } else { $arr1 = str_split($combinedString); $_SESSION['p_addl'] = $arr1[0]; $_SESSION['s_addl'] = $arr1[1]; $_SESSION['dnum'] = $arr1[2]; $_SESSION['sid'] = $arr1[3]; $_SESSION['pid'] = $arr1[4]; $_SESSION['comm'] = $arr1[5]; $_SESSION['age'] = $arr1[6]; $_SESSION['dob'] = $arr1[7]; $_SESSION['rdate'] = $arr1[8]; $_SESSION['refout'] = $arr1[9]; $_SESSION['pname'] = $arr1[10]; $_SESSION['sex'] = $arr1[11]; $_SESSION['doctor'] = $arr1[12]; } if ($SERVER == $ON_PORTABLE) { $_SESSION['langdata_path'] = $LOCAL_PATH . "langdata_" . $lab_config->id . "/"; } else { $_SESSION['langdata_path'] = $LOCAL_PATH . "langdata_revamp/"; } } # Set session variables for recording latency/user props $_SESSION['PROPS_RECORDED'] = false; $_SESSION['DELAY_RECORDED'] = false; #TODO: Add other session variables here $_SESSION['user_role'] = "garbage"; return 1; }
switch ($_POST['action']) { case 'register': if (!$_POST['username']) { //die('Please provide a user name.'); $error = 'Please provide a user name.'; break; } if (!$_POST['password1']) { $error = 'Please provide a password.'; break; } if ($_POST['password1'] != $_POST['password2']) { $error = 'Passwords do not match. Please try again.'; break; } $prev_registered_user = get_user_by_name($context->db, $_POST['username']); if ($prev_registered_user) { $error = 'Username exists.'; break; } // Verify that the email address has not been used in a previous registration. $mailsearch = "SELECT email from users WHERE email=?"; $res_mailsearch = $context->db->query($mailsearch, $_POST['email']); $email_match = $res_mailsearch->fetchRow(DB_FETCHMODE_ASSOC); if ($email_match) { $error = 'Someone has already registered with that email address.'; break; } $new_user = add_user($context->db); $new_user['name'] = $_POST['username']; $new_user['email'] = $_POST['email'];
function login_user_by_name(&$dbh, $user) { if ($user = get_user_by_name($dbh, $user)) { $_SESSION['user_id'] = $user['id']; } }