mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Added change password ability to admin > edit user view, #1446
This commit is contained in:
parent
15c52cacfb
commit
1a106e5c38
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/bus"
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
"github.com/grafana/grafana/pkg/middleware"
|
"github.com/grafana/grafana/pkg/middleware"
|
||||||
m "github.com/grafana/grafana/pkg/models"
|
m "github.com/grafana/grafana/pkg/models"
|
||||||
|
"github.com/grafana/grafana/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AdminSearchUsers(c *middleware.Context) {
|
func AdminSearchUsers(c *middleware.Context) {
|
||||||
@ -91,6 +92,36 @@ func AdminUpdateUser(c *middleware.Context, form dtos.AdminUpdateUserForm) {
|
|||||||
c.JsonOK("User updated")
|
c.JsonOK("User updated")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AdminUpdateUserPassword(c *middleware.Context, form dtos.AdminUpdateUserPasswordForm) {
|
||||||
|
userId := c.ParamsInt64(":id")
|
||||||
|
|
||||||
|
if len(form.Password) < 4 {
|
||||||
|
c.JsonApiErr(400, "New password too short", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userQuery := m.GetUserByIdQuery{Id: userId}
|
||||||
|
|
||||||
|
if err := bus.Dispatch(&userQuery); err != nil {
|
||||||
|
c.JsonApiErr(500, "Could not read user from database", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
passwordHashed := util.EncodePassword(form.Password, userQuery.Result.Salt)
|
||||||
|
|
||||||
|
cmd := m.ChangeUserPasswordCommand{
|
||||||
|
UserId: userId,
|
||||||
|
NewPassword: passwordHashed,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := bus.Dispatch(&cmd); err != nil {
|
||||||
|
c.JsonApiErr(500, "Failed to update user password", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JsonOK("User password updated")
|
||||||
|
}
|
||||||
|
|
||||||
func AdminDeleteUser(c *middleware.Context) {
|
func AdminDeleteUser(c *middleware.Context) {
|
||||||
userId := c.ParamsInt64(":id")
|
userId := c.ParamsInt64(":id")
|
||||||
|
|
||||||
|
@ -102,7 +102,8 @@ func Register(r *macaron.Macaron) {
|
|||||||
r.Get("/users", AdminSearchUsers)
|
r.Get("/users", AdminSearchUsers)
|
||||||
r.Get("/users/:id", AdminGetUser)
|
r.Get("/users/:id", AdminGetUser)
|
||||||
r.Post("/users", bind(dtos.AdminCreateUserForm{}), AdminCreateUser)
|
r.Post("/users", bind(dtos.AdminCreateUserForm{}), AdminCreateUser)
|
||||||
r.Put("/users/:id", bind(dtos.AdminUpdateUserForm{}), AdminUpdateUser)
|
r.Put("/users/:id/details", bind(dtos.AdminUpdateUserForm{}), AdminUpdateUser)
|
||||||
|
r.Put("/users/:id/password", bind(dtos.AdminUpdateUserPasswordForm{}), AdminUpdateUserPassword)
|
||||||
r.Delete("/users/:id", AdminDeleteUser)
|
r.Delete("/users/:id", AdminDeleteUser)
|
||||||
}, reqGrafanaAdmin)
|
}, reqGrafanaAdmin)
|
||||||
|
|
||||||
|
@ -12,3 +12,7 @@ type AdminUpdateUserForm struct {
|
|||||||
Login string `json:"login"`
|
Login string `json:"login"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AdminUpdateUserPasswordForm struct {
|
||||||
|
Password string `json:"password" binding:"Required"`
|
||||||
|
}
|
||||||
|
@ -11,10 +11,7 @@ function (angular) {
|
|||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
if ($routeParams.id) {
|
if ($routeParams.id) {
|
||||||
$scope.createMode = false;
|
|
||||||
$scope.getUser($routeParams.id);
|
$scope.getUser($routeParams.id);
|
||||||
} else {
|
|
||||||
$scope.createMode = true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -25,17 +22,29 @@ function (angular) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.setPassword = function () {
|
||||||
|
if (!$scope.passwordForm.$valid) { return; }
|
||||||
|
|
||||||
|
var payload = { password: $scope.password };
|
||||||
|
backendSrv.put('/api/admin/users/' + $scope.user_id + '/password', payload).then(function() {
|
||||||
|
$location.path('/admin/users');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.create = function() {
|
||||||
|
if (!$scope.userForm.$valid) { return; }
|
||||||
|
|
||||||
|
backendSrv.post('/api/admin/users', $scope.user).then(function() {
|
||||||
|
$location.path('/admin/users');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
$scope.update = function() {
|
$scope.update = function() {
|
||||||
if (!$scope.userForm.$valid) { return; }
|
if (!$scope.userForm.$valid) { return; }
|
||||||
if ($scope.createMode) {
|
|
||||||
backendSrv.post('/api/admin/users', $scope.user).then(function() {
|
backendSrv.put('/api/admin/users/' + $scope.user_id + '/details', $scope.user).then(function() {
|
||||||
$location.path('/admin/users');
|
$location.path('/admin/users');
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
backendSrv.put('/api/admin/users/' + $scope.user_id, $scope.user).then(function() {
|
|
||||||
$location.path('/admin/users');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.init();
|
$scope.init();
|
||||||
|
@ -2,18 +2,14 @@
|
|||||||
<ul class="nav">
|
<ul class="nav">
|
||||||
<li><a href="admin/settings">Settings</a></li>
|
<li><a href="admin/settings">Settings</a></li>
|
||||||
<li><a href="admin/users">Users</a></li>
|
<li><a href="admin/users">Users</a></li>
|
||||||
<li ng-class="{active: createMode}"><a href="admin/users/create">Create user</a></li>
|
<li><a href="admin/users/create">Create user</a></li>
|
||||||
<li class="active" ng-show="!createMode"><a href="admin/users/edit/{{user_id}}">Edit user</a></li>
|
<li class="active"><a href="admin/users/edit/{{user_id}}">Edit user</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</topnav>
|
</topnav>
|
||||||
|
|
||||||
<div class="page-container">
|
<div class="page-container">
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<h2 ng-show="createMode">
|
<h2>
|
||||||
Create a new user
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<h2 ng-show="!createMode">
|
|
||||||
Edit user
|
Edit user
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
@ -52,14 +48,25 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="tight-form" style="margin-top: 5px" ng-if="createMode">
|
<br>
|
||||||
|
<button type="submit" class="pull-right btn btn-success" ng-click="update()" ng-show="!createMode">Update</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
Change password
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<form name="passwordForm">
|
||||||
|
<div>
|
||||||
|
<div class="tight-form">
|
||||||
<ul class="tight-form-list">
|
<ul class="tight-form-list">
|
||||||
<li class="tight-form-item" style="width: 100px">
|
<li class="tight-form-item" style="width: 100px">
|
||||||
<strong>Password</strong>
|
<strong>New password</strong>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<input type="password" required ng-model="user.password" class="input-xxlarge tight-form-input last" >
|
<input type="password" required ng-minlength="4" ng-model="password" class="input-xxlarge tight-form-input last">
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
@ -67,8 +74,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<button type="submit" class="pull-right btn btn-success" ng-click="update()" ng-show="createMode">Create</button>
|
<button type="submit" class="pull-right btn btn-success" ng-click="setPassword()">Change password</button>
|
||||||
<button type="submit" class="pull-right btn btn-success" ng-click="update()" ng-show="!createMode">Update</button>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Login</th>
|
<th>Login</th>
|
||||||
<th>Email</th>
|
<th>Email</th>
|
||||||
<th>Admin</th>
|
<th>Grafana Admin</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr ng-repeat="user in users">
|
<tr ng-repeat="user in users">
|
||||||
|
@ -75,7 +75,7 @@ define([
|
|||||||
controller : 'AdminUsersCtrl',
|
controller : 'AdminUsersCtrl',
|
||||||
})
|
})
|
||||||
.when('/admin/users/create', {
|
.when('/admin/users/create', {
|
||||||
templateUrl: 'app/features/admin/partials/edit_user.html',
|
templateUrl: 'app/features/admin/partials/new_user.html',
|
||||||
controller : 'AdminEditUserCtrl',
|
controller : 'AdminEditUserCtrl',
|
||||||
})
|
})
|
||||||
.when('/admin/users/edit/:id', {
|
.when('/admin/users/edit/:id', {
|
||||||
|
Loading…
Reference in New Issue
Block a user