Files
myprojplanet_vite/src/store/UserStore.ts

1538 lines
46 KiB
TypeScript
Raw Normal View History

2021-08-31 18:09:59 +02:00
import { defineStore } from 'pinia'
import {
2022-10-29 12:37:30 +02:00
ICircuit,
IMyCircuit,
IFriends,
IMsgGlobParam,
2021-09-16 21:08:02 +02:00
ISigninOptions,
2022-10-29 12:37:30 +02:00
ISignupOptions,
IUserFields,
IUserNotifType,
IUserProfile,
IUserState,
IAccount,
IColGridTable,
ISignupIscrizioneConacreisOptions,
ISignupIscrizioneArcadeiOptions,
2021-08-31 18:09:59 +02:00
} from '@src/model'
import { tools } from '@store/Modules/tools'
import translate from '@src/globalroutines/util'
2021-09-16 21:08:02 +02:00
import { ICallResult, ILinkReg, IResult, IToken } from '@model/other'
2021-08-31 18:09:59 +02:00
import * as Types from '@src/store/Api/ApiTypes'
import { useGlobalStore } from '@store/globalStore'
import { serv_constants } from '@store/Modules/serv_constants'
2021-09-16 21:08:02 +02:00
import { Api } from '@api'
2021-08-31 18:09:59 +02:00
import { toolsext } from '@store/Modules/toolsext'
2021-09-16 21:08:02 +02:00
import { static_data } from '@src/db/static_data'
import bcrypt from 'bcryptjs'
2022-11-10 19:32:56 +01:00
2021-09-16 21:08:02 +02:00
import { useTodoStore } from '@store/Todos'
import { Router } from 'vue-router'
import { useProjectStore } from '@store/Projects'
import { shared_consts } from '@/common/shared_vuejs'
2022-01-12 00:38:31 +01:00
import { costanti } from '@costanti'
2023-01-03 16:51:45 +01:00
import { IGroupShort, IMyGroup, IUserAdmins } from '@model/UserStore'
2021-08-31 18:09:59 +02:00
import globalroutines from '../globalroutines/index'
2022-09-13 12:28:33 +02:00
import { useNotifStore } from '@store/NotifStore'
import { useCircuitStore } from './CircuitStore'
2021-08-31 18:09:59 +02:00
export const DefaultUser: IUserFields = {
_id: '',
email: '',
username: '',
name: '',
surname: '',
password: '',
tokens: [],
verified_email: false,
2021-12-29 18:26:41 +01:00
verified_by_aportador: false,
2021-08-31 18:09:59 +02:00
aportador_solidario: '',
made_gift: false,
profile: {
img: '',
teleg_id: 0,
saw_zoom_presentation: false,
ask_zoom_partecipato: false,
saw_and_accepted: false,
qualified: false,
qualified_2invitati: false,
socio: false,
socioresidente: false,
myshares: [],
friends: [],
req_friends: [],
2023-01-06 15:51:58 +01:00
handshake: [],
2022-02-04 23:48:53 +01:00
mygroups: [],
mycircuits: [],
manage_mygroups: [],
asked_friends: [],
2022-02-03 00:33:05 +01:00
asked_groups: [],
refused_groups: [],
2022-07-21 00:20:48 +02:00
notifs: [],
notif_idCities: [],
notif_provinces: [],
notif_regions: [],
notif_sectors: [],
notif_sector_goods: [],
2022-08-26 03:32:50 +02:00
asked_circuits: [],
refused_circuits: [],
manage_mycircuits: [],
2022-09-03 13:06:35 +02:00
useraccounts: [],
calc: { numGoodsAndServices: 0 },
2021-08-31 18:09:59 +02:00
},
cart: {
userId: '',
items: [],
totalPrice: 0,
department: '',
totalQty: 0,
note: '',
},
}
export const DefaultProfile: IUserProfile = {
img: '',
nationality: '',
intcode_cell: '',
cell: process.env.TEST_CELL || '',
2021-12-29 18:26:41 +01:00
dateofbirth: null,
2021-08-31 18:09:59 +02:00
sex: 0,
country_pay: '',
email_paypal: '',
payeer_id: '',
advcash_id: '',
revolut: '',
link_payment: '',
note_payment: '',
username_telegram: '',
teleg_id: 0,
teleg_checkcode: 0,
my_dream: '',
manage_telegram: false,
saw_zoom_presentation: false,
ask_zoom_partecipato: false,
saw_and_accepted: false,
socio: false,
socioresidente: false,
paymenttypes: [],
qualified: false,
qualified_2invitati: false,
myshares: [],
friends: [],
req_friends: [],
2023-01-06 15:51:58 +01:00
handshake: [],
2022-02-04 23:48:53 +01:00
mygroups: [],
mycircuits: [],
manage_mygroups: [],
asked_friends: [],
2022-02-03 00:33:05 +01:00
asked_groups: [],
refused_groups: [],
2022-07-21 00:20:48 +02:00
notifs: [],
notif_idCities: [],
notif_provinces: [],
notif_regions: [],
notif_sectors: [],
notif_sector_goods: [],
2022-08-26 03:32:50 +02:00
asked_circuits: [],
refused_circuits: [],
manage_mycircuits: [],
2022-09-03 13:06:35 +02:00
useraccounts: [],
calc: { numGoodsAndServices: 0 },
2021-08-31 18:09:59 +02:00
}
export const useUserStore = defineStore('UserStore', {
state: () => ({
my: { ...DefaultUser },
2023-01-09 04:05:18 +01:00
userprofile: DefaultUser,
2022-02-03 00:33:05 +01:00
groups: [],
2021-08-31 18:09:59 +02:00
lang: process.env.LANG_DEFAULT ? process.env.LANG_DEFAULT : 'it',
repeatPassword: '',
categorySel: 'personal',
servercode: 0,
resStatus: 0,
x_auth_token: '',
isLogged: false,
isAdmin: false,
isManager: false,
isDepartment: false,
isFacilitatore: false,
2021-08-31 18:09:59 +02:00
isZoomeri: false,
isTratuttrici: false,
isEditor: false,
isTeacher: false,
2021-08-31 18:09:59 +02:00
usersList: [],
countusers: 0,
lastparamquery: {},
updateTables: false,
2021-08-31 18:09:59 +02:00
}),
getters: {
isServerError(): boolean {
return (this.servercode === toolsext.ERR_SERVERFETCH)
},
getServerCode: (state: IUserState): number => (state.servercode ? state.servercode : 0),
2021-09-16 21:08:02 +02:00
getMsg: (state: IUserState): string => (state.msg ? state.msg : ''),
2021-08-31 18:09:59 +02:00
2021-09-02 03:22:13 +02:00
getUsersList: (mystate: IUserState) => {
return mystate.usersList
},
IsMyFriend: (mystate: IUserState) => (userIdOwner: string): boolean => {
// ++TODO Check if userIdOwner is my friend
// userIdOwner is my friend ?
return true
},
2021-09-02 03:22:13 +02:00
IsMyGroup: (mystate: IUserState) => (userIdOwner: string): boolean => {
// ++TODO Check if userIdOwner is on my groups
// userIdOwner is on my groups ?
return true
},
2021-09-02 21:29:24 +02:00
isTokenInvalid: (state: IUserState) => {
try {
return (state.my.tokens!.length <= 0)
} catch (e) {
return true
}
},
2021-08-31 18:09:59 +02:00
isUserInvalid: (state: IUserState): boolean => {
try {
return (state.my._id === undefined) || (state.my._id.trim() === '')
} catch (e) {
return true
}
},
2021-09-19 02:59:24 +02:00
},
actions: {
IsMyFriendByUsername(username: string): boolean {
if (this.my.profile.friends)
return this.my.profile.friends.findIndex((rec) => rec.username === username) >= 0
else
return false
},
2023-01-06 15:51:58 +01:00
IsHandShakeByUsername(username: string): boolean {
if (this.my.profile.handshake)
return this.my.profile.handshake.findIndex((rec) => rec.username === username) >= 0
else
return false
},
2023-01-09 02:39:53 +01:00
IsHandShakeByMe(user: IUserFields): boolean {
if (user && user.profile && user.profile.handshake)
return user.profile.handshake.findIndex((rec) => rec.username === this.my.username) >= 0
else
return false
},
2022-02-03 00:33:05 +01:00
IsMyGroupByGroupname(groupname: string): boolean {
if (this.my.profile.mygroups)
2022-02-04 23:48:53 +01:00
return this.my.profile.mygroups.findIndex((rec) => rec.groupname === groupname) >= 0
2022-02-03 00:33:05 +01:00
else
return false
},
getMyGroupByGroupname(groupname: string): IMyGroup | null {
if (this.my.profile.mygroups) {
const ris = this.my.profile.mygroups.find((rec) => rec.groupname === groupname)
return ris ? ris : null
} else {
return null
}
},
2023-02-02 13:53:09 +01:00
GroupsListWhereIAmAdmin(): any {
try {
return this.my.profile.manage_mygroups
} catch (e) {
return []
}
},
GroupsListWhereIAmAdminInTheCircuit(circuitname: string): any {
try {
const arr: any = this.my.profile.manage_mygroups.filter((group: IMyGroup) => (group.mycircuits!.findIndex((circ: IMyCircuit) => circ.circuitname === circuitname) >= 0))
console.log('arr', arr)
return arr
} catch (e) {
return []
}
2023-01-03 16:51:45 +01:00
},
2023-02-02 13:53:09 +01:00
hoContiComunitariDaAmministrare(): boolean {
try {
const arr: any = this.my.profile.manage_mygroups.filter((group: IMyGroup) => (group.mycircuits!.length > 0))
return !!arr
} catch (e) {
return false
}
},
2023-02-01 01:19:58 +01:00
hoContiCollettiviDaAmministrare(): boolean {
const arr = this.my.profile.manage_mygroups.find((group: IMyGroup) => group.account)
return arr ? true : false
},
IsAskedFriendByUsername(username: string): boolean {
if (this.my.profile.asked_friends)
return this.my.profile.asked_friends.findIndex((rec) => rec.username === username) >= 0
else
return false
},
IsReqFriendByUsername(username: string): boolean {
if (this.my.profile.req_friends)
return this.my.profile.req_friends.findIndex((rec) => rec.username === username) >= 0
else
return false
},
2022-02-03 00:33:05 +01:00
IsAskedGroupByGroupname(groupname: string): boolean {
if (this.my.profile.asked_groups)
2023-01-03 16:51:45 +01:00
return this.my.profile.asked_groups.findIndex((rec: IGroupShort) => rec.groupname === groupname) >= 0
2022-02-03 00:33:05 +01:00
else
return false
},
IsRefusedGroupByGroupname(groupname: string): boolean {
if (this.my.profile.refused_groups)
2023-01-03 16:51:45 +01:00
return this.my.profile.refused_groups.findIndex((rec: IGroupShort) => rec.groupname === groupname) >= 0
else
return false
},
2021-09-19 02:59:24 +02:00
getUserByUsername(username: string): IUserFields | null {
// Check if is this User!
if (this.my.username === username) return this.my
2022-11-10 19:32:56 +01:00
let trovato: any = null
2021-09-19 02:59:24 +02:00
if (this.usersList) trovato = this.usersList.find((item: any) => item.username === username)
if (trovato) {
if (trovato.surname === 'undefined')
trovato.surname = ''
if (trovato.name === 'undefined')
trovato.name = ''
}
2021-09-19 02:59:24 +02:00
return (trovato) || null
},
getImgByUsername(username: string): string {
if (username === '') return ''
// Check if is this User!
const myrec = this.getUserByUsername(username)
if (myrec && myrec.profile && !!myrec.profile.img && myrec.profile.img !== '' && myrec.profile.img !== 'undefined') {
return costanti.DIR_UPLOAD + 'profile/' + this.my.username + '/' + myrec.profile.img
2021-09-19 02:59:24 +02:00
}
return ''
},
getImgUserByUsername(username: string): string {
2022-11-10 19:32:56 +01:00
const img = this.getImgByUsername(username)
return img ? img : 'images/noimg-user.svg'
},
getImgUserByRow(row: any, col: IColGridTable): string {
let value = ''
if (row.hasOwnProperty(col.name)) {
value = row[col.name]
}
let tipoconto = costanti.AccountType.USER
2023-02-02 02:52:27 +01:00
if (col.hasOwnProperty('tipoconto') && col.tipoconto) {
tipoconto = col.tipoconto
}
let img = ''
if (tipoconto === costanti.AccountType.USER) {
img = this.getImgByUsername(value)
} else if (tipoconto === costanti.AccountType.COLLECTIVE_ACCOUNT) {
img = this.getImgByGroupname(value)
} else if (tipoconto === costanti.AccountType.COMMUNITY_ACCOUNT) {
img = this.getImgByCircuitpath(value)
}
if (row) {
const mycol = col.name + '.img'
if (row.hasOwnProperty(mycol)) {
img = row[mycol]
}
}
return img ? img : 'images/noimg-user.svg'
},
2022-12-11 02:57:45 +01:00
getImgByProfile(userparam: any, reale: any = false, col: any = null): string {
try {
2022-12-11 02:57:45 +01:00
let myrec = this.getRecByCol(userparam, col)
let img = ''
if (!reale)
img = 'images/noimg-user.svg'
2023-02-02 02:52:27 +01:00
let tipoconto = costanti.AccountType.USER
2023-02-06 23:50:55 +01:00
if (col && col.hasOwnProperty('tipoconto') && col.tipoconto) {
2023-02-02 02:52:27 +01:00
tipoconto = col.tipoconto
}
if (tipoconto === costanti.AccountType.COLLECTIVE_ACCOUNT) {
img = this.getImgByGroupname(myrec.groupname)
2023-02-02 02:52:27 +01:00
} else if (tipoconto === costanti.AccountType.COMMUNITY_ACCOUNT) {
img = this.getImgByCircuitpath(myrec.path)
2022-12-11 02:57:45 +01:00
} else {
if (myrec.profile && myrec.profile.img) {
img = costanti.DIR_UPLOAD + 'profile/' + myrec.username + '/' + myrec.profile.img
}
2022-01-03 21:53:41 +01:00
}
return img
} catch (e) {
2022-11-10 19:32:56 +01:00
//
}
if (!reale)
2022-12-11 02:57:45 +01:00
return 'images/noimg-user.svg'
else
return ''
2022-01-03 21:53:41 +01:00
},
2022-08-30 17:00:32 +02:00
IsAskedCircuitByName(name: string): boolean {
2022-08-30 17:00:32 +02:00
if (this.my.profile.asked_circuits)
return this.my.profile.asked_circuits.findIndex((rec: ICircuit) => rec.name === name) >= 0
2022-08-30 17:00:32 +02:00
else
return false
},
IsMyCircuitByName(circuitname: string): boolean {
2022-08-30 17:00:32 +02:00
if (this.my.profile.mycircuits)
return this.my.profile.mycircuits.findIndex((rec: IMyCircuit) => rec.circuitname === circuitname) >= 0
2022-08-30 17:00:32 +02:00
else
return false
},
2023-01-03 16:51:45 +01:00
IsMyCircuitByNameAndGroup(circuitname: string, groupname: string): boolean {
const globalStore = useGlobalStore()
if (globalStore.mygroups) {
const group: IMyGroup | undefined = globalStore.mygroups.find((rec: IMyGroup) => rec.groupname === groupname)
if (group && group.mycircuits) {
return group.mycircuits.findIndex((rec: any) => rec.circuitname === circuitname) >= 0
}
return false
} else
return false
},
getMyCircuitsInCommonByUser(user: IUserFields): any[] {
2022-09-03 13:06:35 +02:00
if (!this.my.profile.mycircuits || (!user || !user.profile || !user.profile.mycircuits))
return []
2022-09-14 11:31:48 +02:00
return tools.getCommon([...this.my.profile.mycircuits], [...user.profile.mycircuits], 'circuitname')
2022-09-03 13:06:35 +02:00
},
2023-02-01 01:19:58 +01:00
getMyCircuits(): any[] {
if (!this.my.profile.mycircuits)
return []
return this.my.profile.mycircuits.map(item => item.circuitname)
},
2023-01-03 16:51:45 +01:00
getMyCircuitsInCommonByGroup(group: IMyGroup): any[] {
if (!this.my.profile.mycircuits || (!group || !group.mycircuits))
return []
return tools.getCommon([...this.my.profile.mycircuits], [...group.mycircuits], 'circuitname')
},
2023-01-08 02:17:15 +01:00
getMyHandshakeInCommon(myuser: IUserFields): any[] {
if (!this.my.profile.handshake || (!myuser || !myuser.profile.handshake))
return []
return tools.getCommonAllRecord([...this.my.profile.handshake], [...myuser.profile.handshake], 'username')
},
2022-09-14 11:31:48 +02:00
getAccountByCircuitId(circuitId: string): any {
if (this.my.profile.useraccounts) {
return this.my.profile.useraccounts.find((rec: IAccount) => rec.circuitId === circuitId)
}
return null
2022-09-03 13:06:35 +02:00
},
getAccountsListNameValue(): any[] {
let arr = []
const circuitStore = useCircuitStore()
if (this.my.profile.useraccounts) {
for (const acc of this.my.profile.useraccounts) {
let chi = acc.username ? acc.username : (acc.groupname ? acc.groupname : acc.contocom)
if (acc.circuit) {
chi += ' (' + circuitStore.getNameByCircuitId(acc.circuitId) + ')'
}
arr.push({label: chi, value: acc._id})
}
}
return arr
},
2022-09-03 13:06:35 +02:00
IsRefusedCircuitByName(circuitname: string): boolean {
2022-08-30 17:00:32 +02:00
if (this.my.profile.refused_circuits)
return this.my.profile.refused_circuits.findIndex((rec: ICircuit) => rec.name === circuitname) >= 0
2022-08-30 17:00:32 +02:00
else
return false
},
getImgByCircuit(circ: ICircuit | null): string {
2022-08-26 03:32:50 +02:00
try {
if (circ && circ.photos && circ.photos.length > 0)
return costanti.DIR_UPLOAD + 'circuits/' + circ.path + '/' + circ.photos[0].imagefile
2022-08-26 03:32:50 +02:00
} catch (e) {
}
return 'images/noimg.png'
},
getImgByCircuitpath(circuitpath: string): string {
const circuitStore = useCircuitStore()
const mycirc = circuitStore.getCircuitByPath(circuitpath)
return this.getImgByCircuit(mycirc)
},
getImgByGroup(group: IMyGroup | null): string {
2022-02-03 00:33:05 +01:00
try {
2022-11-10 19:32:56 +01:00
// ++Todo: Sistemare!
if (group) {
return costanti.DIR_UPLOAD + 'mygroups/' + group.groupname + '/' + group.photos[0].imagefile
}
2022-02-03 00:33:05 +01:00
} catch (e) {
}
return 'images/noimg.png'
},
getImgByGroupname(groupname: string): string {
const mygroup = this.getMyGroupByGroupname(groupname)
return this.getImgByGroup(mygroup)
},
2021-12-29 18:26:41 +01:00
getRefLink(username: string): string {
if (username === '')
username = this.my.username
2023-02-20 02:20:00 +01:00
return tools.getUrlSite() + '/registrati/' + username
2021-12-29 18:26:41 +01:00
},
isUserOk(): boolean {
2022-12-09 01:03:52 +01:00
const globalStore = useGlobalStore()
if (globalStore.site.confpages.enableRegMultiChoice) {
return ((this.my.profile.teleg_id! > 0 && this.isUsernameTelegOk()) || this.my.verified_email!) && this.my.verified_by_aportador!
2022-12-09 01:03:52 +01:00
} else {
return this.my.profile.teleg_id! > 0 && this.my.verified_by_aportador! && this.isUsernameTelegOk()
}
// return this.my.verified_email! && this.my.profile.teleg_id! > 0 && this.my.verified_by_aportador!
2021-09-19 02:59:24 +02:00
},
isUserWaitingVerifAportador(): boolean {
return tools.isLogged() && !this.my.verified_by_aportador
},
isOldRegNotFinished(): boolean {
return tools.isLogged() && ((!this.my.profile.teleg_id || this.my.profile.teleg_id <= 0) || !this.isUsernameTelegOk())
// return this.my.verified_email! && this.my.profile.teleg_id! > 0 && this.my.verified_by_aportador!
},
2022-02-21 18:14:38 +01:00
isTelegOk(): boolean {
return this.my.profile.teleg_id! > 0
// return this.my.verified_email! && this.my.profile.teleg_id! > 0 && this.my.verified_by_aportador!
},
isUsernameTelegOk(): boolean {
return !!this.my.profile.username_telegram
// return this.my.verified_email! && this.my.profile.teleg_id! > 0 && this.my.verified_by_aportador!
},
2021-09-19 02:59:24 +02:00
getNameSurnameByUserId(userId: string): string {
const user = this.getUserByUserId(userId)
if (user) return `${user.name} ` + !!user.surname ? user.surname : ''
2021-09-19 02:59:24 +02:00
return `(${userId})`
},
getNameSurnameByUsername(username: string): string {
2022-11-10 19:32:56 +01:00
const user = this.getUserByUsername(username)
if (user) return `${user.name} ` + !!user.surname ? user.surname : ''
2021-09-19 02:59:24 +02:00
return `(${username})`
},
2022-12-11 02:57:45 +01:00
getRecByCol(user: any, col: any = null) {
let myrec = user
if (col && col.field === 'userto')
myrec = user.userto
else if (col && col.field === 'groupto')
myrec = user.groupto
else if (col && col.field === 'userfrom')
2022-12-11 02:57:45 +01:00
myrec = user.userfrom
else if (col && col.field === 'groupfrom')
myrec = user.groupfrom
else if (col && col.field === 'contocomfrom')
myrec = user.contocomfrom
else if (col && col.field === 'contocomto')
myrec = user.contocomto
2022-12-11 02:57:45 +01:00
return myrec
},
getNameToShow(user: any, col: any = null): string {
2022-12-09 03:09:16 +01:00
let name = ''
2022-12-11 02:57:45 +01:00
let myrec = this.getRecByCol(user, col)
2023-02-02 02:52:27 +01:00
let tipoconto = costanti.AccountType.USER
if (col && col.hasOwnProperty('tipoconto')) {
tipoconto = col.tipoconto
}
if (tipoconto === costanti.AccountType.USER) {
if (!!myrec.name)
name = myrec.name + ' '
if (!!myrec.surname)
name += myrec.surname + ' '
2022-12-09 03:09:16 +01:00
if (!name) {
name += myrec.username + ' '
}
if (col && col.field === 'extrarec' && !name) {
name = myrec.dest
}
2023-02-02 02:52:27 +01:00
} else if (tipoconto === costanti.AccountType.COLLECTIVE_ACCOUNT) {
if (myrec.hasOwnProperty('descr'))
return myrec.descr
else if (myrec.hasOwnProperty('groupname'))
return myrec.groupname
2023-02-02 02:52:27 +01:00
} else if (tipoconto === costanti.AccountType.COMMUNITY_ACCOUNT) {
if (myrec.hasOwnProperty('name'))
return myrec.name
else if (myrec.hasOwnProperty('contocom'))
return myrec.contocom
2022-12-09 03:09:16 +01:00
}
return name
},
2022-12-11 02:57:45 +01:00
getUserNameOnlyIfToShow(user: any, col: any = null): string {
let myrec = this.getRecByCol(user, col)
2022-12-10 02:01:26 +01:00
2022-12-11 02:57:45 +01:00
if (myrec.name || myrec.surname) {
return myrec.username
2022-12-10 02:01:26 +01:00
}
return ''
},
2021-09-19 02:59:24 +02:00
getUserByUserId(userId: string): IUserFields | null {
// Check if is this User!
if (this.my._id === userId) return this.my
2022-11-10 19:32:56 +01:00
let trovato: any = null
2021-09-19 02:59:24 +02:00
if (this.usersList) trovato = this.usersList.find((item: any) => item._id === userId)
if (trovato) {
if (trovato.surname === undefined)
trovato.surname = ''
if (trovato.name === undefined)
trovato.name = ''
}
2021-09-19 02:59:24 +02:00
return (trovato) || null
},
getMsgError(err: number): string {
2021-08-31 18:09:59 +02:00
let msgerrore = ''
if (err !== tools.OK) {
2021-09-19 02:59:24 +02:00
msgerrore = `Error [${this.servercode}]: `
if (this.servercode === toolsext.ERR_SERVERFETCH) {
2021-08-31 18:09:59 +02:00
msgerrore = translate('fetch.errore_server')
} else {
msgerrore = translate('fetch.errore_generico')
}
if (process.env.DEV) {
console.log('ERROREEEEEEEEE: ', msgerrore, ' (', err, ')')
}
}
// return { code: this.servercode, msg: msgerrore }
return msgerrore
},
clearAuthData() {
this.my = DefaultUser
// resetArrToken(mystate.my.tokens)
this.categorySel = 'personal'
this.servercode = 0
this.resStatus = 0
this.isLogged = false
this.x_auth_token = ''
return true
},
2021-09-16 21:08:02 +02:00
async resetpwd(paramquery: any) {
const mydata = { ...paramquery }
return bcrypt.hash(mydata.password, bcrypt.genSaltSync(12))
.then((hashedPassword: string) => {
mydata.repeatPassword = ''
mydata.password = String(hashedPassword)
return Api.SendReq('/updatepwd', 'POST', mydata, true)
.then((res) => {
return { code: res.data.code, msg: res.data.msg }
})
.catch((error: Types.AxiosError) => {
this.setErrorCatch(error)
return { code: this.getServerCode, msg: error.getMsgError() }
})
})
},
2021-09-19 02:59:24 +02:00
setErrorCatch(axerr: Types.AxiosError) {
try {
if (this.servercode !== toolsext.ERR_SERVERFETCH) {
this.servercode = axerr.getCode()
}
// this.msg = axerr.getMsg()
console.log('Err catch: (servercode:', axerr.getCode(), axerr.getMsgError(), ')')
} catch (e) {
console.log('Err catch:', axerr)
}
},
2021-08-31 18:09:59 +02:00
async setLangServer() {
const mydata = {
username: this.my.username,
lang: this.lang,
}
return Api.SendReq('/setlang', 'PATCH', { data: mydata })
.then((res) => {
if (res) {
return (res.data.code === serv_constants.RIS_CODE_OK)
2021-09-04 15:05:34 +02:00
}
return false
2021-08-31 18:09:59 +02:00
})
.catch((error: any) => false)
},
async requestpwd(paramquery: any) {
const usertosend = {
email: paramquery.email,
codetocheck: paramquery.tokenforgot_code,
2021-08-31 18:09:59 +02:00
}
console.log(usertosend)
this.setServerCode(tools.CALLING)
return Api.SendReq('/requestnewpwd', 'POST', usertosend)
.then((res) => ({ code: res.data.code, msg: res.data.msg, link: res.data.link })).catch((error) => {
2021-08-31 18:09:59 +02:00
this.setErrorCatch(error)
return this.getServerCode
})
},
async vreg(paramquery: ILinkReg) {
const usertosend = {
idlink: paramquery.idlink,
}
console.log(usertosend)
this.setServerCode(tools.CALLING)
return Api.SendReq('/vreg', 'POST', usertosend)
.then((res) => {
// console.log("RITORNO 2 ");
// mutations.setServerCode(myres);
if (res.data.code === serv_constants.RIS_CODE_EMAIL_VERIFIED) {
console.log('VERIFICATO !!')
2022-03-12 22:21:40 +01:00
tools.localStSetItem(toolsext.localStorage.verified_email, String(true))
2021-08-31 18:09:59 +02:00
} else {
console.log('Risultato di vreg: ', res.data.code)
}
return { code: res.data.code, msg: res.data.msg }
}).catch((error) => {
this.setErrorCatch(error)
2021-09-16 21:08:02 +02:00
return { code: this.getServerCode, msg: error.getMsgError() }
2021-08-31 18:09:59 +02:00
})
},
async unsubscribe(paramquery: any) {
return Api.SendReq('/news/unsubscribe', 'POST', paramquery)
.then((res) => {
// console.log("RITORNO 2 ");
// mutations.setServerCode(myres);
if (res.data.code === serv_constants.RIS_UNSUBSCRIBED_OK) {
console.log('DESOTTOSCRITTO ALLA NEWSLETTER !!')
} else {
console.log('Risultato di unsubscribe: ', res.data.code)
}
return { code: res.data.code, msg: res.data.msg }
}).catch((error) => this.getServerCode)
},
async importemail(paramquery: any) {
return Api.SendReq('/news/import', 'POST', paramquery)
.then((res) => res).catch((error) => ({ numtot: 0, numadded: 0, numalreadyexisted: 0 }))
},
2021-09-04 15:05:34 +02:00
async importExtraList(paramquery: any) {
return Api.SendReq('/users/import_extralist', 'POST', paramquery)
.then((res) => {
return res
}).catch((error) => {
return { numtot: 0, numadded: 0, numalreadyexisted: 0 }
})
},
async execDbOp(paramquery: any) {
return Api.SendReq('/users/dbop', 'POST', paramquery)
.then((res) => {
return res.data
}).catch((error) => {
return false
})
},
async newsletterload(paramquery: any) {
return Api.SendReq('/news/load', 'POST', paramquery)
.then((res) => {
// console.log('res', res)
return res.data
}).catch((error) => {
return null
})
},
async reportload(paramquery: any) {
return Api.SendReq('/report/load', 'POST', paramquery)
.then((res) => {
// console.log('res', res)
return res.data
}).catch((error) => {
return null
})
},
async newsletter_setactivate(paramquery: any) {
return Api.SendReq('/news/setactivate', 'POST', paramquery)
.then((res) => {
// console.log('res', res)
return res.data
}).catch((error) => {
return null
})
},
2021-08-31 18:09:59 +02:00
authUser(data: IUserFields) {
2021-12-29 18:26:41 +01:00
try {
this.my = { ...data }
// console.log('**** my', this.my)
2021-12-29 18:26:41 +01:00
if (!this.my.profile) {
this.my.profile = DefaultProfile
// Memory
this.my.profile.manage_mygroups = []
this.my.profile.asked_friends = []
2022-02-03 00:33:05 +01:00
this.my.profile.asked_groups = []
this.my.profile.refused_groups = []
2021-12-29 18:26:41 +01:00
}
2021-12-29 18:26:41 +01:00
this.isAdmin = tools.isBitActive(this.my.perm, shared_consts.Permissions.Admin.value)
this.isManager = tools.isBitActive(this.my.perm, shared_consts.Permissions.Manager.value)
this.isFacilitatore = tools.isBitActive(this.my.perm, shared_consts.Permissions.Facilitatore.value)
2021-12-29 18:26:41 +01:00
this.isZoomeri = tools.isBitActive(this.my.perm, shared_consts.Permissions.Zoomeri.value)
this.isDepartment = tools.isBitActive(this.my.perm, shared_consts.Permissions.Department.value)
this.isTeacher = tools.isBitActive(this.my.perm, shared_consts.Permissions.Teacher.value)
this.isEditor = tools.isBitActive(this.my.perm, shared_consts.Permissions.Editor.value)
2021-12-29 18:26:41 +01:00
this.my.tokens = []
this.resetArrToken(this.my.tokens)
this.my.tokens.push({ access: 'auth', token: this.x_auth_token, data_login: tools.getDateNow() })
} catch (e) {
console.log('Error authUser: ' + e)
}
2021-08-31 18:09:59 +02:00
},
updateLocalStorage(myuser: IUserFields) {
const globalStore = useGlobalStore()
const now = tools.getDateNow()
// const expirationDate = new Date(now.getTime() + myres.data.expiresIn * 1000);
const expirationDate = new Date(now.getTime() * 1000)
2022-03-12 22:21:40 +01:00
tools.localStSetItem(toolsext.localStorage.lang, this.lang)
tools.localStSetItem(toolsext.localStorage.userId, myuser._id)
tools.localStSetItem(toolsext.localStorage.username, myuser.username)
tools.localStSetItem(toolsext.localStorage.name, myuser.name)
tools.localStSetItem(toolsext.localStorage.surname, myuser.surname)
tools.localStSetItem(toolsext.localStorage.perm, String(myuser.perm) || '')
if (myuser.profile !== undefined) tools.localStSetItem(toolsext.localStorage.img, (myuser.profile.img) ? String(myuser.profile.img) || '' : '')
else tools.localStSetItem(toolsext.localStorage.img, '')
localStorage.setItem(toolsext.localStorage.token, this.x_auth_token)
localStorage.setItem(toolsext.localStorage.expirationDate, expirationDate.toString())
2022-03-12 22:21:40 +01:00
tools.localStSetItem(toolsext.localStorage.isLogged, String(true))
tools.localStSetItem(toolsext.localStorage.verified_email, String(myuser.verified_email))
tools.localStSetItem(toolsext.localStorage.verified_by_aportador, String(myuser.verified_by_aportador))
tools.localStSetItem(toolsext.localStorage.teleg_id, String(myuser.profile.teleg_id))
tools.localStSetItem(toolsext.localStorage.made_gift, String(myuser.made_gift))
tools.localStSetItem(toolsext.localStorage.wasAlreadySubOnDb, String(globalStore.wasAlreadySubOnDb))
2021-08-31 18:09:59 +02:00
},
setusersList(usersList: IUserFields[]) {
// console.log('setusersList', usersList)
// @ts-ignore
this.usersList = [...usersList]
},
2022-11-13 22:39:25 +01:00
setlang($q: any, $router: Router, newstr: string) {
2021-08-31 18:09:59 +02:00
console.log('SETLANG', newstr)
this.lang = newstr
2022-11-13 22:39:25 +01:00
toolsext.setLangAtt($q, $router, newstr)
2022-03-12 22:21:40 +01:00
tools.localStSetItem(toolsext.localStorage.lang, this.lang)
2021-08-31 18:09:59 +02:00
},
2021-09-16 21:08:02 +02:00
signup(authData: ISignupOptions) {
2021-08-31 18:09:59 +02:00
console.log('SIGNUP')
2021-09-16 21:08:02 +02:00
const mylang = this.lang
console.log('MYLANG: ' + mylang)
return bcrypt.hash(authData.password!, bcrypt.genSaltSync(12))
.then((hashedPassword: string) => {
authData.lang = mylang
authData.password = String(hashedPassword)
this.setServerCode(tools.CALLING)
return Api.SendReq('/users', 'POST', authData)
.then((res) => {
const newuser = res.data
// console.log('newuser', newuser)
this.setServerCode(res.status)
if (res.status === 200) {
if (process.env.DEV) {
console.log('USERNAME = ' + newuser.username)
console.log('IDUSER= ' + newuser._id)
}
this.authUser(newuser)
const now = tools.getDateNow()
// const expirationDate = new Date(now.getTime() + myres.data.expiresIn * 1000);
const expirationDate = new Date(now.getTime() * 1000)
2022-03-12 22:21:40 +01:00
tools.localStSetItem(toolsext.localStorage.lang, this.lang)
tools.localStSetItem(toolsext.localStorage.userId, newuser._id)
tools.localStSetItem(toolsext.localStorage.username, newuser.username)
tools.localStSetItem(toolsext.localStorage.name, newuser.name)
tools.localStSetItem(toolsext.localStorage.surname, newuser.surname)
localStorage.setItem(toolsext.localStorage.token, this.x_auth_token)
localStorage.setItem(toolsext.localStorage.expirationDate, expirationDate.toString())
2022-03-12 22:21:40 +01:00
tools.localStSetItem(toolsext.localStorage.verified_email, String(false))
tools.localStSetItem(toolsext.localStorage.verified_by_aportador, String(false))
2021-09-16 21:08:02 +02:00
// Even if you has registered, you have to SignIn first
this.isLogged = false
// dispatch('storeUser', authData);
// dispatch('setLogoutTimer', myres.data.expiresIn);
2021-12-29 18:26:41 +01:00
console.log('OK')
2021-09-16 21:08:02 +02:00
return { code: tools.OK, msg: '' }
} else {
2021-12-29 18:26:41 +01:00
console.log('ERR GENERICO')
2021-09-16 21:08:02 +02:00
return { code: toolsext.ERR_GENERICO, msg: '' }
}
})
.catch((error) => {
console.log('Err', error)
this.setErrorCatch(error)
return { code: this.getServerCode, msg: this.getMsg }
})
})
2021-08-31 18:09:59 +02:00
},
UpdatePwd(x_auth_token: string) {
this.x_auth_token = x_auth_token
if (!this.my.tokens) {
this.my.tokens = []
}
this.my.tokens.push({ access: 'auth', token: x_auth_token, data_login: tools.getDateNow() })
},
setServerCode(num: number) {
this.servercode = num
},
setResStatus(status: number) {
this.resStatus = status
},
setAuth(x_auth_token: string) {
this.x_auth_token = x_auth_token
},
resetArrToken(arrtokens: IToken[]) {
if (!arrtokens) {
arrtokens = []
}
// Take only the others access (from others Browser)
return arrtokens.filter((token: IToken) => token.access !== 'auth')
},
async iscrivitiConacreis(authData: ISignupIscrizioneConacreisOptions) {
console.log('iscrivitiConacreis')
this.setServerCode(tools.CALLING)
authData.userId = this.my._id
return Api.SendReq('/iscritti_conacreis', 'POST', authData)
.then((res) => {
if (res.status === 200) {
return { code: serv_constants.RIS_ISCRIZIONE_OK, msg: '' }
} else {
return { code: toolsext.ERR_GENERICO, msg: '' }
}
}).catch((error) => {
console.log('Err', error)
this.setErrorCatch(error)
return { code: this.getServerCode, msg: this.getMsg }
})
},
async iscrivitiArcadei(authData: ISignupIscrizioneArcadeiOptions) {
console.log('iscrivitiArcadei')
this.setServerCode(tools.CALLING)
authData.userId = this.my._id
return Api.SendReq('/iscritti_arcadei', 'POST', authData)
.then((res) => {
if (res.status === 200) {
return { code: serv_constants.RIS_ISCRIZIONE_OK, msg: '' }
} else {
return { code: toolsext.ERR_GENERICO, msg: '' }
}
}).catch((error) => {
console.log('Err', error)
this.setErrorCatch(error)
return { code: this.getServerCode, msg: this.getMsg }
})
},
2021-09-16 21:08:02 +02:00
async signin($router: Router, authData: ISigninOptions) {
console.log('LOGIN signin')
const globalStore = useGlobalStore()
const options = {
title: tools.translate('notification.title_subscribed', [{
strin: 'sitename',
strout: translate('ws.sitename'),
}]),
content: translate('notification.subscribed'),
openUrl: '/',
}
const usertosend = {
username: authData.username.trim(),
password: authData.password.trim(),
lang: this.lang,
options,
}
if (process.env.DEBUG === '1') {
console.log(usertosend)
}
this.setServerCode(tools.CALLING)
let myres: any
console.log('executing login...')
return await Api.SendReq('/users/login', 'POST', usertosend, true)
2021-09-16 21:08:02 +02:00
.then((res) => {
2021-09-22 01:14:30 +02:00
2021-09-16 21:08:02 +02:00
myres = res
if (myres.status !== 200) {
return Promise.reject(toolsext.ERR_GENERICO)
}
return myres
}).then((res) => {
console.log(' Login res', res)
if (res.success) {
globalStore.SetwasAlreadySubOnDb(res.data.subsExistonDb)
const myuser: IUserFields = res.data.usertosend
if (myuser) {
// console.table(myuser)
this.authUser(myuser)
this.updateLocalStorage(myuser)
// globalStore.loadSite()
2021-09-16 21:08:02 +02:00
}
}
return tools.OK
}).then((code) => {
if (code === tools.OK) {
return this.setGlobal($router, true)
.then(() => {
return code
})
} else {
return code
}
})
.catch((error) => {
2021-09-22 01:14:30 +02:00
console.log('error', error)
2021-09-16 21:08:02 +02:00
this.setErrorCatch(error)
return this.getServerCode
})
},
2021-08-31 18:09:59 +02:00
async logout() {
const globalStore = useGlobalStore()
2021-09-16 21:08:02 +02:00
// const $router = useRouter()
2021-08-31 18:09:59 +02:00
console.log('logout')
localStorage.removeItem(toolsext.localStorage.expirationDate)
localStorage.removeItem(toolsext.localStorage.token)
localStorage.removeItem(toolsext.localStorage.userId)
localStorage.removeItem(toolsext.localStorage.username)
localStorage.removeItem(toolsext.localStorage.name)
localStorage.removeItem(toolsext.localStorage.surname)
localStorage.removeItem(toolsext.localStorage.img)
localStorage.removeItem(toolsext.localStorage.perm)
localStorage.removeItem(toolsext.localStorage.isLogged)
// localStorage.removeItem(rescodes.localStorage.leftDrawerOpen)
localStorage.removeItem(toolsext.localStorage.verified_email)
2021-12-29 18:26:41 +01:00
localStorage.removeItem(toolsext.localStorage.verified_by_aportador)
2021-08-31 18:09:59 +02:00
localStorage.removeItem(toolsext.localStorage.teleg_id)
localStorage.removeItem(toolsext.localStorage.made_gift)
localStorage.removeItem(toolsext.localStorage.categorySel)
localStorage.removeItem(toolsext.localStorage.wasAlreadySubOnDb)
this.isLogged = false
this.my = { ...DefaultUser }
await globalStore.clearDataAfterLogout()
2022-12-20 10:58:55 +01:00
tools.checkApp()
2021-09-16 21:08:02 +02:00
return Api.SendReq('/users/me/token', 'DELETE', null)
2021-08-31 18:09:59 +02:00
.then((res) => {
console.log(res)
}).then(() => this.clearAuthData()).catch((error) => {
this.setErrorCatch(error)
return this.getServerCode
})
},
2021-09-16 21:08:02 +02:00
async setGlobal($router: Router, isLogged: boolean) {
console.log('setGlobal', isLogged)
2021-08-31 18:09:59 +02:00
const globalStore = useGlobalStore()
2021-09-16 21:08:02 +02:00
const todos = useTodoStore()
const projects = useProjectStore()
2021-08-31 18:09:59 +02:00
try {
// this.isLogged = true
if (isLogged) {
// console.log('this.isLogged', this.isLogged)
2022-11-23 10:27:36 +01:00
if (!tools.isMobile)
globalStore.setleftDrawerOpen(localStorage.getItem(toolsext.localStorage.leftDrawerOpen) === 'true')
2021-08-31 18:09:59 +02:00
globalStore.setCategorySel(localStorage.getItem(toolsext.localStorage.categorySel))
globalStore.checkUpdates()
}
const isok = await globalStore.loadAfterLogin()
this.isLogged = isok && isLogged
// console.log('this.isLogged', this.isLogged, 'isok', isok, 'isLogged', isLogged)
if (globalStore.site.confpages.enableTodos)
2021-09-16 21:08:02 +02:00
await todos.dbLoad({ checkPending: true })
2021-08-31 18:09:59 +02:00
if (globalStore.site.confpages.enableProj)
2021-09-16 21:08:02 +02:00
await projects.dbLoad({ checkPending: true, onlyiffirsttime: true })
2021-08-31 18:09:59 +02:00
2021-09-16 21:08:02 +02:00
globalStore.addDynamicPages($router)
2021-08-31 18:09:59 +02:00
static_data.lang_available = globalStore.getLangAvailable()
static_data.arrLangUsed = tools.getLangUsed()
// console.log('$router', $router)
2021-08-31 18:09:59 +02:00
globalStore.finishLoading = true
if (tools.isDebug()) console.log('finishLoading', globalStore.finishLoading)
// document.dispatchEvent(new Event('custom-post-render-event'))
} catch (e) {
console.error('Error', e)
globalStore.finishLoading = true
}
return true
// console.log('setGlobal: END')
},
async autologin_FromLocalStorage($router: Router, $q: any) {
2021-08-31 18:09:59 +02:00
try {
const globalStore = useGlobalStore()
// console.log('*** autologin_FromLocalStorage ***')
2021-08-31 18:09:59 +02:00
// INIT
let isLogged = false
this.lang = tools.getItemLS(toolsext.localStorage.lang)
const token = localStorage.getItem(toolsext.localStorage.token)
2021-08-31 18:09:59 +02:00
if (token) {
const expirationDateStr = localStorage.getItem(toolsext.localStorage.expirationDate)
const expirationDate = new Date(String(expirationDateStr))
const now = tools.getDateNow()
if (now < expirationDate) {
this.setAuth(token)
isLogged = true
} else {
// ++ ?? che fare qui
}
} else {
isLogged = tools.isLogged()
}
2021-09-16 21:08:02 +02:00
return await this.setGlobal($router, isLogged)
.then((loadstorage: any) => {
// console.log('RISULT setGlobal:', loadstorage)
if (loadstorage) {
globalroutines('loadapp', '')
// Create Subscription to Push Notification
globalStore.createPushSubscription()
}
})
2021-08-31 18:09:59 +02:00
2021-09-02 03:22:13 +02:00
} catch (e: any) {
2021-08-31 18:09:59 +02:00
console.error('ERR autologin ', e.message)
return false
}
},
2022-01-03 21:53:41 +01:00
async loadUserProfile({ username, idnotif }: { username: string, idnotif?: string }) {
2022-01-03 21:53:41 +01:00
const data = {
2022-07-21 00:20:48 +02:00
username,
idnotif
2022-01-03 21:53:41 +01:00
}
2023-01-08 02:17:15 +01:00
return await Api.SendReq('/users/profile', 'POST', data)
.then((ris) => {
2023-01-08 02:17:15 +01:00
if (this.my.username === ris.data.user.username) {
// this.updateDataFr(ris.data.friends)
}
return ris.data.user
2022-01-03 21:53:41 +01:00
}).catch((error) => {
return {}
2022-01-26 01:31:07 +01:00
})
},
2022-07-21 00:20:48 +02:00
async setUserNotifs(notifs: IUserNotifType[]) {
const data = {
notifs
}
return Api.SendReq('/users/notifs', 'POST', data)
.then((ris) => {
return ris.data
}).catch((error) => {
return {}
})
},
2022-07-10 01:24:54 +02:00
async loadUserPanel(username: string) {
const data = {
username
}
return Api.SendReq('/users/panel', 'POST', data)
.then((ris) => {
console.log('out:', ris)
return ris.data
}).catch((error) => {
return {}
})
},
2022-07-28 23:27:28 +02:00
async loadGroup(groupname: string, idnotif: string) {
2022-02-03 00:33:05 +01:00
const data = {
2022-07-28 23:27:28 +02:00
groupname,
idnotif,
2022-02-03 00:33:05 +01:00
}
return Api.SendReq('/mygroup/load', 'POST', data)
.then((res) => {
return { data: res.data, status: res.status }
2022-02-03 00:33:05 +01:00
}).catch((error) => {
return { data: null, status: error.status }
2022-02-03 00:33:05 +01:00
})
},
async loadCircuit(path: string, idnotif: string) {
const notifStore = useNotifStore()
2022-08-26 03:32:50 +02:00
const data = {
2022-08-30 17:00:32 +02:00
path,
2022-08-26 03:32:50 +02:00
idnotif,
lastdr: notifStore.getLastDataRead(this.my.username),
2022-08-26 03:32:50 +02:00
}
return Api.SendReq('/circuit/load', 'POST', data)
.then((res) => {
if (res && res.data.arrrecnotif) {
notifStore.updateArrRecNotifFromServer(res.data.arrrecnotif)
}
if (res.data.useraccounts && res.data.useraccounts.length > 0) {
this.my.profile.useraccounts = res.data.useraccounts
}
return { data: res.data, status: res.status }
2022-08-26 03:32:50 +02:00
}).catch((error) => {
return { data: null, status: error.status }
2022-08-26 03:32:50 +02:00
})
},
2022-01-26 01:31:07 +01:00
async loadSkill(idSkill: string) {
const data = {
idSkill
}
return Api.SendReq('/myskills/page', 'POST', data)
.then((res) => {
return res.data
}).catch((error) => {
return {}
2022-01-03 21:53:41 +01:00
})
2022-01-05 19:11:47 +01:00
},
async loadGeneric(table: string, id: number, idnotif: string) {
const data = {
table,
id,
idnotif
}
return Api.SendReq('/mygen/page', 'POST', data)
.then((res) => {
return res.data
}).catch((error) => {
return {}
})
},
2023-01-08 02:17:15 +01:00
updateDataFr(data: any) {
console.log('updateDataFr', data)
this.my.profile.friends = data.listFriends ? data.listFriends : []
this.my.profile.req_friends = data.listRequestFriends ? data.listRequestFriends : []
this.my.profile.asked_friends = data.listSentRequestFriends ? data.listSentRequestFriends : []
this.my.profile.handshake = data.listHandShake ? data.listHandShake : []
},
async loadFriends() {
2022-01-05 19:11:47 +01:00
return Api.SendReq('/users/friends', 'POST', null)
.then((ris) => {
2023-01-08 02:17:15 +01:00
this.updateDataFr(ris.data)
return ris.data
2022-01-05 19:11:47 +01:00
}).catch((error) => {
return {}
})
},
2022-02-03 00:33:05 +01:00
async loadGroups(username: string) {
return Api.SendReq('/users/groups', 'POST', null)
.then((res) => {
return res.data
}).catch((error) => {
return {}
})
},
2022-08-26 03:32:50 +02:00
async loadCircuits() {
return Api.SendReq('/users/circuits', 'POST', null)
.then((res) => {
return res.data
}).catch((error) => {
return {}
})
},
async loadAllAccounts() {
return Api.SendReq('/account/loadall', 'POST', null)
.then((res) => {
return res.data
}).catch((error) => {
return {}
})
},
async setFriendsCmd($q: any, t: any, usernameOrig: string, usernameDest: string, cmd: number, value: any) {
return Api.SendReq('/users/friends/cmd', 'POST', { usernameOrig, usernameDest, cmd, value })
.then((res) => {
this.updateTables = true
2022-01-12 00:38:31 +01:00
return res.data
}).catch((error) => {
tools.showNegativeNotif($q, t('db.recfailed'))
return {}
})
},
2022-02-03 00:33:05 +01:00
async setGroupsCmd($q: any, t: any, usernameOrig: string, groupnameDest: string, cmd: number, value: any) {
return Api.SendReq('/users/groups/cmd', 'POST', { usernameOrig, groupnameDest, cmd, value })
.then((res) => {
this.updateTables = true
2022-02-03 00:33:05 +01:00
return res.data
}).catch((error) => {
tools.showNegativeNotif($q, t('db.recfailed'))
return {}
})
},
2022-09-03 13:06:35 +02:00
async setCircuitCmd($q: any, t: any, usernameOrig: string, circuitname: string, cmd: number, value: any, extrarec?: any) {
2022-09-13 12:28:33 +02:00
return await Api.SendReq('/users/circuits/cmd', 'POST', { usernameOrig, circuitname, cmd, value, extrarec })
2022-08-30 17:00:32 +02:00
.then((res) => {
this.updateTables = true
2022-09-13 12:28:33 +02:00
if (res.data.recnotif) {
const notifStore = useNotifStore()
notifStore.updateRecNotif(res.data.recnotif)
notifStore.updateArrRecNotifFromServer(res.data.arrrecnotif)
2022-09-13 12:28:33 +02:00
}
2022-08-30 17:00:32 +02:00
return res.data
}).catch((error) => {
tools.showNegativeNotif($q, t('db.recfailed'))
return {}
})
},
async sendMsgToBotTelegram($q: any, t: any, mydata: IMsgGlobParam, showmsgsent: boolean) {
2022-12-09 03:09:16 +01:00
const globalStore = useGlobalStore()
return Api.SendReq('/users/mgt', 'POST', { mydata })
.then((res) => {
console.log('res', res)
2022-12-09 03:09:16 +01:00
let msgok = (res.data.nummsgsent === 1) ? res.data.nummsgsent + ' ' + t('cal.sendmsg_sent') : res.data.nummsgsent + ' ' + t('cal.sendmsgs_sent')
if (mydata.cmd === shared_consts.MsgTeleg.SHARE_MSGREG) {
2022-12-09 03:09:16 +01:00
if (tools.isTelegOk()) {
msgok = t('cal.sendmsg_sent_sharedlink') + ' ' + tools.getBotName()
} else {
msgok = t('cal.sendmsg_sent_sharedlink_copied')
}
showmsgsent = true
}
if (showmsgsent && res.data.nummsgsent >= 0) {
tools.showPositiveNotif($q, msgok)
if (mydata.cmd === shared_consts.MsgTeleg.SHARE_MSGREG) {
2022-12-09 03:09:16 +01:00
if (!tools.isTelegOk()) {
2022-12-11 02:57:45 +01:00
// console.log('text', res.data.text)
2022-12-09 03:09:16 +01:00
tools.copyStringToClipboardSilent(res.data.text)
}
if (res.data.textsent) {
return res.data.textsent
}
}
return true
}
return false
}).catch((error) => {
tools.showNegativeNotif($q, t('cal.err_sendmsg'))
return {}
})
},
async importToServerCmd($q: any, t: any, cmd: number, data: any) {
return Api.SendReq('/admin/import', 'POST', { cmd, data })
.then((res) => {
if (res) {
tools.showPositiveNotif($q, t('db.recupdated'))
}
}).catch((error) => {
tools.showNegativeNotif($q, t('db.recfailed'))
return {}
})
2022-01-03 21:53:41 +01:00
}
2021-08-31 18:09:59 +02:00
},
})