mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 17:43:35 -06:00
If the auth config variable, disable_login_form, is set to true then the username and email fields are set to read-only on the profile page. The reason for this is so that the user does not lock themselves out by changing their email address or username. Or create a new user by changing both. ref #7810
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
///<reference path="../../headers/common.d.ts" />
|
|
|
|
import config from 'app/core/config';
|
|
import {coreModule} from 'app/core/core';
|
|
import _ from 'lodash';
|
|
|
|
export class ProfileCtrl {
|
|
user: any;
|
|
old_theme: any;
|
|
orgs: any = [];
|
|
userForm: any;
|
|
showOrgsList = false;
|
|
readonlyLoginFields = config.disableLoginForm;
|
|
|
|
/** @ngInject **/
|
|
constructor(private backendSrv, private contextSrv, private $location) {
|
|
this.getUser();
|
|
this.getUserOrgs();
|
|
}
|
|
|
|
getUser() {
|
|
this.backendSrv.get('/api/user').then(user => {
|
|
this.user = user;
|
|
this.user.theme = user.theme || 'dark';
|
|
});
|
|
}
|
|
|
|
getUserOrgs() {
|
|
this.backendSrv.get('/api/user/orgs').then(orgs => {
|
|
this.orgs = orgs;
|
|
this.showOrgsList = orgs.length > 1;
|
|
});
|
|
}
|
|
|
|
setUsingOrg(org) {
|
|
this.backendSrv.post('/api/user/using/' + org.orgId).then(() => {
|
|
window.location.href = config.appSubUrl + '/profile';
|
|
});
|
|
}
|
|
|
|
update() {
|
|
if (!this.userForm.$valid) { return; }
|
|
|
|
this.backendSrv.put('/api/user/', this.user).then(() => {
|
|
this.contextSrv.user.name = this.user.name || this.user.login;
|
|
if (this.old_theme !== this.user.theme) {
|
|
window.location.href = config.appSubUrl + this.$location.path();
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
coreModule.controller('ProfileCtrl', ProfileCtrl);
|