mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
Merge branch 'main' of https://github.com/balzack/databag
This commit is contained in:
commit
3bfb367fa3
7
app/mobile/src/api/removeProfile.js
Normal file
7
app/mobile/src/api/removeProfile.js
Normal file
@ -0,0 +1,7 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function removeProfile(server, token) {
|
||||
let profile = await fetchWithTimeout(`https://${server}/profile?agent=${token}`, { method: 'DELETE' });
|
||||
checkResponse(profile)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { useEffect, useState, useRef, useContext } from 'react';
|
||||
import { getAvailable } from 'api/getAvailable';
|
||||
import { setLogin } from 'api/setLogin';
|
||||
import { removeProfile } from 'api/removeProfile';
|
||||
import { setAccountAccess } from 'api/setAccountAccess';
|
||||
import { addAccount } from 'api/addAccount';
|
||||
import { getUsername } from 'api/getUsername';
|
||||
@ -48,7 +49,8 @@ export function useAppContext() {
|
||||
await profile.actions.setSession(access);
|
||||
await card.actions.setSession(access);
|
||||
await channel.actions.setSession(access);
|
||||
updateState({ session: true, loginTimestamp: access.created });
|
||||
updateState({ session: true, server: access.server, appToken: access.appToken,
|
||||
loginTimestamp: access.created });
|
||||
setWebsocket(access.server, access.appToken);
|
||||
}
|
||||
|
||||
@ -85,6 +87,11 @@ export function useAppContext() {
|
||||
await clearSession();
|
||||
await store.actions.clearSession();
|
||||
},
|
||||
remove: async () => {
|
||||
await removeProfile(state.server, state.appToken);
|
||||
await clearSession();
|
||||
await store.actions.clearSession();
|
||||
},
|
||||
}
|
||||
|
||||
const setWebsocket = (server, token) => {
|
||||
|
@ -14,9 +14,6 @@ export function Dashboard(props) {
|
||||
const { config, server, token } = location.state;
|
||||
const { state, actions } = useDashboard(config, server, token);
|
||||
|
||||
console.log(state.createToken);
|
||||
console.log(state.accessToken);
|
||||
|
||||
const saveConfig = async () => {
|
||||
try {
|
||||
await actions.saveConfig();
|
||||
|
@ -65,6 +65,21 @@ export function Profile() {
|
||||
}
|
||||
}
|
||||
|
||||
const remove = async () => {
|
||||
Alert.alert(
|
||||
"Deleting Account",
|
||||
"Confirm?",
|
||||
[
|
||||
{ text: "Cancel",
|
||||
onPress: () => {},
|
||||
},
|
||||
{ text: "Delete", onPress: () => {
|
||||
actions.remove();
|
||||
}}
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
const logout = async () => {
|
||||
Alert.alert(
|
||||
"Logging Out",
|
||||
@ -172,6 +187,10 @@ export function Profile() {
|
||||
<Ionicons name="logout" size={14} color={Colors.white} />
|
||||
<Text style={styles.logoutText}>Logout</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity style={styles.delete} onPress={remove}>
|
||||
<Ionicons name="delete" size={14} color={Colors.white} />
|
||||
<Text style={styles.deleteText}>Delete</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
@ -136,6 +136,22 @@ export const styles = StyleSheet.create({
|
||||
color: Colors.white,
|
||||
paddingLeft: 8,
|
||||
},
|
||||
delete: {
|
||||
marginTop: 32,
|
||||
borderRadius: 4,
|
||||
backgroundColor: Colors.error,
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
paddingLeft: 8,
|
||||
paddingRight: 8,
|
||||
paddingTop: 8,
|
||||
paddingBottom: 8,
|
||||
},
|
||||
deleteText: {
|
||||
color: Colors.white,
|
||||
paddingLeft: 8,
|
||||
},
|
||||
switch: {
|
||||
false: Colors.grey,
|
||||
true: Colors.background,
|
||||
|
@ -76,6 +76,10 @@ export function useProfile() {
|
||||
app.actions.logout();
|
||||
navigate('/');
|
||||
},
|
||||
remove: async () => {
|
||||
await app.actions.remove();
|
||||
navigate('/');
|
||||
},
|
||||
setVisible: async (searchable) => {
|
||||
updateState({ searchable });
|
||||
await account.actions.setSearchable(searchable);
|
||||
|
89
net/server/internal/api_removeProfile.go
Normal file
89
net/server/internal/api_removeProfile.go
Normal file
@ -0,0 +1,89 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
"databag/internal/store"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
//RemoveProfile removes account
|
||||
func RemoveProfile(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
account, code, err := ParamAgentToken(r, true)
|
||||
if err != nil {
|
||||
PrintMsg(r)
|
||||
ErrResponse(w, code, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Tag{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.TagSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Asset{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Topic{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.TopicSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.ChannelSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Channel{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Article{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.ArticleSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.CardSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Card{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Group{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.GroupData{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Group{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.App{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.AccountToken{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Delete(&store.AccountDetail{}, account.AccountDetailID).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Delete(account).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
// delete asset files
|
||||
path := getStrConfigValue(CNFAssetPath, APPDefaultPath) + "/" + account.GUID
|
||||
if err = os.RemoveAll(path); err != nil {
|
||||
ErrMsg(err)
|
||||
}
|
||||
|
||||
WriteResponse(w, nil)
|
||||
}
|
@ -734,6 +734,13 @@ var endpoints = routes{
|
||||
SetProfileImage,
|
||||
},
|
||||
|
||||
route{
|
||||
"RemoveProfile",
|
||||
strings.ToUpper("Delete"),
|
||||
"/profile",
|
||||
RemoveProfile,
|
||||
},
|
||||
|
||||
route{
|
||||
"Status",
|
||||
strings.ToUpper("Get"),
|
||||
|
Loading…
Reference in New Issue
Block a user