Merge pull request #1665 from normanjaeckel/ProfilePassword
Added possibility to reset password. Work on user app in general.
This commit is contained in:
commit
ce52dde13a
@ -37,7 +37,7 @@
|
|||||||
<translate>Edit profile</translate>
|
<translate>Edit profile</translate>
|
||||||
</a>
|
</a>
|
||||||
<li>
|
<li>
|
||||||
<a href="#TODO">
|
<a ui-sref="users.user.detail.password({ id: operator.user.id })">
|
||||||
<i class="fa fa-key"></i>
|
<i class="fa fa-key"></i>
|
||||||
<translate>Change password</translate>
|
<translate>Change password</translate>
|
||||||
</a>
|
</a>
|
||||||
|
@ -69,6 +69,13 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
|||||||
url: '/profile',
|
url: '/profile',
|
||||||
controller: 'UserProfileCtrl',
|
controller: 'UserProfileCtrl',
|
||||||
})
|
})
|
||||||
|
.state('users.user.detail.password', {
|
||||||
|
views: {
|
||||||
|
'@users.user': {},
|
||||||
|
},
|
||||||
|
url: '/password',
|
||||||
|
controller: 'UserPasswordCtrl',
|
||||||
|
})
|
||||||
.state('users.user.import', {
|
.state('users.user.import', {
|
||||||
url: '/import',
|
url: '/import',
|
||||||
controller: 'UserImportCtrl',
|
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
|
// Put the operator into the root scope
|
||||||
$http.get('/users/whoami/').success(function(data) {
|
$http.get('/users/whoami/').success(function(data) {
|
||||||
operator.setUser(data.user_id);
|
operator.setUser(data.user_id);
|
||||||
});
|
});
|
||||||
$rootScope.operator = operator;
|
$rootScope.operator = operator;
|
||||||
})
|
}
|
||||||
|
])
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Directive to check for permissions
|
* 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.
|
* TODO: find a way not to copy the code.
|
||||||
*/
|
*/
|
||||||
.directive('osPerms', ['$animate', function($animate) {
|
.directive('osPerms', [
|
||||||
|
'$animate',
|
||||||
|
function($animate) {
|
||||||
return {
|
return {
|
||||||
multiElement: true,
|
multiElement: true,
|
||||||
transclude: 'element',
|
transclude: 'element',
|
||||||
@ -234,7 +248,8 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}])
|
}
|
||||||
|
])
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Like osPerms but does only hide the DOM-Elements
|
* 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');
|
User.bindOne(user.id, $scope, 'user');
|
||||||
Group.bindAll({}, $scope, 'groups');
|
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');
|
Group.bindAll({where: {id: {'>': 2}}}, $scope, 'groups');
|
||||||
$scope.user = {};
|
$scope.user = {};
|
||||||
$scope.save = function (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');
|
Group.bindAll({where: {id: {'>': 2}}}, $scope, 'groups');
|
||||||
$scope.user = user; // autoupdate is not activated
|
$scope.user = user; // autoupdate is not activated
|
||||||
$scope.save = function (user) {
|
$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.user = user; // autoupdate is not activated
|
||||||
$scope.save = function (user) {
|
$scope.save = function (user) {
|
||||||
User.save(user).then(
|
User.save(user).then(
|
||||||
function(success) {
|
function(success) {
|
||||||
// TODO: show success message
|
$state.go('users.user.list');
|
||||||
console.log("profile saved");
|
},
|
||||||
|
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
|
// import from textarea
|
||||||
$scope.importByLine = function () {
|
$scope.importByLine = function () {
|
||||||
$scope.users = $scope.userlist[0].split("\n");
|
$scope.users = $scope.userlist[0].split("\n");
|
||||||
@ -450,18 +527,28 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
|||||||
$scope.clear = function () {
|
$scope.clear = function () {
|
||||||
$scope.csv.result = null;
|
$scope.csv.result = null;
|
||||||
};
|
};
|
||||||
})
|
}
|
||||||
|
])
|
||||||
|
|
||||||
.controller('GroupListCtrl', function($scope, Group) {
|
.controller('GroupListCtrl', [
|
||||||
|
'$scope',
|
||||||
|
'Group',
|
||||||
|
function($scope, Group) {
|
||||||
Group.bindAll({}, $scope, 'groups');
|
Group.bindAll({}, $scope, 'groups');
|
||||||
|
|
||||||
// delete selected group
|
// delete selected group
|
||||||
$scope.delete = function (group) {
|
$scope.delete = function (group) {
|
||||||
Group.destroy(group.id);
|
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
|
// get all permissions
|
||||||
$scope.permissions = permissions.data.actions.POST.permissions.choices;
|
$scope.permissions = permissions.data.actions.POST.permissions.choices;
|
||||||
$scope.group = {};
|
$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
|
// get all permissions
|
||||||
$scope.permissions = permissions.data.actions.POST.permissions.choices;
|
$scope.permissions = permissions.data.actions.POST.permissions.choices;
|
||||||
$scope.group = group; // autoupdate is not activated
|
$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');
|
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() {
|
$scope.logout = function() {
|
||||||
$http.post('/users/logout/').success(function(data) {
|
$http.post('/users/logout/').success(function(data) {
|
||||||
operator.setUser(null);
|
operator.setUser(null);
|
||||||
@ -499,7 +605,8 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
|||||||
// DS.flush();
|
// DS.flush();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
// this is code from angular.js. Find a way to call this function from this file
|
// this is code from angular.js. Find a way to call this function from this file
|
||||||
function getBlockNodes(nodes) {
|
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>
|
<h1>Edit profil</h1>
|
||||||
|
|
||||||
|
<p ng-if='formError' class="text-danger">
|
||||||
|
<strong>{{ formError }}</strong>
|
||||||
|
</p>
|
||||||
<form name="userForm" >
|
<form name="userForm" >
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="inputUsername" translate>Username</label>
|
<label for="inputUsername" translate>Username</label>
|
||||||
|
@ -18,6 +18,10 @@ urlpatterns = patterns(
|
|||||||
views.WhoAmIView.as_view(),
|
views.WhoAmIView.as_view(),
|
||||||
name='user_whoami'),
|
name='user_whoami'),
|
||||||
|
|
||||||
|
url(r'^setpassword/$',
|
||||||
|
views.SetPasswordView.as_view(),
|
||||||
|
name='user_setpassword'),
|
||||||
|
|
||||||
# PDF
|
# PDF
|
||||||
url(r'^print/$',
|
url(r'^print/$',
|
||||||
views.UsersListPDF.as_view(),
|
views.UsersListPDF.as_view(),
|
||||||
|
@ -5,7 +5,13 @@ from django.utils.translation import ugettext as _
|
|||||||
from django.utils.translation import ugettext_lazy
|
from django.utils.translation import ugettext_lazy
|
||||||
|
|
||||||
from ..core.config import config
|
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 ..utils.views import APIView, PDFView
|
||||||
from .models import Group, User
|
from .models import Group, User
|
||||||
from .pdf import users_passwords_to_pdf, users_to_pdf
|
from .pdf import users_passwords_to_pdf, users_to_pdf
|
||||||
@ -232,6 +238,22 @@ class WhoAmIView(APIView):
|
|||||||
**context)
|
**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
|
# Views to generate PDFs
|
||||||
|
|
||||||
class UsersListPDF(PDFView):
|
class UsersListPDF(PDFView):
|
||||||
|
Loading…
Reference in New Issue
Block a user