Skip to content

Commit 6810ff1

Browse files
committed
1 parent e047da1 commit 6810ff1

File tree

9 files changed

+207
-95
lines changed

9 files changed

+207
-95
lines changed

loginSystem/static/loginSystem/login-systen.js

+43-41
Original file line numberDiff line numberDiff line change
@@ -33,73 +33,75 @@ var application = angular.module('loginSystem', []);
3333

3434
application.config(['$interpolateProvider',
3535

36-
function($interpolateProvider) {
36+
function ($interpolateProvider) {
3737
$interpolateProvider.startSymbol('{$');
3838
$interpolateProvider.endSymbol('$}');
3939
}
4040
]);
4141

42-
application.controller('loginSystem', function($scope,$http,$window) {
42+
application.controller('loginSystem', function ($scope, $http, $window) {
4343

44+
$scope.verifyCode = true;
4445

45-
$scope.verifyLoginCredentials = function() {
46+
$scope.verifyLoginCredentials = function () {
4647

47-
$("#verifyingLogin").show();
48+
$("#verifyingLogin").show();
4849

4950

50-
var username = $scope.username;
51-
var password= $scope.password;
52-
var languageSelection= $scope.languageSelection;
51+
var username = $scope.username;
52+
var password = $scope.password;
53+
var languageSelection = $scope.languageSelection;
5354

5455

55-
url = "/verifyLogin";
56+
url = "/verifyLogin";
5657

57-
var data = {
58-
username: username,
59-
password: password,
60-
languageSelection:languageSelection,
61-
};
62-
63-
var config = {
64-
headers : {
65-
'X-CSRFToken': getCookie('csrftoken')
66-
}
67-
};
68-
69-
$http.post(url, data,config).then(ListInitialData, cantLoadInitialData);
58+
var data = {
59+
username: username,
60+
password: password,
61+
languageSelection: languageSelection,
62+
twofa: $scope.twofa
63+
};
7064

65+
var config = {
66+
headers: {
67+
'X-CSRFToken': getCookie('csrftoken')
68+
}
69+
};
7170

72-
function ListInitialData(response) {
71+
$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);
7372

74-
if (response.data.loginStatus === 0)
75-
{
76-
$scope.errorMessage = response.data.error_message;
77-
$("#loginFailed").fadeIn();
78-
}
79-
else{
80-
$("#loginFailed").hide();
81-
$window.location.href = '/base/';
82-
}
8373

74+
function ListInitialData(response) {
8475

76+
if (response.data.loginStatus === 0) {
77+
$scope.errorMessage = response.data.error_message;
78+
$("#loginFailed").fadeIn();
79+
}else if(response.data.loginStatus === 2){
80+
$scope.verifyCode = false;
81+
}
82+
else {
83+
$("#loginFailed").hide();
84+
$window.location.href = '/base/';
85+
}
8586

86-
$("#verifyingLogin").hide();
87-
}
88-
function cantLoadInitialData(response) {}
8987

88+
$("#verifyingLogin").hide();
89+
}
9090

91+
function cantLoadInitialData(response) {
92+
}
9193

9294

93-
};
95+
};
9496

95-
$scope.initiateLogin = function($event){
96-
var keyCode = $event.which || $event.keyCode;
97-
if (keyCode === 13) {
98-
$scope.verifyLoginCredentials();
97+
$scope.initiateLogin = function ($event) {
98+
var keyCode = $event.which || $event.keyCode;
99+
if (keyCode === 13) {
100+
$scope.verifyLoginCredentials();
99101

100-
}
102+
}
101103

102-
};
104+
};
103105

104106

105107
});

loginSystem/templates/loginSystem/login.html

+10
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ <h4 class="text-muted text-center mb-10">Web Hosting Control Panel</h4>
191191
src="{% static 'images/loading.gif' %}">
192192
</div>
193193

194+
<div ng-hide="verifyCode" class="form-group">
195+
<div class="input-group">
196+
<input ng-model="twofa" type="text" class="form-control" name="twofa"
197+
placeholder="Enter code from Google Authenticator" required style="height: 45px;">
198+
<span class="input-group-addon bg-blue">
199+
<i class="glyph-icon icon-unlock-alt"></i>
200+
</span>
201+
</div>
202+
</div>
203+
194204

195205
<div class="form-group">
196206
<div class="input-group">

loginSystem/views.py

+24
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,32 @@ def verifyLogin(request):
9191
json_data = json.dumps(data)
9292
return HttpResponse(json_data)
9393

94+
if admin.twoFA:
95+
try:
96+
twoinit = request.session['twofa']
97+
except:
98+
request.session['twofa'] = 0
99+
data = {'userID': admin.pk, 'loginStatus': 2, 'error_message': "None"}
100+
json_data = json.dumps(data)
101+
response.write(json_data)
102+
return response
103+
104+
105+
94106
if hashPassword.check_password(admin.password, password):
95107

108+
if admin.twoFA:
109+
if request.session['twofa'] == 0:
110+
import pyotp
111+
totp = pyotp.TOTP(admin.secretKey)
112+
del request.session['twofa']
113+
logging.writeToFile(str(totp.now()))
114+
if totp.verify(data['twofa']):
115+
data = {'userID': 0, 'loginStatus': 0, 'error_message': "Invalid verification code."}
116+
json_data = json.dumps(data)
117+
response.write(json_data)
118+
return response
119+
96120
request.session['userID'] = admin.pk
97121

98122
ipAddr = request.META.get('REMOTE_ADDR')

plogical/upgrade.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def applyLoginSystemMigrations():
534534
pass
535535

536536
try:
537-
cursor.execute("ALTER TABLE loginSystem_administrator ADD secretKey varchar(50) DEFAULT 'ACTIVE'")
537+
cursor.execute("ALTER TABLE loginSystem_administrator ADD secretKey varchar(50) DEFAULT 'None'")
538538
except:
539539
pass
540540

static/loginSystem/login-systen.js

+43-41
Original file line numberDiff line numberDiff line change
@@ -33,73 +33,75 @@ var application = angular.module('loginSystem', []);
3333

3434
application.config(['$interpolateProvider',
3535

36-
function($interpolateProvider) {
36+
function ($interpolateProvider) {
3737
$interpolateProvider.startSymbol('{$');
3838
$interpolateProvider.endSymbol('$}');
3939
}
4040
]);
4141

42-
application.controller('loginSystem', function($scope,$http,$window) {
42+
application.controller('loginSystem', function ($scope, $http, $window) {
4343

44+
$scope.verifyCode = true;
4445

45-
$scope.verifyLoginCredentials = function() {
46+
$scope.verifyLoginCredentials = function () {
4647

47-
$("#verifyingLogin").show();
48+
$("#verifyingLogin").show();
4849

4950

50-
var username = $scope.username;
51-
var password= $scope.password;
52-
var languageSelection= $scope.languageSelection;
51+
var username = $scope.username;
52+
var password = $scope.password;
53+
var languageSelection = $scope.languageSelection;
5354

5455

55-
url = "/verifyLogin";
56+
url = "/verifyLogin";
5657

57-
var data = {
58-
username: username,
59-
password: password,
60-
languageSelection:languageSelection,
61-
};
62-
63-
var config = {
64-
headers : {
65-
'X-CSRFToken': getCookie('csrftoken')
66-
}
67-
};
68-
69-
$http.post(url, data,config).then(ListInitialData, cantLoadInitialData);
58+
var data = {
59+
username: username,
60+
password: password,
61+
languageSelection: languageSelection,
62+
twofa: $scope.twofa
63+
};
7064

65+
var config = {
66+
headers: {
67+
'X-CSRFToken': getCookie('csrftoken')
68+
}
69+
};
7170

72-
function ListInitialData(response) {
71+
$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);
7372

74-
if (response.data.loginStatus === 0)
75-
{
76-
$scope.errorMessage = response.data.error_message;
77-
$("#loginFailed").fadeIn();
78-
}
79-
else{
80-
$("#loginFailed").hide();
81-
$window.location.href = '/base/';
82-
}
8373

74+
function ListInitialData(response) {
8475

76+
if (response.data.loginStatus === 0) {
77+
$scope.errorMessage = response.data.error_message;
78+
$("#loginFailed").fadeIn();
79+
}else if(response.data.loginStatus === 2){
80+
$scope.verifyCode = false;
81+
}
82+
else {
83+
$("#loginFailed").hide();
84+
$window.location.href = '/base/';
85+
}
8586

86-
$("#verifyingLogin").hide();
87-
}
88-
function cantLoadInitialData(response) {}
8987

88+
$("#verifyingLogin").hide();
89+
}
9090

91+
function cantLoadInitialData(response) {
92+
}
9193

9294

93-
};
95+
};
9496

95-
$scope.initiateLogin = function($event){
96-
var keyCode = $event.which || $event.keyCode;
97-
if (keyCode === 13) {
98-
$scope.verifyLoginCredentials();
97+
$scope.initiateLogin = function ($event) {
98+
var keyCode = $event.which || $event.keyCode;
99+
if (keyCode === 13) {
100+
$scope.verifyLoginCredentials();
99101

100-
}
102+
}
101103

102-
};
104+
};
103105

104106

105107
});

static/userManagment/userManagment.js

+26-4
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ app.controller('createUserCtr', function ($scope, $http) {
127127
/* Java script code to modify user account */
128128
app.controller('modifyUser', function ($scope, $http) {
129129

130+
var qrCode = window.qr = new QRious({
131+
element: document.getElementById('qr'),
132+
size: 200,
133+
value: 'QRious'
134+
});
135+
136+
130137
$scope.userModificationLoading = true;
131138
$scope.acctDetailsFetched = true;
132139
$scope.userAccountsLimit = true;
@@ -137,6 +144,15 @@ app.controller('modifyUser', function ($scope, $http) {
137144
$scope.detailsFetched = true;
138145
$scope.accountTypeView = true;
139146
$scope.websitesLimit = true;
147+
$scope.qrHidden = true;
148+
149+
$scope.decideQRShow = function(){
150+
if($scope.twofa === true){
151+
$scope.qrHidden = false;
152+
}else{
153+
$scope.qrHidden = true;
154+
}
155+
};
140156

141157

142158
$scope.fetchUserDetails = function () {
@@ -173,6 +189,12 @@ app.controller('modifyUser', function ($scope, $http) {
173189
$scope.lastName = userDetails.lastName;
174190
$scope.email = userDetails.email;
175191
$scope.secLevel = userDetails.securityLevel;
192+
$scope.twofa = Boolean(userDetails.twofa);
193+
194+
qrCode.set({
195+
value: userDetails.otpauth
196+
});
197+
176198

177199
$scope.userModificationLoading = true;
178200
$scope.acctDetailsFetched = false;
@@ -220,7 +242,6 @@ app.controller('modifyUser', function ($scope, $http) {
220242

221243
};
222244

223-
224245
$scope.modifyUser = function () {
225246

226247

@@ -252,7 +273,8 @@ app.controller('modifyUser', function ($scope, $http) {
252273
lastName: lastName,
253274
email: email,
254275
passwordByPass: password,
255-
securityLevel: $scope.securityLevel
276+
securityLevel: $scope.securityLevel,
277+
twofa: $scope.twofa
256278
};
257279

258280
var config = {
@@ -1685,15 +1707,15 @@ app.controller('listTableUsers', function ($scope, $http) {
16851707

16861708

16871709
};
1688-
1710+
16891711
$scope.controlUserState = function (userName, state) {
16901712
$scope.cyberpanelLoading = false;
16911713

16921714
var url = "/users/controlUserState";
16931715

16941716
var data = {
16951717
accountUsername: userName,
1696-
state : state
1718+
state: state
16971719
};
16981720

16991721
var config = {

0 commit comments

Comments
 (0)