Added possibility to reset password. Work on user app in general.
This commit is contained in:
parent
08c31a6b09
commit
8154b0324b
@ -37,7 +37,7 @@
|
||||
<translate>Edit profile</translate>
|
||||
</a>
|
||||
<li>
|
||||
<a href="#TODO">
|
||||
<a ui-sref="users.user.detail.password({ id: operator.user.id })">
|
||||
<i class="fa fa-key"></i>
|
||||
<translate>Change password</translate>
|
||||
</a>
|
||||
|
@ -69,6 +69,13 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
||||
url: '/profile',
|
||||
controller: 'UserProfileCtrl',
|
||||
})
|
||||
.state('users.user.detail.password', {
|
||||
views: {
|
||||
'@users.user': {},
|
||||
},
|
||||
url: '/password',
|
||||
controller: 'UserPasswordCtrl',
|
||||
})
|
||||
.state('users.user.import', {
|
||||
url: '/import',
|
||||
controller: 'UserImportCtrl',
|
||||
@ -161,13 +168,18 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
||||
}
|
||||
])
|
||||
|
||||
.run(function(operator, $rootScope, $http) {
|
||||
.run([
|
||||
'operator',
|
||||
'$rootScope',
|
||||
'$http',
|
||||
function(operator, $rootScope, $http) {
|
||||
// Put the operator into the root scope
|
||||
$http.get('/users/whoami/').success(function(data) {
|
||||
operator.setUser(data.user_id);
|
||||
});
|
||||
$rootScope.operator = operator;
|
||||
})
|
||||
}
|
||||
])
|
||||
|
||||
/*
|
||||
* Directive to check for permissions
|
||||
@ -176,7 +188,9 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
||||
*
|
||||
* TODO: find a way not to copy the code.
|
||||
*/
|
||||
.directive('osPerms', ['$animate', function($animate) {
|
||||
.directive('osPerms', [
|
||||
'$animate',
|
||||
function($animate) {
|
||||
return {
|
||||
multiElement: true,
|
||||
transclude: 'element',
|
||||
@ -234,7 +248,8 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
||||
);
|
||||
}
|
||||
};
|
||||
}])
|
||||
}
|
||||
])
|
||||
|
||||
/*
|
||||
* Like osPerms but does only hide the DOM-Elements
|
||||
@ -338,12 +353,23 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
||||
}
|
||||
])
|
||||
|
||||
.controller('UserDetailCtrl', function($scope, User, user, Group) {
|
||||
.controller('UserDetailCtrl', [
|
||||
'$scope',
|
||||
'User',
|
||||
'user',
|
||||
'Group',
|
||||
function($scope, User, user, Group) {
|
||||
User.bindOne(user.id, $scope, 'user');
|
||||
Group.bindAll({}, $scope, 'groups');
|
||||
})
|
||||
}
|
||||
])
|
||||
|
||||
.controller('UserCreateCtrl', function($scope, $state, User, Group) {
|
||||
.controller('UserCreateCtrl', [
|
||||
'$scope',
|
||||
'$state',
|
||||
'User',
|
||||
'Group',
|
||||
function($scope, $state, User, Group) {
|
||||
Group.bindAll({where: {id: {'>': 2}}}, $scope, 'groups');
|
||||
$scope.user = {};
|
||||
$scope.save = function (user) {
|
||||
@ -356,9 +382,16 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
||||
}
|
||||
);
|
||||
};
|
||||
})
|
||||
}
|
||||
])
|
||||
|
||||
.controller('UserUpdateCtrl', function($scope, $state, User, user, Group) {
|
||||
.controller('UserUpdateCtrl', [
|
||||
'$scope',
|
||||
'$state',
|
||||
'User',
|
||||
'user',
|
||||
'Group',
|
||||
function($scope, $state, User, user, Group) {
|
||||
Group.bindAll({where: {id: {'>': 2}}}, $scope, 'groups');
|
||||
$scope.user = user; // autoupdate is not activated
|
||||
$scope.save = function (user) {
|
||||
@ -371,21 +404,65 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
||||
}
|
||||
);
|
||||
};
|
||||
})
|
||||
}
|
||||
])
|
||||
|
||||
.controller('UserProfileCtrl', function($scope, $state, User, user) {
|
||||
.controller('UserProfileCtrl', [
|
||||
'$scope',
|
||||
'$state',
|
||||
'User',
|
||||
'user',
|
||||
function($scope, $state, User, user) {
|
||||
$scope.user = user; // autoupdate is not activated
|
||||
$scope.save = function (user) {
|
||||
User.save(user).then(
|
||||
function(success) {
|
||||
// TODO: show success message
|
||||
console.log("profile saved");
|
||||
$state.go('users.user.list');
|
||||
},
|
||||
function(error) {
|
||||
$scope.formError = error;
|
||||
}
|
||||
);
|
||||
};
|
||||
})
|
||||
}
|
||||
])
|
||||
|
||||
.controller('UserImportCtrl', function($scope, $state, User) {
|
||||
.controller('UserPasswordCtrl', [
|
||||
'$scope',
|
||||
'$state',
|
||||
'$http',
|
||||
'user',
|
||||
function($scope, $state, $http, user) {
|
||||
$scope.user = user; // autoupdate is not activated
|
||||
$scope.save = function (user) {
|
||||
if ($scope.newPassword != $scope.newPassword2) {
|
||||
$scope.newPassword = $scope.newPassword2 = '';
|
||||
$scope.formError = 'Password confirmation does not match.';
|
||||
} else {
|
||||
$http.post(
|
||||
'/users/setpassword/',
|
||||
{'old_password': $scope.oldPassword, 'new_password': $scope.newPassword}
|
||||
).then(
|
||||
function(data) {
|
||||
// Success.
|
||||
$state.go('users.user.list');
|
||||
},
|
||||
function(data) {
|
||||
// Error, e. g. wrong old password.
|
||||
$scope.oldPassword = $scope.newPassword = $scope.newPassword2 = '';
|
||||
$scope.formError = data;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
])
|
||||
|
||||
.controller('UserImportCtrl', [
|
||||
'$scope',
|
||||
'$state',
|
||||
'User',
|
||||
function($scope, $state, User) {
|
||||
// import from textarea
|
||||
$scope.importByLine = function () {
|
||||
$scope.users = $scope.userlist[0].split("\n");
|
||||
@ -450,18 +527,28 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
||||
$scope.clear = function () {
|
||||
$scope.csv.result = null;
|
||||
};
|
||||
})
|
||||
}
|
||||
])
|
||||
|
||||
.controller('GroupListCtrl', function($scope, Group) {
|
||||
.controller('GroupListCtrl', [
|
||||
'$scope',
|
||||
'Group',
|
||||
function($scope, Group) {
|
||||
Group.bindAll({}, $scope, 'groups');
|
||||
|
||||
// delete selected group
|
||||
$scope.delete = function (group) {
|
||||
Group.destroy(group.id);
|
||||
};
|
||||
})
|
||||
}
|
||||
])
|
||||
|
||||
.controller('GroupCreateCtrl', function($scope, $state, Group, permissions) {
|
||||
.controller('GroupCreateCtrl', [
|
||||
'$scope',
|
||||
'$state',
|
||||
'Group',
|
||||
'permissions',
|
||||
function($scope, $state, Group, permissions) {
|
||||
// get all permissions
|
||||
$scope.permissions = permissions.data.actions.POST.permissions.choices;
|
||||
$scope.group = {};
|
||||
@ -472,9 +559,16 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
||||
}
|
||||
);
|
||||
};
|
||||
})
|
||||
}
|
||||
])
|
||||
|
||||
.controller('GroupUpdateCtrl', function($scope, $state, Group, permissions, group) {
|
||||
.controller('GroupUpdateCtrl', [
|
||||
'$scope',
|
||||
'$state',
|
||||
'Group',
|
||||
'permissions',
|
||||
'group',
|
||||
function($scope, $state, Group, permissions, group) {
|
||||
// get all permissions
|
||||
$scope.permissions = permissions.data.actions.POST.permissions.choices;
|
||||
$scope.group = group; // autoupdate is not activated
|
||||
@ -485,13 +579,25 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
||||
}
|
||||
);
|
||||
};
|
||||
})
|
||||
}
|
||||
])
|
||||
|
||||
.controller('GroupDetailCtrl', function($scope, Group, group) {
|
||||
.controller('GroupDetailCtrl', [
|
||||
'$scope',
|
||||
'Group',
|
||||
'group',
|
||||
function($scope, Group, group) {
|
||||
Group.bindOne(group.id, $scope, 'group');
|
||||
})
|
||||
}
|
||||
])
|
||||
|
||||
.controller('userMenu', function($scope, $http, DS, User, operator) {
|
||||
.controller('userMenu', [
|
||||
'$scope',
|
||||
'$http',
|
||||
'DS',
|
||||
'User',
|
||||
'operator',
|
||||
function($scope, $http, DS, User, operator) {
|
||||
$scope.logout = function() {
|
||||
$http.post('/users/logout/').success(function(data) {
|
||||
operator.setUser(null);
|
||||
@ -499,7 +605,8 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
||||
// DS.flush();
|
||||
});
|
||||
};
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
// this is code from angular.js. Find a way to call this function from this file
|
||||
function getBlockNodes(nodes) {
|
||||
|
@ -0,0 +1,37 @@
|
||||
<h1>Change password</h1>
|
||||
|
||||
<p ng-if='formError' class="text-danger">
|
||||
<strong>{{ formError }}</strong>
|
||||
</p>
|
||||
<form name="userForm" >
|
||||
<div class="form-group">
|
||||
<label for="inputOldPassword" translate>Old password</label>
|
||||
<input type="password"
|
||||
ng-model="oldPassword"
|
||||
class="form-control"
|
||||
name="inputOldPassword"
|
||||
required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="inputNewPassword" translate>New password</label>
|
||||
<input type="password"
|
||||
ng-model="newPassword"
|
||||
class="form-control"
|
||||
name="inputNewPassword"
|
||||
required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="inputNewPassword2" translate>Confirm new password</label>
|
||||
<input type="password"
|
||||
ng-model="newPassword2"
|
||||
class="form-control"
|
||||
name="inputNewPassword2"
|
||||
required>
|
||||
</div>
|
||||
<button type="submit" ng-click="save(user)" class="btn btn-primary" translate>
|
||||
Save
|
||||
</button>
|
||||
<button ui-sref="users.user.list" class="btn btn-default" translate>
|
||||
Cancel
|
||||
</button>
|
||||
</form>
|
@ -1,5 +1,8 @@
|
||||
<h1>Edit profil</h1>
|
||||
|
||||
<p ng-if='formError' class="text-danger">
|
||||
<strong>{{ formError }}</strong>
|
||||
</p>
|
||||
<form name="userForm" >
|
||||
<div class="form-group">
|
||||
<label for="inputUsername" translate>Username</label>
|
||||
|
@ -18,6 +18,10 @@ urlpatterns = patterns(
|
||||
views.WhoAmIView.as_view(),
|
||||
name='user_whoami'),
|
||||
|
||||
url(r'^setpassword/$',
|
||||
views.SetPasswordView.as_view(),
|
||||
name='user_setpassword'),
|
||||
|
||||
# PDF
|
||||
url(r'^print/$',
|
||||
views.UsersListPDF.as_view(),
|
||||
|
@ -5,7 +5,13 @@ from django.utils.translation import ugettext as _
|
||||
from django.utils.translation import ugettext_lazy
|
||||
|
||||
from ..core.config import config
|
||||
from ..utils.rest_api import ModelViewSet, Response, detail_route, status
|
||||
from ..utils.rest_api import (
|
||||
ModelViewSet,
|
||||
Response,
|
||||
ValidationError,
|
||||
detail_route,
|
||||
status,
|
||||
)
|
||||
from ..utils.views import APIView, PDFView
|
||||
from .models import Group, User
|
||||
from .pdf import users_passwords_to_pdf, users_to_pdf
|
||||
@ -232,6 +238,22 @@ class WhoAmIView(APIView):
|
||||
**context)
|
||||
|
||||
|
||||
class SetPasswordView(APIView):
|
||||
"""
|
||||
Users can set a new password for themselves.
|
||||
"""
|
||||
http_method_names = ['post']
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
user = request.user
|
||||
if user.check_password(request.data['old_password']):
|
||||
user.set_password(request.data['new_password'])
|
||||
user.save()
|
||||
else:
|
||||
raise ValidationError(_('Password does not match.'))
|
||||
return super().post(request, *args, **kwargs)
|
||||
|
||||
|
||||
# Views to generate PDFs
|
||||
|
||||
class UsersListPDF(PDFView):
|
||||
|
Loading…
Reference in New Issue
Block a user