Add a user service and load the user information dynamically from the backend.
This commit is contained in:
parent
ccc6e3bd2e
commit
2f98c95d21
4 changed files with 49 additions and 4 deletions
|
@ -19,6 +19,18 @@ def welcome():
|
|||
return make_response('welcome', 200)
|
||||
|
||||
|
||||
@app.route('/api/user/')
|
||||
@login_required
|
||||
def get_logged_in_user():
|
||||
user = current_user.db_user
|
||||
return jsonify({
|
||||
'verified': user.verified,
|
||||
'anonymous': False,
|
||||
'username': user.username,
|
||||
'email': user.email,
|
||||
})
|
||||
|
||||
|
||||
@app.route('/api/repository/', methods=['POST'])
|
||||
@login_required
|
||||
def create_repo_api():
|
||||
|
|
|
@ -1,4 +1,31 @@
|
|||
quayApp = angular.module('quay', ['restangular']).
|
||||
quayApp = angular.module('quay', ['restangular'], function($provide) {
|
||||
$provide.factory('UserService', ['Restangular', function(Restangular) {
|
||||
var userResponse = {
|
||||
verified: false,
|
||||
anonymous: true,
|
||||
username: null,
|
||||
email: null
|
||||
}
|
||||
|
||||
var userService = {}
|
||||
|
||||
userService.load = function() {
|
||||
var userFetch = Restangular.one('user/');
|
||||
userFetch.get().then(function(loadedUser) {
|
||||
userResponse = loadedUser;
|
||||
});
|
||||
};
|
||||
|
||||
userService.currentUser = function() {
|
||||
return userResponse;
|
||||
}
|
||||
|
||||
// Load the user the first time.
|
||||
userService.load();
|
||||
|
||||
return userService;
|
||||
}])
|
||||
}).
|
||||
config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
|
||||
$routeProvider.
|
||||
when('/repository/:namespace/:name', {templateUrl: '/static/partials/view-repo.html', controller: RepoCtrl}).
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
function HeaderCtrl($scope, UserService) {
|
||||
$scope.$watch( function () { return UserService.currentUser(); }, function (currentUser) {
|
||||
$scope.user = currentUser;
|
||||
}, true);
|
||||
}
|
||||
|
||||
function RepoListCtrl($scope, Restangular) {
|
||||
var repositoryFetch = Restangular.all('repository/');
|
||||
repositoryFetch.getList().then(function(resp) {
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<!-- Nav bar -->
|
||||
<nav class="navbar navbar-default" role="navigation">
|
||||
<nav class="navbar navbar-default" role="navigation" ng-controller='HeaderCtrl'>
|
||||
<!-- Quay -->
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
|
||||
|
@ -53,7 +53,7 @@
|
|||
<li class="dropdown">
|
||||
<!--<button type="button" class="btn btn-default navbar-btn">Sign in</button>-->
|
||||
|
||||
<a href="javascript:void(0)" class="dropdown-toggle" data-toggle="dropdown">devtable <b class="caret"></b></a>
|
||||
<a href="javascript:void(0)" class="dropdown-toggle" data-toggle="dropdown">{{ user.username }} <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="#">Settings</a></li>
|
||||
<li><a href="#">Sign out</a></li>
|
||||
|
|
Reference in a new issue