initial commit
This commit is contained in:
28
lemur/static/app/angular/authentication/login/login.js
vendored
Normal file
28
lemur/static/app/angular/authentication/login/login.js
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('lemur')
|
||||
.config(function config($routeProvider) {
|
||||
$routeProvider.when('/login', {
|
||||
templateUrl: '/angular/authentication/login/login.tpl.html',
|
||||
controller: 'LoginController'
|
||||
});
|
||||
})
|
||||
.controller('LoginController', function ($rootScope, $scope, AuthenticationService, UserService) {
|
||||
$scope.login = AuthenticationService.login;
|
||||
$scope.authenticate = AuthenticationService.authenticate;
|
||||
$scope.logout = AuthenticationService.logout;
|
||||
|
||||
UserService.getCurrentUser().then(function (user) {
|
||||
$scope.currentUser = user;
|
||||
});
|
||||
|
||||
$rootScope.$on('user:login', function () {
|
||||
UserService.getCurrentUser().then(function (user) {
|
||||
$scope.currentUser = user;
|
||||
});
|
||||
});
|
||||
|
||||
$rootScope.$on('user:logout', function () {
|
||||
$scope.currentUser = null;
|
||||
});
|
||||
});
|
27
lemur/static/app/angular/authentication/login/login.tpl.html
Normal file
27
lemur/static/app/angular/authentication/login/login.tpl.html
Normal file
@ -0,0 +1,27 @@
|
||||
<h2 class="featurette-heading">Login <span class="text-muted"><small>None shall pass</small></span></h2>
|
||||
<div class="row">
|
||||
<div class="login">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-12 col-md-12">
|
||||
<button class="btn btn-block btn-default" ng-click="authenticate('ping')">
|
||||
Login with Meechum
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="login-or">
|
||||
<hr class="hr-or">
|
||||
<span class="span-or">or</span>
|
||||
</div>
|
||||
<form role="form" _lpchecked="1">
|
||||
<div class="form-group">
|
||||
<input type="text" ng-model="username" placeholder="Username" class="form-control"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="password" ng-model="password" placeholder="Password" class="form-control"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button ng-click="login(username, password)" class="btn btn-block btn-success">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
12
lemur/static/app/angular/authentication/logout/logout.js
vendored
Normal file
12
lemur/static/app/angular/authentication/logout/logout.js
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('lemur')
|
||||
.config(function config($routeProvider) {
|
||||
$routeProvider.when('/logout', {
|
||||
controller: 'LogoutCtrl'
|
||||
});
|
||||
})
|
||||
.controller('LogoutCtrl', function ($scope, $location, lemurRestangular, userService) {
|
||||
userService.logout();
|
||||
$location.path('/');
|
||||
});
|
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head lang="en">
|
||||
<meta charset="UTF-8">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
62
lemur/static/app/angular/authentication/services.js
vendored
Normal file
62
lemur/static/app/angular/authentication/services.js
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
angular.module('lemur')
|
||||
.service('AuthenticationApi', function (LemurRestangular) {
|
||||
return LemurRestangular.all('auth');
|
||||
})
|
||||
.service('AuthenticationService', function ($location, $rootScope, AuthenticationApi, UserService, toaster, $auth) {
|
||||
var AuthenticationService = this;
|
||||
|
||||
AuthenticationService.login = function (username, password) {
|
||||
AuthenticationApi.customPOST({'username': username, 'password': password}, 'login')
|
||||
.then(
|
||||
function (user) {
|
||||
$auth.setToken(user.token, true);
|
||||
$rootScope.$emit('user:login');
|
||||
$location.url('/certificates');
|
||||
},
|
||||
function (response) {
|
||||
toaster.pop({
|
||||
type: 'error',
|
||||
title: 'Whoa there',
|
||||
body: response.data.message,
|
||||
showCloseButton: true
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
AuthenticationService.authenticate = function (provider) {
|
||||
$auth.authenticate(provider)
|
||||
.then(
|
||||
function (user) {
|
||||
UserService.getCurrentUser();
|
||||
$rootScope.$emit('user:login');
|
||||
$location.url('/certificates');
|
||||
},
|
||||
function (response) {
|
||||
toaster.pop({
|
||||
type: 'error',
|
||||
title: 'Something went wrong',
|
||||
body: response.data.message
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
AuthenticationService.logout = function () {
|
||||
if (!$auth.isAuthenticated()) {
|
||||
return;
|
||||
}
|
||||
$auth.logout()
|
||||
.then(function() {
|
||||
$rootScope.$emit('user:logout');
|
||||
toaster.pop({
|
||||
type: 'success',
|
||||
title: 'Good job!',
|
||||
body: 'You have been successfully logged out.'
|
||||
});
|
||||
$location.path('/');
|
||||
})
|
||||
};
|
||||
|
||||
});
|
18
lemur/static/app/angular/authentication/unlock/unlock.js
vendored
Normal file
18
lemur/static/app/angular/authentication/unlock/unlock.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('lemur')
|
||||
.config(function config($routeProvider) {
|
||||
$routeProvider.when('/unlock', {
|
||||
templateUrl: '/angular/authentication/unlock/unlock.tpl.html',
|
||||
controller: 'UnlockCtrl'
|
||||
});
|
||||
})
|
||||
.controller('UnlockCtrl', function ($scope, $location, lemurRestangular, messageService) {
|
||||
$scope.unlock = function () {
|
||||
lemurRestangular.one('unlock').customPOST({'password': $scope.password})
|
||||
.then(function (data) {
|
||||
messageService.addMessage(data);
|
||||
$location.path('/dashboard');
|
||||
});
|
||||
};
|
||||
});
|
@ -0,0 +1,16 @@
|
||||
<h2 class="featurette-heading">Unlock <span class="text-muted"><small>Assume 9 is twice 5; how will you write 6 times 5 in the same system of notation?</small></span></h2>
|
||||
<form class="form-horizontal" _lpchecked="1">
|
||||
<fieldset class="col-lg-offset-4">
|
||||
<div class="form-group">
|
||||
<div class="col-lg-4">
|
||||
<input type="password" ng-model="password" placeholder="Password" class="form-control"/>
|
||||
</div>
|
||||
</div>
|
||||
<hr class="featurette-divider">
|
||||
<div class="form-group">
|
||||
<div class="col-lg-4">
|
||||
<button ng-click="unlock()" class="btn btn-success">Unlock</button>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
Reference in New Issue
Block a user