Browse Source

Updated site so non-admin users can edit their own profiles.

pull/6/head
jrtechs 5 years ago
parent
commit
9600d4bc4a
5 changed files with 78 additions and 6 deletions
  1. +16
    -1
      README.MD
  2. +31
    -2
      html/users.html
  3. BIN
      img/404.jpg
  4. +22
    -2
      server.js
  5. +9
    -1
      user.js

+ 16
- 1
README.MD View File

@ -21,5 +21,20 @@ npm install express --save
npm install fs --save
npm install express-session --save
npm install whiskers --save
```
```
Codacs which don't work
H.265
MPEG-2 Video AC-3 (ATSC A/52)
Video but no audio
H.264 audio:AC-3 (ATSC A/52)
H.264 (Main Profile) AC-3 (ATSC A/52)
Audio but no video:
H.265 (Main 10 Profile) MPEG-4 AAC
just work:
H.264 (High Profile), MPEG-4 AAC

+ 31
- 2
html/users.html View File

@ -8,7 +8,6 @@
</script>
<div id="editUserBox" class="row" style="display:none">
<!-- Edit User -->
<div class="col-md-6">
<div class="card">
@ -121,5 +120,35 @@
</div>
</div>
{else}
This is an admin page.
{if loggedIn}
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h3 class="text-center">Update Profile</h3>
</div>
<div class="card-body">
<form action="/updateUser" method ="post" class="p-2">
<div class="form-group">
<input class="form-control" id="usernameLabel" type="text" name="username" value="{username}" required>
<label>User Name</label>
</div>
<div class="form-group">
<input class="form-control" type="password" name="password" required>
<label>Password</label>
</div>
<div class="text-center">
<input type="submit" name="Update Profile" value="Update User"
class="btn btn-lg btn-secondary"/>
</div>
</form>
</div>
</div>
<br>
</div>
{else}
<h1 class="align-content-center">Login Required</h1>
<div class="align-content-center">
<img src="/includes/img/404.jpg" alt="Page not found" width="70%" />
</div>
{/if}
{/if}

BIN
img/404.jpg View File

Before After
Width: 690  |  Height: 649  |  Size: 37 KiB

+ 22
- 2
server.js View File

@ -66,6 +66,8 @@ function renderHTML(request, result, templateFile, templateDependencyFunction)
function getUserInformation(templateContext, request)
{
templateContext.users = config.users;
templateContext.id = request.session.userID;
templateContext.username = request.session.username;
}
function getHomePageInformation(templateContext, request)
@ -78,6 +80,7 @@ app.get('/users', (req, res) => renderHTML(req, res, "users.html", getUserInform
app.use(express.static('css'));
app.use(express.static('js'));
app.use(express.static('img'));
app.post('/login', function(request, result)
@ -86,12 +89,11 @@ app.post('/login', function(request, result)
{
request.session.login = true;
request.session.username = request.body.username;
request.session.userID = userUtils.getID(request.body.username, config);
if(userUtils.isAdmin(request.body.username, config))
{
request.session.admin = true;
}
}
result.redirect('/');
});
@ -222,6 +224,24 @@ app.post('/edituser', function(request, result)
}
});
app.post('/updateUser', function(request, result)
{
if(checkPrivilege(request) >= PRIVILEGE.MEMBER)
{
console.log(request.session.userID);
var admin = false;
userUtils.editUser(request.session.userID, request.body.username, request.body.password,admin, config);
fileIO.writeJSONToFile(CONFIG_FILE_NAME, config);
result.redirect('/users');
}
else
{
result.status(401);
result.send('None shall pass');
}
});
const PRIVILEGE = {NOBODY: 0, MEMBER: 1, ADMIN: 2};
const checkPrivilege = function(request)
{

+ 9
- 1
user.js View File

@ -82,6 +82,13 @@ module.exports =
return false;
},
getID: function(username, configuration)
{
var index = getIndexOfUser(username, configuration);
return configuration.users[index].id;
},
/**
* Checks to see if there was a valid login attempt
*
@ -144,8 +151,9 @@ module.exports =
{
for(var i = 0; i < configuration.users.length; i++)
{
if (configuration.users[i].id + "" === id)
if (configuration.users[i].id=== id)
{
console.log("User account updated.");
configuration.users[i].username = userName;
configuration.users[i].admin = admin;

Loading…
Cancel
Save