mirror of
https://github.com/xevidos/codiad.git
synced 2024-12-22 13:52:16 +01:00
Updated ReadMe, Updated is admin check, Added initial change user access ability, Started updating update script for new sql methods, Reformatted user init.js indentation, Reformatted indentation on user dialog.
This commit is contained in:
parent
a9dc1e2815
commit
3d122eb296
7 changed files with 486 additions and 462 deletions
|
@ -27,7 +27,7 @@ Task List:
|
||||||
|
|
||||||
* Add ability to login with LDAP
|
* Add ability to login with LDAP
|
||||||
* Add custom market
|
* Add custom market
|
||||||
* Add in new admin interface
|
* Add in new admin interface ( Check admin-portal branch for progress )
|
||||||
- Group Management
|
- Group Management
|
||||||
- Permissions Management
|
- Permissions Management
|
||||||
- Plugin Management
|
- Plugin Management
|
||||||
|
@ -37,6 +37,7 @@ Task List:
|
||||||
* Add if file could not be saved 5 times close the open file
|
* Add if file could not be saved 5 times close the open file
|
||||||
* Add multi level users. ( Projects for only certain groups, Permission levels )
|
* Add multi level users. ( Projects for only certain groups, Permission levels )
|
||||||
* Add mobile compatibility
|
* Add mobile compatibility
|
||||||
|
* Add support for more database systems and test ( MSSQL, Oracle, Postgre SQL, SQLite, etc )
|
||||||
* Clean up update script
|
* Clean up update script
|
||||||
* Re Add the language recognition system after recode
|
* Re Add the language recognition system after recode
|
||||||
|
|
||||||
|
@ -47,6 +48,10 @@ Completed:
|
||||||
* Add ability to center bottom of code
|
* Add ability to center bottom of code
|
||||||
* Add updating script
|
* Add updating script
|
||||||
* Add site renaming
|
* Add site renaming
|
||||||
|
* Database Update
|
||||||
|
- Added Mysql Support.
|
||||||
|
- Project Updated to use PDO so future support for more database systems can be added.
|
||||||
|
- Updated to store program data ( Not project data ) in databases.
|
||||||
* Fix JS errors already showing
|
* Fix JS errors already showing
|
||||||
* Remove Codiad autocomplete in favor of Ace's
|
* Remove Codiad autocomplete in favor of Ace's
|
||||||
* Updated for PHP 7.2
|
* Updated for PHP 7.2
|
14
common.php
14
common.php
|
@ -201,15 +201,9 @@ class Common {
|
||||||
global $sql;
|
global $sql;
|
||||||
$query = "SELECT COUNT( * ) FROM users WHERE username=? AND access=?;";
|
$query = "SELECT COUNT( * ) FROM users WHERE username=? AND access=?;";
|
||||||
$bind_variables = array( $_SESSION["user"], "admin" );
|
$bind_variables = array( $_SESSION["user"], "admin" );
|
||||||
$return = $sql->query( $query, $bind_variables, formatJSEND( "error", "Error checking user acess." ), 'fetchColumn' );
|
$return = $sql->query( $query, $bind_variables, -1, 'fetchColumn' );
|
||||||
|
$admin = ( $return > 0 );
|
||||||
if( $return > 0 ) {
|
return $admin;
|
||||||
|
|
||||||
return( true );
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return( false );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function logout() {
|
public static function logout() {
|
||||||
|
@ -644,7 +638,7 @@ class Common {
|
||||||
// Wrapper for old method names
|
// Wrapper for old method names
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function is_admin() { Common::is_admin(); }
|
function is_admin() { return Common::is_admin(); }
|
||||||
function debug($message) { Common::debug($message); }
|
function debug($message) { Common::debug($message); }
|
||||||
function i18n($key, $args = array()) { echo Common::i18n($key, $args); }
|
function i18n($key, $args = array()) { echo Common::i18n($key, $args); }
|
||||||
function get_i18n($key, $args = array()) { return Common::get_i18n($key, $args); }
|
function get_i18n($key, $args = array()) { return Common::get_i18n($key, $args); }
|
||||||
|
|
|
@ -56,69 +56,6 @@ class updater {
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const DEFAULT_OPTIONS = array(
|
|
||||||
array(
|
|
||||||
"name" => "codiad.editor.autocomplete",
|
|
||||||
"value" => "false",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"name" => "codiad.editor.fileManagerTrigger",
|
|
||||||
"value" => "false",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"name" => "codiad.editor.fontSize",
|
|
||||||
"value" => "14px",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"name" => "codiad.editor.highlightLine",
|
|
||||||
"value" => "true",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"name" => "codiad.editor.indentGuides",
|
|
||||||
"value" => "true",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"name" => "codiad.editor.overScroll",
|
|
||||||
"value" => "0.5",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"name" => "codiad.editor.persistentModal",
|
|
||||||
"value" => "true",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"name" => "codiad.editor.printMargin",
|
|
||||||
"value" => "true",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"name" => "codiad.editor.printMarginColumn",
|
|
||||||
"value" => "80",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"name" => "codiad.editor.rightSidebarTrigger",
|
|
||||||
"value" => "false",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"name" => "codiad.editor.softTabs",
|
|
||||||
"value" => "false",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"name" => "codiad.editor.tabSize",
|
|
||||||
"value" => "4",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"name" => "codiad.editor.theme",
|
|
||||||
"value" => "twilight",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"name" => "codiad.editor.wrapMode",
|
|
||||||
"value" => "false",
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"name" => "codiad.settings.autosave",
|
|
||||||
"value" => "true",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Properties
|
* Properties
|
||||||
|
@ -253,12 +190,12 @@ class updater {
|
||||||
|
|
||||||
require_once('../../common.php');
|
require_once('../../common.php');
|
||||||
require_once('../sql/class.sql.php');
|
require_once('../sql/class.sql.php');
|
||||||
|
require_once('../settings/class.settings.php');
|
||||||
|
|
||||||
$user_settings_file = DATA . "/settings.php";
|
$user_settings_file = DATA . "/settings.php";
|
||||||
$projects_file = DATA . "/projects.php";
|
$projects_file = DATA . "/projects.php";
|
||||||
$users_file = DATA . "/users.php";
|
$users_file = DATA . "/users.php";
|
||||||
|
global $sql;
|
||||||
$sql = new sql();
|
|
||||||
$connection = $sql->connect();
|
$connection = $sql->connect();
|
||||||
|
|
||||||
$query = "
|
$query = "
|
||||||
|
@ -485,7 +422,7 @@ DELETE FROM user_options;
|
||||||
|
|
||||||
public function set_default_options() {
|
public function set_default_options() {
|
||||||
|
|
||||||
foreach( self::DEFAULT_OPTIONS as $id => $option ) {
|
foreach( Settings::DEFAULT_OPTIONS as $id => $option ) {
|
||||||
|
|
||||||
$this->update_option( $option["name"], $option["value"], true );
|
$this->update_option( $option["name"], $option["value"], true );
|
||||||
}
|
}
|
||||||
|
@ -571,25 +508,32 @@ DELETE FROM user_options;
|
||||||
|
|
||||||
public function update_option( $option, $value, $user_setting = null ) {
|
public function update_option( $option, $value, $user_setting = null ) {
|
||||||
|
|
||||||
|
$sql = new sql();
|
||||||
$query = "INSERT INTO user_options ( name, username, value ) VALUES ( ?, ?, ? );";
|
$query = "INSERT INTO user_options ( name, username, value ) VALUES ( ?, ?, ? );";
|
||||||
$bind = "sss";
|
|
||||||
$bind_variables = array(
|
$bind_variables = array(
|
||||||
$option,
|
$option,
|
||||||
$this->username,
|
$this->username,
|
||||||
$value,
|
$value,
|
||||||
);
|
);
|
||||||
$result = sql::sql( $query, $bind, $bind_variables, formatJSEND( "error", "Error, Could not add user's settings." ) );
|
$result = $sql->query( $query, $bind_variables, 0, "rowCount" );
|
||||||
|
|
||||||
if( $result !== true ) {
|
if( $result == 0 ) {
|
||||||
|
|
||||||
$query = "UPDATE user_options SET value=? WHERE name=? AND username=?;";
|
$query = "UPDATE user_options SET value=? WHERE name=? AND username=?;";
|
||||||
$bind = "sss";
|
|
||||||
$bind_variables = array(
|
$bind_variables = array(
|
||||||
$value,
|
$value,
|
||||||
$option,
|
$option,
|
||||||
$this->username,
|
$this->username,
|
||||||
);
|
);
|
||||||
$result = sql::sql( $query, $bind, $bind_variables, formatJSEND( "error", "Error, Could not update user's settings." ) );
|
$result = $sql->query( $query, $bind_variables, 0, "rowCount" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( $result > 0 ) {
|
||||||
|
|
||||||
|
echo formatJSEND( "success", null );
|
||||||
|
} else {
|
||||||
|
|
||||||
|
echo formatJSEND( "error", "Error, Could not update option $option" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -606,8 +550,10 @@ DELETE FROM user_options;
|
||||||
|
|
||||||
if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
|
if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
|
||||||
|
|
||||||
|
global $sql;
|
||||||
$updater = new updater();
|
$updater = new updater();
|
||||||
$action = $_GET["action"];
|
$action = $_GET["action"];
|
||||||
|
$sql = new sql();
|
||||||
|
|
||||||
switch( $action ) {
|
switch( $action ) {
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,11 @@ require_once( "../settings/class.settings.php" );
|
||||||
|
|
||||||
class User {
|
class User {
|
||||||
|
|
||||||
|
const ACCESS = array(
|
||||||
|
"admin",
|
||||||
|
"user"
|
||||||
|
);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// PROPERTIES
|
// PROPERTIES
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -142,3 +142,10 @@ if ($_GET['action']=='verify') {
|
||||||
//$User->Verify();
|
//$User->Verify();
|
||||||
checkSession();
|
checkSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ( $_GET['action'] == 'update_access' ) {
|
||||||
|
|
||||||
|
checkSession();
|
||||||
|
echo json_encode( array( $_GET["username"], $_GET["access"] ) );
|
||||||
|
}
|
||||||
|
|
|
@ -1,140 +1,176 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
|
* Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
|
||||||
* as-is and without warranty under the MIT License. See
|
* as-is and without warranty under the MIT License. See
|
||||||
* [root]/license.txt for more. This information must remain intact.
|
* [root]/license.txt for more. This information must remain intact.
|
||||||
*/
|
*/
|
||||||
require_once('../../common.php');
|
require_once('../../common.php');
|
||||||
require_once('./class.user.php');
|
require_once('./class.user.php');
|
||||||
$User = new User();
|
$User = new User();
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// Verify Session or Key
|
// Verify Session or Key
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
checkSession();
|
checkSession();
|
||||||
|
|
||||||
switch($_GET['action']){
|
switch($_GET['action']){
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
// List Projects
|
// List Projects
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
case 'list':
|
case 'list':
|
||||||
|
|
||||||
$projects_assigned = false;
|
$projects_assigned = false;
|
||||||
if( ! checkAccess() ){
|
|
||||||
?>
|
if( ! checkAccess() ) {
|
||||||
<label><?php i18n("Restricted"); ?></label>
|
|
||||||
<pre><?php i18n("You can not edit the user list"); ?></pre>
|
?>
|
||||||
<button onclick="codiad.modal.unload();return false;"><?php i18n("Close"); ?></button>
|
<label><?php i18n("Restricted"); ?></label>
|
||||||
<?php } else { ?>
|
<pre><?php i18n("You can not edit the user list"); ?></pre>
|
||||||
<label><?php i18n("User List"); ?></label>
|
<button onclick="codiad.modal.unload();return false;"><?php i18n("Close"); ?></button>
|
||||||
<div id="user-list">
|
<?php
|
||||||
<table width="100%">
|
} else {
|
||||||
<tr>
|
|
||||||
<th width="150"><?php i18n("Username"); ?></th>
|
$admin = is_admin();
|
||||||
<th width="85"><?php i18n("Password"); ?></th>
|
?>
|
||||||
<th width="70"><?php i18n("Delete"); ?></th>
|
<label><?php i18n("User List"); ?></label>
|
||||||
</tr>
|
<div id="user-list">
|
||||||
</table>
|
<table width="100%">
|
||||||
<div class="user-wrapper">
|
<tr>
|
||||||
<table width="100%" style="word-wrap: break-word;word-break: break-all;">
|
<th width="150"><?php i18n("Username"); ?></th>
|
||||||
<?php
|
<th width="85"><?php i18n("Password"); ?></th>
|
||||||
|
<?php
|
||||||
// Get projects JSON data
|
|
||||||
$users = $User->list_users();
|
if( $admin ) {
|
||||||
foreach( $users as $user => $data ) {
|
|
||||||
?>
|
?>
|
||||||
<tr>
|
<th width="70"><?php i18n("Access"); ?></th>
|
||||||
<td width="150"><?php echo($data['username']); ?></td>
|
<?php
|
||||||
<td width="85"><a onclick="codiad.user.password('<?php echo($data['username']); ?>');" class="icon-flashlight bigger-icon"></a></td>
|
}
|
||||||
<?php
|
?>
|
||||||
if($_SESSION['user'] == $data['username']){
|
<th width="70"><?php i18n("Delete"); ?></th>
|
||||||
?>
|
</tr>
|
||||||
<td width="75"><a onclick="codiad.message.error('You Cannot Delete Your Own Account');" class="icon-block bigger-icon"></a></td>
|
</table>
|
||||||
<?php
|
<div class="user-wrapper">
|
||||||
}else{
|
<table width="100%" style="word-wrap: break-word;word-break: break-all;">
|
||||||
?>
|
<?php
|
||||||
<td width="70"><a onclick="codiad.user.delete('<?php echo($data['username']); ?>');" class="icon-cancel-circled bigger-icon"></a></td>
|
|
||||||
<?php
|
// Get projects JSON data
|
||||||
}
|
$users = $User->list_users();
|
||||||
?>
|
foreach( $users as $user => $data ) {
|
||||||
</tr>
|
?>
|
||||||
<?php
|
<tr>
|
||||||
}
|
<td width="150"><?php echo($data['username']); ?></td>
|
||||||
?>
|
<td width="85"><a onclick="codiad.user.password('<?php echo($data['username']); ?>');" class="icon-flashlight bigger-icon"></a></td>
|
||||||
</table>
|
<?php
|
||||||
</div>
|
|
||||||
</div>
|
if( $admin ) {
|
||||||
<button class="btn-left" onclick="codiad.user.createNew();"><?php i18n("New Account"); ?></button>
|
|
||||||
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Close"); ?></button>
|
?>
|
||||||
<?php
|
<td width="75">
|
||||||
}
|
<select onchange="codiad.user.update_access( event, '<?php echo( $data['username'] ); ?>' )">
|
||||||
|
<?php
|
||||||
break;
|
foreach( User::ACCESS as $role ) {
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
?>
|
||||||
// Create New User
|
<option value="<?php echo $role;?>" <?php if( $data["access"] == $role ) { echo 'selected="selected"'; }?>><?php echo i18n( $role );?></option>
|
||||||
//////////////////////////////////////////////////////////////////////
|
<?php
|
||||||
|
}
|
||||||
case 'create':
|
?>
|
||||||
|
</select>
|
||||||
?>
|
</td>
|
||||||
<form>
|
<?php
|
||||||
<label><?php i18n("Username"); ?></label>
|
}
|
||||||
<input type="text" name="username" autofocus="autofocus" autocomplete="off">
|
|
||||||
<label><?php i18n("Password"); ?></label>
|
if( $_SESSION['user'] == $data['username'] ) {
|
||||||
<input type="password" name="password1">
|
|
||||||
<label><?php i18n("Confirm Password"); ?></label>
|
?>
|
||||||
<input type="password" name="password2">
|
<td width="75"><a onclick="codiad.message.error('You Cannot Delete Your Own Account');" class="icon-block bigger-icon"></a></td>
|
||||||
<button class="btn-left"><?php i18n("Create Account"); ?></button>
|
<?php
|
||||||
|
} else {
|
||||||
|
|
||||||
|
?>
|
||||||
|
<td width="70"><a onclick="codiad.user.delete('<?php echo($data['username']); ?>');" class="icon-cancel-circled bigger-icon"></a></td>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button class="btn-left" onclick="codiad.user.createNew();"><?php i18n("New Account"); ?></button>
|
||||||
|
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Close"); ?></button>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// Create New User
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
case 'create':
|
||||||
|
|
||||||
|
?>
|
||||||
|
<form>
|
||||||
|
<label><?php i18n("Username"); ?></label>
|
||||||
|
<input type="text" name="username" autofocus="autofocus" autocomplete="off">
|
||||||
|
<label><?php i18n("Password"); ?></label>
|
||||||
|
<input type="password" name="password1">
|
||||||
|
<label><?php i18n("Confirm Password"); ?></label>
|
||||||
|
<input type="password" name="password2">
|
||||||
|
<button class="btn-left"><?php i18n("Create Account"); ?></button>
|
||||||
<button class="btn-right" onclick="codiad.user.list();return false;"><?php i18n("Cancel"); ?></button>
|
<button class="btn-right" onclick="codiad.user.list();return false;"><?php i18n("Cancel"); ?></button>
|
||||||
<form>
|
<form>
|
||||||
<?php
|
<?php
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Delete User
|
// Delete User
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
case 'delete':
|
case 'delete':
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<form>
|
<form>
|
||||||
<input type="hidden" name="username" value="<?php echo($_GET['username']); ?>">
|
<input type="hidden" name="username" value="<?php echo($_GET['username']); ?>">
|
||||||
<label><?php i18n("Confirm User Deletion"); ?></label>
|
<label><?php i18n("Confirm User Deletion"); ?></label>
|
||||||
<pre><?php i18n("Account:"); ?> <?php echo($_GET['username']); ?></pre>
|
<pre><?php i18n("Account:"); ?> <?php echo($_GET['username']); ?></pre>
|
||||||
<button class="btn-left"><?php i18n("Confirm"); ?></button>
|
<button class="btn-left"><?php i18n("Confirm"); ?></button>
|
||||||
<button class="btn-right" onclick="codiad.user.list();return false;"><?php i18n("Cancel"); ?></button>
|
<button class="btn-right" onclick="codiad.user.list();return false;"><?php i18n("Cancel"); ?></button>
|
||||||
<div class="loading"></div>
|
<div class="loading"></div>
|
||||||
<?php
|
<?php
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Change Password
|
// Change Password
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
case 'password':
|
case 'password':
|
||||||
|
|
||||||
if($_GET['username']=='undefined'){
|
if( $_GET['username'] == 'undefined' ) {
|
||||||
$username = $_SESSION['user'];
|
|
||||||
}else{
|
$username = $_SESSION['user'];
|
||||||
$username = $_GET['username'];
|
} else {
|
||||||
}
|
$username = $_GET['username'];
|
||||||
|
}
|
||||||
?>
|
|
||||||
<form>
|
?>
|
||||||
<input type="hidden" name="username" value="<?php echo($username); ?>">
|
<form>
|
||||||
<label><?php i18n("New Password"); ?></label>
|
<input type="hidden" name="username" value="<?php echo($username); ?>">
|
||||||
<input type="password" name="password1" autofocus="autofocus">
|
<label><?php i18n("New Password"); ?></label>
|
||||||
<label><?php i18n("Confirm Password"); ?></label>
|
<input type="password" name="password1" autofocus="autofocus">
|
||||||
<input type="password" name="password2">
|
<label><?php i18n("Confirm Password"); ?></label>
|
||||||
<button class="btn-left"><?php i18n("Change %{username}%'s Password", array("username" => ucfirst($username))) ?></button>
|
<input type="password" name="password2">
|
||||||
|
<button class="btn-left"><?php i18n("Change %{username}%'s Password", array("username" => ucfirst($username))) ?></button>
|
||||||
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Cancel"); ?></button>
|
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Cancel"); ?></button>
|
||||||
<?php
|
<?php
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -1,251 +1,282 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
|
* Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
|
||||||
* as-is and without warranty under the MIT License. See
|
* as-is and without warranty under the MIT License. See
|
||||||
* [root]/license.txt for more. This information must remain intact.
|
* [root]/license.txt for more. This information must remain intact.
|
||||||
*/
|
*/
|
||||||
|
(function(global, $) {
|
||||||
(function(global, $){
|
|
||||||
|
var codiad = global.codiad;
|
||||||
var codiad = global.codiad;
|
|
||||||
|
$(function() {
|
||||||
$(function() {
|
codiad.user.init();
|
||||||
codiad.user.init();
|
});
|
||||||
});
|
|
||||||
|
codiad.user = {
|
||||||
codiad.user = {
|
|
||||||
|
loginForm: $('#login'),
|
||||||
loginForm: $('#login'),
|
controller: 'components/user/controller.php',
|
||||||
controller: 'components/user/controller.php',
|
dialog: 'components/user/dialog.php',
|
||||||
dialog: 'components/user/dialog.php',
|
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////
|
// Initilization
|
||||||
// Initilization
|
//////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
|
init: async function() {
|
||||||
init: async function() {
|
var _this = this;
|
||||||
var _this = this;
|
this.loginForm.on('submit', function(e) {
|
||||||
this.loginForm.on('submit', function(e) {
|
e.preventDefault();
|
||||||
e.preventDefault();
|
_this.authenticate();
|
||||||
_this.authenticate();
|
});
|
||||||
});
|
|
||||||
|
// Get Theme
|
||||||
// Get Theme
|
if(codiad.settings !== undefined) {
|
||||||
if( codiad.settings !== undefined ) {
|
|
||||||
|
var theme = await codiad.settings.get_option('codiad.theme');
|
||||||
var theme = await codiad.settings.get_option( 'codiad.theme' );
|
} else {
|
||||||
} else {
|
|
||||||
|
var theme = 'default';
|
||||||
var theme = 'default';
|
}
|
||||||
}
|
$("#theme option").each(function() {
|
||||||
$("#theme option").each(function()
|
if($(this).val() == theme) {
|
||||||
{
|
$(this).attr("selected", "selected");
|
||||||
if($(this).val() == theme) {
|
}
|
||||||
$(this).attr("selected","selected");
|
});
|
||||||
}
|
|
||||||
});
|
// Get Language
|
||||||
|
if(codiad.settings !== undefined) {
|
||||||
// Get Language
|
|
||||||
if( codiad.settings !== undefined ) {
|
var language = await codiad.settings.get_option('codiad.language');
|
||||||
|
} else {
|
||||||
var language = await codiad.settings.get_option('codiad.language');
|
|
||||||
} else {
|
var language = 'en';
|
||||||
|
}
|
||||||
var language = 'en';
|
|
||||||
}
|
$("#language option").each(function() {
|
||||||
|
if($(this).val() == language) {
|
||||||
$("#language option").each(function()
|
$(this).attr("selected", "selected");
|
||||||
{
|
}
|
||||||
if($(this).val() == language) {
|
});
|
||||||
$(this).attr("selected","selected");
|
|
||||||
}
|
// More Selector
|
||||||
});
|
$('.show-language-selector').click(function() {
|
||||||
|
$(this).hide();
|
||||||
// More Selector
|
$('.language-selector').animate({
|
||||||
$('.show-language-selector').click(function(){
|
height: 'toggle'
|
||||||
$(this).hide();
|
}, "fast");
|
||||||
$('.language-selector').animate({height:'toggle'}, "fast");
|
});
|
||||||
});
|
},
|
||||||
},
|
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////
|
// Authenticate User
|
||||||
// Authenticate User
|
//////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
|
authenticate: function() {
|
||||||
authenticate: function() {
|
$.post(this.controller + '?action=authenticate', this.loginForm.serialize(), function(data) {
|
||||||
$.post(this.controller + '?action=authenticate', this.loginForm.serialize(), function(data) {
|
parsed = codiad.jsend.parse(data);
|
||||||
parsed = codiad.jsend.parse(data);
|
if(parsed != 'error') {
|
||||||
if (parsed != 'error') {
|
// Session set, reload
|
||||||
// Session set, reload
|
window.location.reload();
|
||||||
window.location.reload();
|
}
|
||||||
}
|
});
|
||||||
});
|
},
|
||||||
},
|
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////
|
// Logout
|
||||||
// Logout
|
//////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
|
logout: function() {
|
||||||
logout: function() {
|
var forcelogout = true;
|
||||||
var forcelogout = true;
|
if($('#list-active-files li.changed').length > 0) {
|
||||||
if ($('#list-active-files li.changed').length > 0) {
|
forcelogout = confirm(i18n('You have unsaved files.'));
|
||||||
forcelogout = confirm(i18n('You have unsaved files.'));
|
}
|
||||||
}
|
if(forcelogout) {
|
||||||
if(forcelogout) {
|
$('#list-active-files li.changed').each(function() {
|
||||||
$('#list-active-files li.changed').each(function () { $(this).removeClass('changed')});
|
$(this).removeClass('changed')
|
||||||
amplify.publish('user.logout', {});
|
});
|
||||||
codiad.settings.save();
|
amplify.publish('user.logout', {});
|
||||||
$.get(this.controller + '?action=logout', function() {
|
codiad.settings.save();
|
||||||
window.location.reload();
|
$.get(this.controller + '?action=logout', function() {
|
||||||
});
|
window.location.reload();
|
||||||
}
|
});
|
||||||
},
|
}
|
||||||
|
},
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
// Open the user manager dialog
|
//////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////
|
// Open the user manager dialog
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
list: function() {
|
|
||||||
$('#modal-content form')
|
list: function() {
|
||||||
.die('submit'); // Prevent form bubbling
|
$('#modal-content form')
|
||||||
codiad.modal.load(400, this.dialog + '?action=list');
|
.die('submit'); // Prevent form bubbling
|
||||||
},
|
codiad.modal.load(600, this.dialog + '?action=list');
|
||||||
|
},
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
// Create User
|
//////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////
|
// Create User
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
createNew: function() {
|
|
||||||
var _this = this;
|
createNew: function() {
|
||||||
codiad.modal.load(400, this.dialog + '?action=create');
|
var _this = this;
|
||||||
$('#modal-content form')
|
codiad.modal.load(400, this.dialog + '?action=create');
|
||||||
.live('submit', function(e) {
|
$('#modal-content form')
|
||||||
e.preventDefault();
|
.live('submit', function(e) {
|
||||||
var pass = true;
|
e.preventDefault();
|
||||||
var username = $('#modal-content form input[name="username"]')
|
var pass = true;
|
||||||
.val();
|
var username = $('#modal-content form input[name="username"]')
|
||||||
var password1 = $('#modal-content form input[name="password1"]')
|
.val();
|
||||||
.val();
|
var password1 = $('#modal-content form input[name="password1"]')
|
||||||
var password2 = $('#modal-content form input[name="password2"]')
|
.val();
|
||||||
.val();
|
var password2 = $('#modal-content form input[name="password2"]')
|
||||||
|
.val();
|
||||||
// Check matching passwords
|
|
||||||
if (password1 != password2) {
|
// Check matching passwords
|
||||||
codiad.message.error(i18n('Passwords Do Not Match'));
|
if(password1 != password2) {
|
||||||
pass = false;
|
codiad.message.error(i18n('Passwords Do Not Match'));
|
||||||
}
|
pass = false;
|
||||||
|
}
|
||||||
// Check no spaces in username
|
|
||||||
if (!/^[a-z0-9]+$/i.test(username) || username.length===0) {
|
// Check no spaces in username
|
||||||
codiad.message.error(i18n('Username Must Be Alphanumeric String'));
|
if(!/^[a-z0-9]+$/i.test(username) || username.length === 0) {
|
||||||
pass = false;
|
codiad.message.error(i18n('Username Must Be Alphanumeric String'));
|
||||||
}
|
pass = false;
|
||||||
|
}
|
||||||
if (pass) {
|
|
||||||
$.post(_this.controller + '?action=create', {'username' : username , 'password' : password1 }, function(data) {
|
if(pass) {
|
||||||
var createResponse = codiad.jsend.parse(data);
|
$.post(_this.controller + '?action=create', {
|
||||||
if (createResponse != 'error') {
|
'username': username,
|
||||||
codiad.message.success(i18n('User Account Created'))
|
'password': password1
|
||||||
_this.list();
|
}, function(data) {
|
||||||
}
|
var createResponse = codiad.jsend.parse(data);
|
||||||
});
|
if(createResponse != 'error') {
|
||||||
}
|
codiad.message.success(i18n('User Account Created'))
|
||||||
});
|
_this.list();
|
||||||
},
|
}
|
||||||
|
});
|
||||||
//////////////////////////////////////////////////////////////////
|
}
|
||||||
// Delete User
|
});
|
||||||
//////////////////////////////////////////////////////////////////
|
},
|
||||||
|
|
||||||
delete: function(username) {
|
//////////////////////////////////////////////////////////////////
|
||||||
var _this = this;
|
// Delete User
|
||||||
codiad.modal.load(400, this.dialog + '?action=delete&username=' + username);
|
//////////////////////////////////////////////////////////////////
|
||||||
$('#modal-content form')
|
|
||||||
.live('submit', function(e) {
|
delete: function(username) {
|
||||||
e.preventDefault();
|
var _this = this;
|
||||||
var username = $('#modal-content form input[name="username"]')
|
codiad.modal.load(400, this.dialog + '?action=delete&username=' + username);
|
||||||
.val();
|
$('#modal-content form')
|
||||||
codiad.modal.show_loading();
|
.live('submit', function(e) {
|
||||||
$.get(_this.controller + '?action=delete&username=' + username, function(data) {
|
e.preventDefault();
|
||||||
var deleteResponse = codiad.jsend.parse(data);
|
var username = $('#modal-content form input[name="username"]')
|
||||||
if (deleteResponse != 'error') {
|
.val();
|
||||||
codiad.message.success(i18n('Account Deleted'))
|
codiad.modal.show_loading();
|
||||||
_this.list();
|
$.get(_this.controller + '?action=delete&username=' + username, function(data) {
|
||||||
}
|
var deleteResponse = codiad.jsend.parse(data);
|
||||||
});
|
if(deleteResponse != 'error') {
|
||||||
});
|
codiad.message.success(i18n('Account Deleted'))
|
||||||
},
|
_this.list();
|
||||||
|
}
|
||||||
//////////////////////////////////////////////////////////////////
|
});
|
||||||
// Set Project Access
|
});
|
||||||
//////////////////////////////////////////////////////////////////
|
},
|
||||||
|
|
||||||
projects: function(username) {
|
//////////////////////////////////////////////////////////////////
|
||||||
codiad.modal.load(400, this.dialog + '?action=projects&username=' + username);
|
// Set Project Access
|
||||||
var _this = this;
|
//////////////////////////////////////////////////////////////////
|
||||||
$('#modal-content form')
|
|
||||||
.live('submit', function(e) {
|
projects: function(username) {
|
||||||
e.preventDefault();
|
codiad.modal.load(400, this.dialog + '?action=projects&username=' + username);
|
||||||
var username = $('#modal-content form input[name="username"]')
|
var _this = this;
|
||||||
.val();
|
$('#modal-content form')
|
||||||
var accessLevel = $('#modal-content form select[name="access_level"]')
|
.live('submit', function(e) {
|
||||||
.val();
|
e.preventDefault();
|
||||||
var projects = new Array();
|
var username = $('#modal-content form input[name="username"]')
|
||||||
$('input:checkbox[name="project"]:checked').each(function(){
|
.val();
|
||||||
projects.push($(this).val());
|
var accessLevel = $('#modal-content form select[name="access_level"]')
|
||||||
});
|
.val();
|
||||||
if(accessLevel==0){ projects = 0; }
|
var projects = new Array();
|
||||||
// Check and make sure if access level not full that at least on project is selected
|
$('input:checkbox[name="project"]:checked').each(function() {
|
||||||
if (accessLevel==1 && !projects) {
|
projects.push($(this).val());
|
||||||
codiad.message.error(i18n('At Least One Project Must Be Selected'));
|
});
|
||||||
} else {
|
if(accessLevel == 0) {
|
||||||
$.post(_this.controller + '?action=project_access&username=' + username,{projects: projects}, function(data) {
|
projects = 0;
|
||||||
var projectsResponse = codiad.jsend.parse(data);
|
}
|
||||||
if (projectsResponse != 'error') {
|
// Check and make sure if access level not full that at least on project is selected
|
||||||
codiad.message.success(i18n('Account Modified'));
|
if(accessLevel == 1 && !projects) {
|
||||||
}
|
codiad.message.error(i18n('At Least One Project Must Be Selected'));
|
||||||
});
|
} else {
|
||||||
}
|
$.post(_this.controller + '?action=project_access&username=' + username, {
|
||||||
});
|
projects: projects
|
||||||
},
|
}, function(data) {
|
||||||
|
var projectsResponse = codiad.jsend.parse(data);
|
||||||
//////////////////////////////////////////////////////////////////
|
if(projectsResponse != 'error') {
|
||||||
// Change Password
|
codiad.message.success(i18n('Account Modified'));
|
||||||
//////////////////////////////////////////////////////////////////
|
}
|
||||||
|
});
|
||||||
password: function(username) {
|
}
|
||||||
var _this = this;
|
});
|
||||||
codiad.modal.load(400, this.dialog + '?action=password&username=' + username);
|
},
|
||||||
$('#modal-content form')
|
|
||||||
.live('submit', function(e) {
|
//////////////////////////////////////////////////////////////////
|
||||||
e.preventDefault();
|
// Change Password
|
||||||
var username = $('#modal-content form input[name="username"]')
|
//////////////////////////////////////////////////////////////////
|
||||||
.val();
|
|
||||||
var password1 = $('#modal-content form input[name="password1"]')
|
password: function(username) {
|
||||||
.val();
|
var _this = this;
|
||||||
var password2 = $('#modal-content form input[name="password2"]')
|
codiad.modal.load(400, this.dialog + '?action=password&username=' + username);
|
||||||
.val();
|
$('#modal-content form')
|
||||||
if (password1 != password2) {
|
.live('submit', function(e) {
|
||||||
codiad.message.error(i18n('Passwords Do Not Match'));
|
e.preventDefault();
|
||||||
} else {
|
var username = $('#modal-content form input[name="username"]')
|
||||||
$.post(_this.controller + '?action=password', {'username' : username , 'password' : password1 }, function(data) {
|
.val();
|
||||||
var passwordResponse = codiad.jsend.parse(data);
|
var password1 = $('#modal-content form input[name="password1"]')
|
||||||
if (passwordResponse != 'error') {
|
.val();
|
||||||
codiad.message.success(i18n('Password Changed'));
|
var password2 = $('#modal-content form input[name="password2"]')
|
||||||
codiad.modal.unload();
|
.val();
|
||||||
}
|
if(password1 != password2) {
|
||||||
});
|
codiad.message.error(i18n('Passwords Do Not Match'));
|
||||||
}
|
} else {
|
||||||
});
|
$.post(_this.controller + '?action=password', {
|
||||||
},
|
'username': username,
|
||||||
|
'password': password1
|
||||||
//////////////////////////////////////////////////////////////////
|
}, function(data) {
|
||||||
// Change Current Project
|
var passwordResponse = codiad.jsend.parse(data);
|
||||||
//////////////////////////////////////////////////////////////////
|
if(passwordResponse != 'error') {
|
||||||
|
codiad.message.success(i18n('Password Changed'));
|
||||||
project: function(project) {
|
codiad.modal.unload();
|
||||||
$.get(this.controller + '?action=project&project=' + project);
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
};
|
});
|
||||||
|
},
|
||||||
})(this, jQuery);
|
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
// Change Current Project
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
project: function(project) {
|
||||||
|
$.get(this.controller + '?action=project&project=' + project);
|
||||||
|
},
|
||||||
|
|
||||||
|
update_access: function( e, username=null ) {
|
||||||
|
|
||||||
|
let access = "";
|
||||||
|
|
||||||
|
if( ( typeof e ) == "string" ) {
|
||||||
|
|
||||||
|
access = e;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
access = e.target.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.get( this.controller + `?action=update_access&username=${username}&access=${access}`, function( data ) {
|
||||||
|
|
||||||
|
let response = codiad.jsend.parse( data );
|
||||||
|
if( response != 'error' ) {
|
||||||
|
|
||||||
|
codiad.message.success( i18n( 'Access Updated' ) );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
})(this, jQuery);
|
||||||
|
|
Loading…
Reference in a new issue