forked from abner/for-legacy-web
merge: pull request #1108 from Zomatree/feat/reset-bot-password
commit
9e293e0a30
|
|
@ -1 +1 @@
|
|||
Subproject commit e54133252e834299a23e759b7cda2cf2b2447279
|
||||
Subproject commit bb4bfcfd5a22dfc84a1a9f797a43af6804d96b93
|
||||
|
|
@ -297,4 +297,5 @@ export const modalController = new ModalControllerExtended({
|
|||
report_success: ReportSuccess,
|
||||
modify_displayname: ModifyDisplayname,
|
||||
changelog_usernames: ChangelogUsernames,
|
||||
reset_bot_token: Confirmation
|
||||
});
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ export default function Confirmation(
|
|||
| "delete_bot"
|
||||
| "block_user"
|
||||
| "unfriend_user"
|
||||
| "reset_bot_token"
|
||||
>,
|
||||
) {
|
||||
const history = useHistory();
|
||||
|
|
@ -31,6 +32,7 @@ export default function Confirmation(
|
|||
delete_bot: ["confirm_delete", "delete"],
|
||||
unfriend_user: ["unfriend_user", "remove"],
|
||||
block_user: ["block_user", "block"],
|
||||
reset_bot_token: ["reset_bot_token", "reset"],
|
||||
};
|
||||
|
||||
const event = EVENTS[props.type];
|
||||
|
|
@ -88,6 +90,12 @@ export default function Confirmation(
|
|||
.bots.delete(props.target);
|
||||
props.cb?.();
|
||||
break;
|
||||
case "reset_bot_token":
|
||||
clientController
|
||||
.getAvailableClient()
|
||||
.bots
|
||||
.edit(props.target.id, { remove: ["Token"] })
|
||||
.then(props.callback)
|
||||
}
|
||||
}}
|
||||
submit={{
|
||||
|
|
|
|||
|
|
@ -190,6 +190,11 @@ export type Modal = {
|
|||
type: "report_success";
|
||||
user?: User;
|
||||
}
|
||||
| {
|
||||
type: "reset_bot_token";
|
||||
target: { name: string, id: string },
|
||||
callback: () => Promise<void>;
|
||||
}
|
||||
);
|
||||
|
||||
export type ModalProps<T extends Modal["type"]> = Modal & { type: T } & {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import { modalController } from "../../../controllers/modals/ModalController";
|
|||
|
||||
interface Data {
|
||||
_id: string;
|
||||
token: string;
|
||||
username: string;
|
||||
public: boolean;
|
||||
interactions_url?: string;
|
||||
|
|
@ -74,6 +75,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
|||
const [user, setUser] = useState<User>(client.users.get(bot._id)!);
|
||||
const [data, setData] = useState<Data>({
|
||||
_id: bot._id,
|
||||
token: bot.token,
|
||||
username: user.username,
|
||||
public: bot.public,
|
||||
interactions_url: bot.interactions_url as any,
|
||||
|
|
@ -94,7 +96,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
|||
const refreshProfile = useCallback(() => {
|
||||
client.api
|
||||
.get(`/users/${bot._id as ""}/profile`, undefined, {
|
||||
headers: { "x-bot-token": bot.token },
|
||||
headers: { "x-bot-token": data.token },
|
||||
})
|
||||
.then((profile) => setProfile(profile ?? {}));
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
|
|
@ -149,7 +151,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
|||
"/users/@me",
|
||||
avatar ? { avatar } : { remove: ["Avatar"] },
|
||||
{
|
||||
headers: { "x-bot-token": bot.token },
|
||||
headers: { "x-bot-token": data.token },
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -168,7 +170,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
|||
? { profile: { background } }
|
||||
: { remove: ["ProfileBackground"] },
|
||||
{
|
||||
headers: { "x-bot-token": bot.token },
|
||||
headers: { "x-bot-token": data.token },
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -184,7 +186,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
|||
"/users/@me",
|
||||
content ? { profile: { content } } : { remove: ["ProfileContent"] },
|
||||
{
|
||||
headers: { "x-bot-token": bot.token },
|
||||
headers: { "x-bot-token": data.token },
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -312,6 +314,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
|||
if (editMode) {
|
||||
setData({
|
||||
_id: bot._id,
|
||||
token: data.token,
|
||||
username: user!.username,
|
||||
public: bot.public,
|
||||
interactions_url: bot.interactions_url as any,
|
||||
|
|
@ -334,7 +337,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
|||
<CategoryButton
|
||||
account
|
||||
icon={<Key size={24} />}
|
||||
onClick={() => modalController.writeText(bot.token)}
|
||||
onClick={() => modalController.writeText(data.token)}
|
||||
description={
|
||||
<>
|
||||
{"••••• "}
|
||||
|
|
@ -344,7 +347,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
|||
ev,
|
||||
modalController.push({
|
||||
type: "show_token",
|
||||
token: bot.token,
|
||||
token: data.token,
|
||||
name: user!.username,
|
||||
}),
|
||||
)
|
||||
|
|
@ -490,6 +493,25 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
|||
}>
|
||||
<Text id="app.settings.pages.bots.add" />
|
||||
</Button>
|
||||
<Button
|
||||
palette="error"
|
||||
onClick={ async () => {
|
||||
modalController.push({
|
||||
type: "reset_bot_token",
|
||||
target: { name: user.username, id: bot._id },
|
||||
callback: async () => {
|
||||
const updatedBot = await client.bots.fetch(bot._id);
|
||||
setData({
|
||||
...data,
|
||||
token: updatedBot.bot.token
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}>
|
||||
<Text id="app.settings.pages.bots.reset_token" />
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue