Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional access #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* Module dependencies.
*/
Expand Down Expand Up @@ -49,7 +48,8 @@ var express = require('express')
, actionHistory = require('./routes/actionHistory')
, versionControl = require('./routes/versionControl')
, syncIDE = require('./routes/syncIDE')
, testcaseHistory = require('./routes/testcaseHistory');
, testcaseHistory = require('./routes/testcaseHistory')
, remoteexecution = require('./routes/remoteexecution');

var realFs = require("fs");
var gracefulFs = require("graceful-fs");
Expand Down Expand Up @@ -164,6 +164,9 @@ app.post('/variableTags',auth.auth, variableTags.variableTagsPost);
//start execution
app.post('/executionengine/startexecution', executionengine.startexecutionPost);

// remote execution
app.get('/api/remoteexecution/startexecution', remoteexecution.startexecutionPost);

//stop
app.post('/executionengine/stopexecution',auth.auth, executionengine.stopexecutionPost);
app.post('/executionengine/actionresult',executionengine.actionresultPost);
Expand Down
7 changes: 6 additions & 1 deletion public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Ext.application({
var mainTab = Ext.ComponentQuery.query('#mainTabPanel')[0];
if(Ext.util.Cookies.get('role') == "Test Designer"){
mainTab.remove(mainTab.down("#adminTab"));
//dev changes user specific access
//mainTab.remove(mainTab.down("#ScriptBrowser"));
mainTab.down("scriptBrowser").down("#compileBar").hide();
mainTab.down("scriptBrowser").down("#saveAll").hide();
mainTab.down("scriptBrowser").down("#push").hide();
Expand All @@ -23,7 +25,10 @@ Ext.application({
mainTab.down("actions").down("#deleteAction").hide();
mainTab.down("actions").down("#cloneAction").hide();
mainTab.down("actions").down("#newAction").hide();
}
//dev changes
} else if(Ext.util.Cookies.get('role') == "Developer") {
mainTab.remove(mainTab.down("#adminTab"));
} //dev changes
},

controllers: [
Expand Down
9 changes: 9 additions & 0 deletions public/controller/Executions.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,15 @@ Ext.define("Redwood.controller.Executions", {
executionView.up("executionsEditor").down("#runExecution").setDisabled(false);
executionView.up("executionsEditor").down("#stopExecution").setDisabled(true);
}
},
failure: function(response) {
if (Ext.MessageBox.isVisible()) Ext.MessageBox.hide();
var obj = Ext.decode(response.responseText);
if(obj.error != null){
Ext.Msg.alert('Error', Ext.util.Format.htmlEncode(obj.error));
executionView.up("executionsEditor").down("#runExecution").setDisabled(false);
executionView.up("executionsEditor").down("#stopExecution").setDisabled(true);
}
}
});
})
Expand Down
7 changes: 7 additions & 0 deletions public/model/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ Ext.define('Redwood.model.Users', {
}, {
name: 'status',
type: 'string'
},
//dev changes
{
name: 'projects',
type: 'array'
}
//dev changes

]
});
35 changes: 34 additions & 1 deletion public/view/UserEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ Ext.define('Redwood.view.UserEdit', {
var newUser = {};
newUser.name = form.getFieldValues().name;
newUser.tag = form.getFieldValues().tag;
//dev changes
newUser.projects = form.getFieldValues().projects;
//dev changes
newUser.password = form.getFieldValues().firstpassword;
newUser.username = form.getFieldValues().username;
newUser.email = form.getFieldValues().email;
Expand Down Expand Up @@ -208,7 +211,37 @@ Ext.define('Redwood.view.UserEdit', {
}
}
}
}
},
//dev changes
{
xtype:"combofieldbox",
afterLabelTextTpl: this.requiredText,
fieldLabel: 'Projects',
displayField:"name",
descField:"name",
height:24,
labelWidth: 100,
forceSelection:false,
createNewOnEnter:false,
encodeSubmitValue:true,
autoSelect: false,
triggerAction: 'all',
store:Ext.data.StoreManager.lookup('Projects'),
valueField:"_id",
queryMode: 'local',
removeOnDblClick:true,
allowBlank: false,
maskRe: /[a-z_0-9_A-Z_-]/,
name:"projects",
listeners: {
specialkey: function(field, e){
if (e.getKey() == e.ENTER) {
this.up('form').down("#submit").handler();
}
}
}
}
//dev changes
,{
xtype:'textfield',
vtype: 'passwordTest',
Expand Down
95 changes: 66 additions & 29 deletions routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var sessions = {};
var projects = require('../routes/projects');
var userState = require('../routes/userStates');
var realtime = require("./realtime");
var common = require('../common');

exports.loginPage = function(req,res){
res.redirect('/login.html');
Expand All @@ -22,17 +23,27 @@ exports.loadSessions = function(){
};

exports.logIn = function (req,res,next){
verifyUser(req.body.username,req.body.password,function(userFound,role){
verifyUser(req.body.username,req.body.password,function(userFound,user){
console.log(user);
//common.logger.info("projects",user.projects[0]);
if (userFound){
require('crypto').randomBytes(20, function(ex, buf) {
realtime.emitMessage("Login",req.body.username);
var token = buf.toString('hex');
sessions[req.body.username] = {sessionid:token,expires:new Date(Date.now() + 2592000000),role:role};
console.log("role:", user.role);
common.logger.info("login projects", user.projects);
sessions[req.body.username] = {sessionid:token,expires:new Date(Date.now() + 2592000000),role:user.role, userId:user._id, projects:user.projects};
storeSession(req.body.username,token,new Date(Date.now() + 2592000000));
res.cookie('sessionid', token, { expires: new Date(Date.now() + 2592000000), httpOnly: false});
res.cookie('username', req.body.username, {maxAge: 2592000000, httpOnly: false });
res.cookie('role', role, {maxAge: 2592000000, httpOnly: false });
res.cookie('role', user.role, {maxAge: 2592000000, httpOnly: false });
res.cookie('userId', user._id, {maxAge: 2592000000, httpOnly: false });
if (user.role !== 'Admin') {
res.cookie('projects', user.projects, {maxAge: 2592000000, httpOnly: false });
res.cookie('userDefaultProject', user.projects[0], {maxAge: 2592000000, httpOnly: false });
}
return next();

});
}
else{
Expand All @@ -43,57 +54,83 @@ exports.logIn = function (req,res,next){

function logInSucess(req,res){
userState.GetUserProject(req.cookies.username,function(project){
console.log("######################################");
console.log(res);
var roleField = res.get("set-cookie")[2].split(";");
var userRole = roleField[0].split("=")[1];

if(userRole !== 'Admin') {
var projectField = res.get("set-cookie")[5].split(";");
var defaultProjectID = projectField[0].split("=")[1];
}
//common.logger.info("cookie projects string", defaultProjectID);
//common.logger.info("cookie userRole string", userRole);
//common.logger.info("cookie projects", res.get("set-cookie")[3].indexOf("="));
//common.logger.info("cookie projects length", res.get("set-cookie")[3].length);
//common.logger.info("cookie projects typeod", typeof res.get("set-cookie")[3]);
//common.logger.info("user projects", req.cookies.projects[0]);
//common.logger.info("resp project", project);
//common.logger.info("cookie project",req.cookies.project);
//var userDefaultProject = req.cookies.projects[0];
if(req.cookies.deeplink){
common.logger.info("at if logic");
res.clearCookie('deeplink');
if(req.originalUrl != "/index.html"){
res.json({error:null,redirect:req.cookies.deeplink});
}
else{
res.json({error:null,redirect:"./index.html"});
}
}
else if ((project == null) && ((req.cookies.project === undefined)||(req.cookies.project == "") )){
common.logger.info("resp project", project);
projects.allProjects(function(projects){
res.cookie('project', projects[0].name, {maxAge: 2592000000, httpOnly: false });
res.redirect("/index.html");
// res.json({error:null,redirect:"./index.html"});
if(userRole !== "Admin") {
projects.forEach(function(project){
common.logger.info("project name if logic", project._id.toString());
if (project._id.toString() == defaultProjectID){
res.cookie('project', project.name, {maxAge: 2592000000, httpOnly: false });
}
});
} else {
res.cookie('project', projects[0].name, {maxAge: 2592000000, httpOnly: false });
}
if(req.originalUrl != "/index.html"){
res.json({error:null,redirect:"./index.html"});
}
else{
res.json({error:null,redirect:"./index.html"});
}
});
}
else if (project == null){
else if ((project == null) || (req.cookies.project === undefined) || (req.cookies.project == "")){
common.logger.info("at else logic");
projects.allProjects(function(projects){
var found = false;
projects.forEach(function(project){
if (project.name === req.cookies.project){
found = true;
}
});
if (found == false){
if(userRole !== "Admin") {
projects.forEach(function(project){
if (project._id.toString() == defaultProjectID){
found = true;
res.cookie('project', project.name, {maxAge: 2592000000, httpOnly: false });
}
});
} else {
res.cookie('project', projects[0].name, {maxAge: 2592000000, httpOnly: false });
}

res.json({error:null,redirect:"./index.html"});
});
}
else{
if ((req.cookies.project === undefined)||(req.cookies.project == "")){
res.cookie('project', project, {maxAge: 2592000000, httpOnly: false });
}
res.json({error:null,redirect:"./index.html"});
}
})
}
exports.logInSucess = function(req,res){
logInSucess(req,res)
};

exports.auth = function(req,res,next){
//common.logger.info("Original url", req.originalUrl);
if (sessions[req.cookies.username] != undefined){
if (req.cookies.sessionid == sessions[req.cookies.username].sessionid){
if (req.cookies.project == undefined){
if(req.originalUrl == "/index.html"){
common.logger.info("Original url", req.originalUrl);
res.cookie('deeplink', req.originalUrl, {maxAge: 2592000000, httpOnly: false });
return next();
}
else{
common.logger.info("Original url", req.originalUrl);
logInSucess(req,res);
return;
}
Expand Down Expand Up @@ -139,8 +176,8 @@ function verifyUser(username,password,callback){
callback(false,null);
}
else{
callback(true,user.role);
callback(true,user);
}
});
})
}
}
Loading