diff --git a/.gitignore b/.gitignore index 70faa0d..1f76754 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea .htaccess .token .token_flickr diff --git a/include/email-validation.inc b/include/email-validation.inc deleted file mode 100644 index 267b72d..0000000 --- a/include/email-validation.inc +++ /dev/null @@ -1,23 +0,0 @@ -Okay, your password has been changed. It could take as long as an hour before this change makes it to the VCS server and other services. To change your password again, you\'ll have to start this process over to get a new key.
'; diff --git a/public/manage/event.php b/public/manage/event.php index d770c4b..db73641 100644 --- a/public/manage/event.php +++ b/public/manage/event.php @@ -4,7 +4,6 @@ require __DIR__ . '/../../vendor/autoload.php'; require __DIR__ . '/../../include/login.inc'; -require __DIR__ . '/../../include/email-validation.inc'; define('PHP_SELF', hsc($_SERVER['PHP_SELF'])); diff --git a/public/manage/pinfo.php b/public/manage/pinfo.php deleted file mode 100644 index ea31152..0000000 --- a/public/manage/pinfo.php +++ /dev/null @@ -1,11 +0,0 @@ - FILTER_VALIDATE_INT, "rawpasswd" => FILTER_UNSAFE_RAW, @@ -83,8 +62,13 @@ function csrf_validate(&$mydata, $name) { $action = filter_input(INPUT_POST, "action", FILTER_CALLBACK, ["options" => "validateAction"]); if ($id && $action) { - csrf_validate($_SESSION, $action); - if (!is_admin($_SESSION["username"])) { + try { + Csrf::validate($_SESSION, $action); + } catch (Exception $e) { + warn($e->getMessage()); + exit; + } + if (!Access::isAdmin($_SESSION["username"])) { warn("you're not allowed to take actions on users."); exit; } @@ -104,8 +88,13 @@ function csrf_validate(&$mydata, $name) { } if ($in) { - csrf_validate($_SESSION, "useredit"); - if (!can_modify($_SESSION["username"],$id)) { + try { + Csrf::validate($_SESSION, 'useredit'); + } catch (Exception $e) { + warn($e->getMessage()); + exit; + } + if (!Access::canUserEdit($_SESSION["username"], $id)) { warn("you're not allowed to modify this user."); } else { @@ -115,7 +104,7 @@ function csrf_validate(&$mydata, $name) { else { if (!empty($in['rawpasswd'])) { $userinfo = fetch_user($id); - $in['svnpasswd'] = gen_pass($in['rawpasswd']); + $in['svnpasswd'] = Password::hash($in['rawpasswd']); } $cvsaccess = empty($in['cvsaccess']) ? 0 : 1; @@ -134,10 +123,10 @@ function csrf_validate(&$mydata, $name) { if (!empty($in['sshkey'])) { $query->add(',ssh_keys=?', [html_entity_decode($in['sshkey'],ENT_QUOTES)]); } - if (is_admin($_SESSION["username"]) && !empty($in['username'])) { + if (Access::isAdmin($_SESSION["username"]) && !empty($in['username'])) { $query->add(',username=?', [$in['username']]); } - if (is_admin($_SESSION["username"])) { + if (Access::isAdmin($_SESSION["username"])) { $query->add(',cvsaccess=?', [$cvsaccess]); } $query->add( @@ -161,7 +150,7 @@ function csrf_validate(&$mydata, $name) { if(!empty($in['profile_markdown'])) { $profile_markdown = $in['profile_markdown']; - $profile_html = \Michelf\MarkdownExtra::defaultTransform($profile_markdown); + $profile_html = MarkdownExtra::defaultTransform($profile_markdown); $query = "INSERT INTO users_profile (userid, markdown, html) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE markdown=?, html=?"; db_query_safe($query, [$id, $profile_markdown, $profile_html, $profile_markdown, $profile_html]); @@ -178,7 +167,7 @@ function csrf_validate(&$mydata, $name) { if ($id) { ?>| diff --git a/src/Access.php b/src/Access.php new file mode 100644 index 0000000..19bee1f --- /dev/null +++ b/src/Access.php @@ -0,0 +1,80 @@ +prepare('SELECT userid FROM users WHERE userid = ? AND (email = ? OR username = ?)'); + $sql->execute([$userId, $username, $username]); + + return $sql->rowCount() > 0; + } +} \ No newline at end of file diff --git a/src/Email.php b/src/Email.php new file mode 100644 index 0000000..dc931f2 --- /dev/null +++ b/src/Email.php @@ -0,0 +1,27 @@ +prepare("SELECT svnpasswd FROM users WHERE cvsaccess AND username = ?"); + $stmt->execute([$username]); + if (false === $row = $stmt->fetch()) { + return false; + } + return password_verify($password, $row['svnpasswd']); + } +} \ No newline at end of file diff --git a/src/cvs-auth.php b/src/cvs-auth.php index ec18876..074e749 100644 --- a/src/cvs-auth.php +++ b/src/cvs-auth.php @@ -2,19 +2,6 @@ use App\DB; -function gen_pass($password) { - return password_hash($password, PASSWORD_BCRYPT); -} - -function verify_password(DB $db, $user, $pass) { - $stmt = $db->prepare("SELECT svnpasswd FROM users WHERE cvsaccess AND username = ?"); - $stmt->execute([$user]); - if (false === $row = $stmt->fetch()) { - return false; - } - return password_verify($pass, $row['svnpasswd']); -} - function verify_username(DB $db, $user) { $stmt = $db->prepare("SELECT 1 FROM users WHERE cvsaccess AND username = ?"); $stmt->execute([$user]); |