ref: change auth setting in Login Screen
This commit is contained in:
parent
9d31ea245c
commit
12c90ff120
26 changed files with 1149 additions and 99 deletions
72
package/config/api/Admin/user/SaveUser/page.tsx
Normal file
72
package/config/api/Admin/user/SaveUser/page.tsx
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import { BASE_URL_ADMINISTRATION } from "@package/config/ApiPath";
|
||||
import { FetchData } from "@package/config/FetchData";
|
||||
import { ReturnService } from "@package/config/ReturnService";
|
||||
import { DEFAULT_PASSWORD } from "@package/utils/Constants";
|
||||
import i18n from "@package/utils/language/i18n";
|
||||
import { encrypt, getKeyApi } from "@package/utils/Utilities";
|
||||
|
||||
const BASE_URL_LANGUAGE = i18n.language
|
||||
|
||||
interface UserObject {
|
||||
id?: string;
|
||||
idSubsidiary?: number;
|
||||
idCompany?: number;
|
||||
name?: string;
|
||||
lastName?: string;
|
||||
email?: string;
|
||||
cellphone?: string;
|
||||
password?: string;
|
||||
type?: string;
|
||||
isActive?: boolean;
|
||||
isAdmin?: boolean;
|
||||
}
|
||||
|
||||
async function SaveUser(ae_object: UserObject) {
|
||||
const token = getKeyApi()
|
||||
if (token === '') {
|
||||
return new ReturnService('', false, i18n.t('errorTokenAPI'), 102)
|
||||
}
|
||||
|
||||
if ((ae_object.id ?? '').trim().length <= 0 && (ae_object.password ?? '').trim().length <= 0) {
|
||||
ae_object.password = DEFAULT_PASSWORD
|
||||
}
|
||||
|
||||
if ((ae_object.password ?? '').trim().length > 0) {
|
||||
ae_object.password = encrypt(ae_object.password ?? '')
|
||||
}
|
||||
|
||||
const options = {
|
||||
method: 'post',
|
||||
mode: 'cors' as RequestMode,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: 'Bearer ' + token,
|
||||
lng: BASE_URL_LANGUAGE
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: (ae_object.id ?? '').trim(),
|
||||
idSubsidiary: ae_object.idSubsidiary ?? 0,
|
||||
idCompany: ae_object.idCompany ?? 0,
|
||||
name: ae_object.name ?? '',
|
||||
lastName: ae_object.lastName ?? '',
|
||||
email: ae_object.email ?? '',
|
||||
cellphone: ae_object.cellphone ?? '',
|
||||
password: ae_object.password ?? '',
|
||||
idTypeUser: ae_object.type ?? '',
|
||||
isActive: ae_object.isActive ?? false,
|
||||
isAdmin: ae_object.isAdmin ?? false
|
||||
})
|
||||
}
|
||||
|
||||
const data = await FetchData(BASE_URL_ADMINISTRATION, 'user/save', options)
|
||||
|
||||
let result = data;
|
||||
if (data.correct) {
|
||||
result = data.object as ReturnService<unknown>
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
export { SaveUser }
|
||||
Loading…
Add table
Add a link
Reference in a new issue