2020-09-14 10:45:56 -04:00
|
|
|
import GeneratedAccountModel from '../generated/models/account';
|
2020-09-14 11:45:48 -04:00
|
|
|
import { fragment } from 'ember-data-model-fragments/attributes';
|
2020-09-17 14:39:15 -04:00
|
|
|
import { computed } from '@ember/object';
|
2020-10-07 12:37:41 -04:00
|
|
|
import { equal } from '@ember/object/computed';
|
2020-09-14 10:45:56 -04:00
|
|
|
|
2020-09-14 11:45:48 -04:00
|
|
|
export default class AccountModel extends GeneratedAccountModel {
|
2020-09-17 14:39:15 -04:00
|
|
|
// =attributes
|
|
|
|
|
|
2020-09-14 11:45:48 -04:00
|
|
|
/**
|
|
|
|
|
* Attributes of this resource, if any, represented as a JSON fragment.
|
|
|
|
|
* @type {FragmentAccountAttributesModel}
|
|
|
|
|
*/
|
|
|
|
|
@fragment('fragment-account-attributes', { defaultValue: {} }) attributes;
|
|
|
|
|
|
2020-10-07 12:37:41 -04:00
|
|
|
/**
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
@equal('type', 'password') isPassword;
|
|
|
|
|
|
2021-06-04 14:23:08 -04:00
|
|
|
/**
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
@equal('type', 'oidc') isOIDC;
|
|
|
|
|
|
2020-09-17 14:39:15 -04:00
|
|
|
/**
|
2020-09-18 14:15:19 -04:00
|
|
|
* Convenience for getting username in account.
|
2020-09-17 14:39:15 -04:00
|
|
|
* @type {string}
|
|
|
|
|
*/
|
2021-06-17 14:09:31 -04:00
|
|
|
@computed('attributes.{email,full_name,login_name}')
|
|
|
|
|
get accountName() {
|
|
|
|
|
const { email, full_name, login_name } = this.attributes;
|
|
|
|
|
return email || full_name || login_name;
|
2020-09-17 14:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-15 16:51:07 -04:00
|
|
|
// =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}
|
|
|
|
|
*/
|
2020-09-16 14:29:02 -04:00
|
|
|
setPassword(password, options = { adapterOptions: {} }) {
|
2020-09-15 16:51:07 -04:00
|
|
|
const defaultAdapterOptions = {
|
|
|
|
|
method: 'set-password',
|
2020-09-16 14:29:02 -04:00
|
|
|
password,
|
2020-09-15 16:51:07 -04:00
|
|
|
};
|
|
|
|
|
return this.save({
|
|
|
|
|
...options,
|
|
|
|
|
adapterOptions: {
|
|
|
|
|
...defaultAdapterOptions,
|
2020-09-16 14:29:02 -04:00
|
|
|
...options.adapterOptions,
|
|
|
|
|
},
|
2020-09-15 16:51:07 -04:00
|
|
|
});
|
|
|
|
|
}
|
2020-09-16 14:56:52 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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}
|
|
|
|
|
*/
|
2020-09-17 14:39:15 -04:00
|
|
|
changePassword(
|
|
|
|
|
currentPassword,
|
|
|
|
|
newPassword,
|
|
|
|
|
options = { adapterOptions: {} }
|
|
|
|
|
) {
|
2020-09-16 14:56:52 -04:00
|
|
|
const defaultAdapterOptions = {
|
|
|
|
|
method: 'change-password',
|
|
|
|
|
currentPassword,
|
|
|
|
|
newPassword,
|
|
|
|
|
};
|
|
|
|
|
return this.save({
|
|
|
|
|
...options,
|
|
|
|
|
adapterOptions: {
|
|
|
|
|
...defaultAdapterOptions,
|
|
|
|
|
...options.adapterOptions,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-09-14 11:45:48 -04:00
|
|
|
}
|