Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Commit

Permalink
feat: User creation from management gui / management API
Browse files Browse the repository at this point in the history
  • Loading branch information
aelamrani authored and brasseld committed Mar 7, 2019
1 parent f1405d8 commit f4176b1
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/management-api-documentation.md
Expand Up @@ -16,7 +16,7 @@ You can also configure a page by clicking on the *settings* button. Page's confi

(+) button let you create a new documentation page.

Another possibility is to add a whole directory. Click on the wheel at the top of the screen and import a directory.
Another possibility is to add a whole directory. Click on the link at the top of the screen and import a directory.
If this directory contains a gravitee descriptor (a file named `.gravitee.json`) we will add the content according to the descriptor.

Here is a descriptor sample :
Expand All @@ -39,4 +39,4 @@ Here is a descriptor sample :
]
}
}
```
```
3 changes: 3 additions & 0 deletions docs/management-configuration-create-user.md
@@ -0,0 +1,3 @@
# User creation

Fill user information and validate. The new user will receive an email to finalize the creation by setting a password.
4 changes: 2 additions & 2 deletions docs/management-configuration-portal-pages.md
Expand Up @@ -15,7 +15,7 @@ You can also configure a page by clicking on the *settings* button. Page's confi

(+) button let you create a new documentation page.

Another possibility is to add a whole directory. Click on the wheel at the top of the screen and import a directory.
Another possibility is to add a whole directory. Click on the link at the top of the screen and import a directory.
If this directory contains a gravitee descriptor (a file named `.gravitee.json`) we will add the content according to the descriptor.

Here is a descriptor sample :
Expand All @@ -38,4 +38,4 @@ Here is a descriptor sample :
]
}
}
```
```
13 changes: 13 additions & 0 deletions src/management/configuration/configuration.route.ts
Expand Up @@ -512,6 +512,19 @@ function configurationRouterConfig($stateProvider) {
}
}
})
.state('management.settings.newuser', {
url: '/users/new',
component: 'newUser',
data: {
menu: null,
docs: {
page: 'management-configuration-create-user'
},
perms: {
only: ['management-user-c']
}
}
})
.state('management.settings.portal', {
url: '/portal',
component: 'portalSettings',
Expand Down
2 changes: 1 addition & 1 deletion src/management/configuration/portal/portal.html
Expand Up @@ -109,7 +109,7 @@ <h2>Portal</h2>
</md-input-container>
<md-input-container class="gv-input-container-dense">
<md-checkbox ng-model="$ctrl.Constants.portal.userCreation.enabled" aria-label="Allow user creation">
Allow User Creation
Allow User Registration
</md-checkbox>
</md-input-container>
<md-input-container class="gv-input-container-dense">
Expand Down
37 changes: 37 additions & 0 deletions src/management/configuration/user/new/new-user.component.ts
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import UserService from '../../../../services/user.service';
import NotificationService from '../../../../services/notification.service';
import { StateService } from '@uirouter/core';

const NewUserComponent: ng.IComponentOptions = {
template: require('./new-user.html'),
controller: function (
UserService: UserService,
NotificationService: NotificationService,
$state: StateService
) {
'ngInject';
this.create = () => {
UserService.create(this.user).then(() => {
NotificationService.show('User registered with success');
$state.go('management.settings.users');
});
};
}
};

export default NewUserComponent;
50 changes: 50 additions & 0 deletions src/management/configuration/user/new/new-user.html
@@ -0,0 +1,50 @@
<!--
Copyright (C) 2015 The Gravitee team (http://gravitee.io)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<div class="gv-forms" layout="column">
<div layout="row" layout-align="start end" class="gv-forms-header">
<h1 class="user">
Create a user
<a ui-sref="management.settings.users" style="font-size: 12px; font-weight: normal;">Back to users</a>
</h1>
</div>

<div class="gv-form">
<form name="$ctrl.formCreation" ng-submit="$ctrl.create($)" layout="column">
<md-input-container class="md-icon-float">
<label>First name</label>
<input ng-model="$ctrl.user.firstname" type="text" required autofocus>
</md-input-container>

<md-input-container class="md-icon-float">
<label>Last name</label>
<input ng-model="$ctrl.user.lastname" type="text" required>
</md-input-container>

<md-input-container class="md-icon-float">
<label>Email</label>
<input ng-model="$ctrl.user.email" type="email" required>
</md-input-container>

<div class="md-actions" layout="row">
<md-button type="submit" class="md-raised md-primary" ng-disabled="$ctrl.formCreation.$invalid || $ctrl.formCreation.$pristine">
Save
</md-button>
</div>
</form>
</div>
</div>
6 changes: 5 additions & 1 deletion src/management/configuration/users/users.component.ts
Expand Up @@ -74,7 +74,11 @@ const UsersComponent: ng.IComponentOptions = {

this.search = () => {
$state.go('.', {q: this.query});
}
};

this.newUser = () => {
$state.go('management.settings.newuser');
};
}
};

Expand Down
5 changes: 5 additions & 0 deletions src/management/configuration/users/users.html
Expand Up @@ -68,3 +68,8 @@ <h2></h2>
</div>
</div>
</div>

<md-button ng-click="$ctrl.newUser()" aria-label="Add user" class="md-fab md-fab-bottom-right">
<md-tooltip md-direction="top" md-visible="false">Add user</md-tooltip>
<ng-md-icon icon="add"></ng-md-icon>
</md-button>
2 changes: 2 additions & 0 deletions src/management/management.module.ts
Expand Up @@ -281,6 +281,7 @@ import ApiLoggingController from '../management/configuration/api_logging/api_lo
// Users
import UsersComponent from '../management/configuration/users/users.component';
import UserDetailComponent from '../management/configuration/user/userdetail.component';
import NewUserComponent from '../management/configuration/user/new/new-user.component';
import DialogAddUserGroupController from '../management/configuration/user/dialog/addusergroup.dialog.controller';
// Groups
import GroupsComponent from '../management/configuration/groups/groups.component';
Expand Down Expand Up @@ -740,6 +741,7 @@ angular.module('gravitee-management', [uiRouter, permission, uiPermission, 'ngMa
// Users
.component('users', UsersComponent)
.component('userDetail', UserDetailComponent)
.component('newUser', NewUserComponent)
.controller('DialogAddUserGroupController', DialogAddUserGroupController)

// Router
Expand Down
8 changes: 6 additions & 2 deletions src/services/user.service.ts
Expand Up @@ -54,8 +54,8 @@ class UserService {
this.userURL = `${Constants.baseURL}user/`;
}

list(query?: string, page = 1): ng.IPromise<any> {
let url = `${this.usersURL}?page=${page}`;
list(query?: string, page = 1, size = 10): ng.IPromise<any> {
let url = `${this.usersURL}?page=${page}&size=${size}`;

if (query) {
url += '&q=' + query;
Expand All @@ -80,6 +80,10 @@ class UserService {
return this.$http.post(`${this.usersURL}register`, user);
}

finalizeRegistration(user): ng.IPromise<any> {
return this.$http.post(`${this.usersURL}register/finalize`, user);
}

search(query): ng.IPromise<any> {
return this.$http.get(`${this.searchUsersURL}?q=${query}`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/user/registration/confirm/confirm.controller.ts
Expand Up @@ -33,7 +33,7 @@ class ConfirmController {
}

$scope.confirmRegistration = function () {
UserService.create({
UserService.finalizeRegistration({
token: $state.params.token, password: $scope.confirmPassword,
firstname: $scope.user.firstname, lastname: $scope.user.lastname
}).then(function () {
Expand Down
2 changes: 1 addition & 1 deletion src/user/resetPassword/resetPassword.controller.ts
Expand Up @@ -30,7 +30,7 @@ class ResetPasswordController {
}

$scope.changePassword = function () {
UserService.create({token: $state.params.token, password: $scope.confirmPassword,
UserService.finalizeRegistration({token: $state.params.token, password: $scope.confirmPassword,
firstname: $scope.user.firstname, lastname: $scope.user.lastname}).then(function () {
$scope.formConfirm.$setPristine();
NotificationService.show('Your password has been initialized successfully, you can now login...');
Expand Down
15 changes: 7 additions & 8 deletions src/user/user.controller.ts
Expand Up @@ -18,6 +18,7 @@ import { User } from "../entities/user";
import {IScope} from 'angular';
import UserService from "../services/user.service";
import { StateService } from '@uirouter/core';
import StringService from "../services/string.service";

interface IUserScope extends ng.IScope {
formUser: any;
Expand Down Expand Up @@ -45,19 +46,17 @@ class UserController {
}

save() {
let that = this;
this.UserService.save(this.user).then((response) => {
that.$rootScope.$broadcast('graviteeUserRefresh');
that.$scope.formUser.$setPristine();
//that.originalPicture = response.data["picture"];
//that.user.picture = response.data["picture"];
that.NotificationService.show("User has been updated successfully");
this.user = response.data;
this.$rootScope.$broadcast('graviteeUserRefresh');
this.$scope.formUser.$setPristine();
this.NotificationService.show("User has been updated successfully");
});
}

cancel() {
this.$scope.formUser.$setPristine();
//this.user.picture = this.originalPicture;
delete this.user.picture;
this.$state.reload();
}

getUserPicture() {
Expand Down

0 comments on commit f4176b1

Please sign in to comment.