Browse Source

Adding user ranks, Fixing #73

Alan Hardman 5 years ago
parent
commit
9dcfdd136d
5 changed files with 23 additions and 9 deletions
  1. 4 2
      app/controller.php
  2. 1 1
      app/view/install.html
  3. 13 0
      db/15.02.07.sql
  4. 2 3
      db/database.sql
  5. 3 3
      install.php

+ 4 - 2
app/controller.php

@@ -4,9 +4,10 @@ abstract class Controller {
 
 	/**
 	 * Require a user to be logged in. Redirects to /login if a session is not found.
+	 * @param  int $rank
 	 * @return int|bool
 	 */
-	protected function _requireLogin() {
+	protected function _requireLogin($rank = 1) {
 		$f3 = \Base::instance();
 		if($id = $f3->get("user.id")) {
 			return $id;
@@ -23,9 +24,10 @@ abstract class Controller {
 
 	/**
 	 * Require a user to be an administrator. Throws HTTP 403 if logged in, but not an admin.
+	 * @param  int $rank
 	 * @return int|bool
 	 */
-	protected function _requireAdmin() {
+	protected function _requireAdmin($rank = 4) {
 		$id = $this->_requireLogin();
 
 		$f3 = \Base::instance();

+ 1 - 1
app/view/install.html

@@ -123,7 +123,7 @@
 											<div class="form-group form-group-sm">
 												<label for="user-password" class="col-sm-3 control-label">Password</label>
 												<div class="col-sm-9">
-													<input type="password" class="form-control" id="user-password" name="user-password" required placeholder="admin">
+													<input type="password" class="form-control" id="user-password" name="user-password" placeholder="admin">
 												</div>
 											</div>
 											<div class="text-right">

+ 13 - 0
db/15.02.07.sql

@@ -0,0 +1,13 @@
+/*
+Rank 0: guest - read-only access
+Rank 1: client - read-only access + comments
+Rank 2: user - current user permissions
+Rank 3: manager - delete issues/comments
+Rank 4: admin - current admin privileges, minus plugin config
+Rank 5: superadmin - able to change config file values from web interface
+*/
+
+ALTER TABLE user ADD COLUMN rank tinyint(1) UNSIGNED DEFAULT 0 NOT NULL AFTER role;
+UPDATE user SET rank = '2' WHERE role = 'user';
+UPDATE user SET rank = '4' WHERE role = 'admin';
+UPDATE config SET value = '15.02.07' WHERE attribute = 'version';

+ 2 - 3
db/database.sql

@@ -11,6 +11,7 @@ CREATE TABLE `user` (
 	`password` char(40) DEFAULT NULL,
 	`salt` char(32) DEFAULT NULL,
 	`role` enum('user','admin','group') NOT NULL DEFAULT 'user',
+	`rank` tinyint(1) unsigned NOT NULL DEFAULT '0',
 	`task_color` char(6) DEFAULT NULL,
 	`theme` varchar(64) DEFAULT NULL,
 	`language` varchar(5) DEFAULT NULL,
@@ -23,8 +24,6 @@ CREATE TABLE `user` (
 	UNIQUE KEY `email` (`email`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-INSERT INTO `user` (`username`, `email`, `name`, `password`, `salt`, `role`, `api_key`, `created_date`) VALUES ('admin', 'admin@local', 'Admin', '703983b055847560176a1e2e8508dd68d237ddfa', 'Qfv42OMfAS751Mn6hsKeTECDgyq5dVf7', 'admin', '', NOW());
-
 DROP TABLE IF EXISTS `user_group`;
 CREATE TABLE `user_group` (
 	`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
@@ -274,4 +273,4 @@ CREATE TABLE `config` (
 	UNIQUE KEY `attribute` (`attribute`)
 ) ;
 
-INSERT INTO `config` (`attribute`, `value`) VALUES ('version', '15.01.31');
+INSERT INTO `config` (`attribute`, `value`) VALUES ('version', '15.02.07');

+ 3 - 3
install.php

@@ -35,9 +35,8 @@ if(!function_exists("imagecreatetruecolor")) {
 }
 
 // Run installation process if post data received
-if($f3->get("POST")) {
-	$f3 = \Base::instance();
-	$post = $f3->get("POST");
+if($_POST) {
+	$post = $_POST;
 
 	try {
 		// Connect to database
@@ -56,6 +55,7 @@ if($f3->get("POST")) {
 		$security = \Helper\Security::instance();
 		$user = new \Model\User;
 		$user->role = "admin";
+		$user->rank = 5; // superadmin
 		$user->name = "Admin";
 		$user->username = $post["user-username"] ?: "admin";
 		$user->email = $post["user-email"];