Skip to content

Commit c8fb09d

Browse files
committed
fix: UI-Login
Fixed the user Login and Update password page. First time users can login using Admin/Admin and then change password and username. Signed-off-by: Salisu Ali <[email protected]>
1 parent bdf73e4 commit c8fb09d

2 files changed

Lines changed: 20 additions & 31 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## First Time Login
2+
When Login for the very first time, The default Login is ```Admin/Admin```. This login credentials cannot be used to make modifications in ZEBRA, so The user will automatically be redirected to UPDATE Password page.
3+
4+
## Update Password
5+
The user will need to Update his password using this page. As for user name, The user can choose any username of his choice. The user is also expected to provide access token and refresh token secrets of his choice.
6+
7+
## Restart ZEBRA
8+
The user will need to restart ZEBRA before the new login credentials can be used
9+
10+
## Error
11+
This error occurs when ZEBRA redirects user to /undefined. This happens when ZEBRA cannot find the redirect URL after login. The user can simply go back to the homepage and try login in again.

src/Auth.js

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,6 @@ let dbrefresh = nedb.dbrefresh;
77
var fs = require('fs'); //importing the fs module
88
//var Zconfig = require("./config/");
99

10-
/*function parameters(fn){
11-
parms = {
12-
ddsbaseurl: Zconfig.ddsbaseurl,
13-
ddsbaseport: Zconfig.ddsbaseport,
14-
rmf3filename: Zconfig.rmf3filename,
15-
rmfppfilename: Zconfig.rmfppfilename,
16-
mvsResource: Zconfig.mvsResource,
17-
mongourl: Zconfig.mongourl,
18-
dbinterval: Zconfig.dbinterval,
19-
dbname: Zconfig.dbname,
20-
appurl: Zconfig.appurl,
21-
appport: Zconfig.appport,
22-
mongoport: Zconfig.mongoport,
23-
ppminutesInterval: Zconfig.ppminutesInterval,
24-
rmf3interval: Zconfig.rmf3interval,
25-
httptype: Zconfig.httptype,
26-
useDbAuth: Zconfig.useDbAuth,
27-
dbUser: Zconfig.dbUser,
28-
dbPassword: Zconfig.dbPassword,
29-
authSource: Zconfig.authSource,
30-
useMongo: Zconfig.useMongo,
31-
usePrometheus: Zconfig.usePrometheus,
32-
https: Zconfig.https,
33-
grafanaurl: Zconfig.grafanaurl,
34-
grafanaport: Zconfig.grafanaport
35-
}
36-
fn(parms);
37-
}*/
3810

3911
//Update Password REST API
4012
module.exports.updatePassword = async function(req, res){
@@ -52,7 +24,7 @@ module.exports.updatePassword = async function(req, res){
5224
const Salt = bcrypt.genSaltSync()
5325
const hashedpassword = bcrypt.hashSync(newpassword, Salt)
5426
//const user = {name: data.name, password: hashedpassword}
55-
db.update({ password: user.password }, {$set: { password: hashedpassword}}, {}, function (err, numReplaced) {
27+
db.update({ name: user.password }, {$set: { password: hashedpassword}}, {}, function (err, numReplaced) {
5628
if(err){
5729
res.status(201).send("Error");
5830
} else {
@@ -284,7 +256,13 @@ function wenv(act, rft, fn){ //write to .env file
284256
//Update Paasword Form
285257
module.exports.updatePasswordForm = async function(req, res){
286258
db.find({ }, async function (err, users) {
287-
const user = users.find(user => user.name == req.body.name)
259+
var user = null;
260+
if(req.body.name != "Admin"){
261+
user = users.find(user => user.name == "Admin")
262+
}
263+
if(user == null){
264+
user = users.find(user => user.name == req.body.name)
265+
}
288266
username = req.body.name;
289267
oldpassword = 'Admin';
290268
newpassword = req.body.newpassword;
@@ -301,7 +279,7 @@ module.exports.updatePasswordForm = async function(req, res){
301279
//Update ENV here
302280
wenv(req.body.act, req.body.rft, function(data){
303281
if(data === "Success"){
304-
db.update({ password: user.password }, {$set: { password: hashedpassword}}, {}, function (err, numReplaced) {
282+
db.update({ name: user.name }, {$set: { password: hashedpassword, name:req.body.name}}, {}, function (err, numReplaced) {
305283
if(err){
306284
res.render("login", {data: "pwd"})
307285
} else {

0 commit comments

Comments
 (0)