* [COMPLIANCE] Add Copyright and License Headers * chore: 🤖 update Copyright headers to satisfy our lint rules --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
85 lines
1.9 KiB
JavaScript
85 lines
1.9 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
import GeneratedAccountModel from '../generated/models/account';
|
|
import { computed } from '@ember/object';
|
|
import { equal } from '@ember/object/computed';
|
|
|
|
export default class AccountModel extends GeneratedAccountModel {
|
|
// =attributes
|
|
|
|
/**
|
|
* @type {boolean}
|
|
*/
|
|
@equal('type', 'password') isPassword;
|
|
|
|
/**
|
|
* @type {boolean}
|
|
*/
|
|
@equal('type', 'oidc') isOIDC;
|
|
|
|
/**
|
|
* Convenience for getting username in account.
|
|
* @type {string}
|
|
*/
|
|
@computed('{email,full_name,login_name}')
|
|
get accountName() {
|
|
const { email, full_name, login_name } = this;
|
|
return email || full_name || login_name;
|
|
}
|
|
|
|
// =methods
|
|
|
|
/**
|
|
* Save account password via the `set-password` method.
|
|
* See serializer and adapter for more information.
|
|
* @param {string} password
|
|
* @param {object} options
|
|
* @param {object} options.adapterOptions
|
|
* @return {Promise}
|
|
*/
|
|
setPassword(password, options = { adapterOptions: {} }) {
|
|
const defaultAdapterOptions = {
|
|
method: 'set-password',
|
|
password,
|
|
};
|
|
return this.save({
|
|
...options,
|
|
adapterOptions: {
|
|
...defaultAdapterOptions,
|
|
...options.adapterOptions,
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Update account password via the `change-password` method.
|
|
* See serializer and adapter for more information.
|
|
* @param {string} currentPassword
|
|
* @param {string} newPassword
|
|
* @param {object} options
|
|
* @param {object} options.adapterOptions
|
|
* @return {Promise}
|
|
*/
|
|
changePassword(
|
|
currentPassword,
|
|
newPassword,
|
|
options = { adapterOptions: {} }
|
|
) {
|
|
const defaultAdapterOptions = {
|
|
method: 'change-password',
|
|
currentPassword,
|
|
newPassword,
|
|
};
|
|
return this.save({
|
|
...options,
|
|
adapterOptions: {
|
|
...defaultAdapterOptions,
|
|
...options.adapterOptions,
|
|
},
|
|
});
|
|
}
|
|
}
|