Fix signup cycle (signup, confirm, login)

This commit is contained in:
aldrin 2021-04-16 11:08:28 +02:00
parent 6e4c2ddabd
commit fbb4e4502e
3 changed files with 20 additions and 17 deletions

View file

@ -30,11 +30,12 @@ async function request(
init.headers.set("Accept", "application/json"); init.headers.set("Accept", "application/json");
init.headers.set("Content-Type", "application/json"); init.headers.set("Content-Type", "application/json");
const response = await fetch(`/api/${endpoint}/`, init); const response = await fetch(`/api/${endpoint}/`, init);
const dataOrErrors = await response.json(); if (response.status !== 204) {
if (response.status === successStatus) { if (response.status === successStatus) {
return dataOrErrors; return await response.json();
} else { } else {
throw new APIError(response.statusText, dataOrErrors); throw new APIError(response.statusText, await response.json());
}
} }
} }

View file

@ -52,6 +52,12 @@ export default class LoginForm extends Vue {
await this.user.login(); await this.user.login();
} else { } else {
await this.user.signup(); await this.user.signup();
this.$router.push({ name: "login" });
this.$buefy.toast.open({
message:
"Eine E-Mail zur Bestätigung deiner E-Mail-Adresse wurde versendet.",
type: "is-success",
});
} }
// TODO: error handling, show confirmation page // TODO: error handling, show confirmation page
} }

View file

@ -8,15 +8,7 @@
<UserTable :user="user" /> <UserTable :user="user" />
</div> </div>
<div v-else class="column is-3-widescreen is-4-desktop is-5-tablet"> <div v-else class="column is-3-widescreen is-4-desktop is-5-tablet">
<b-notification <LoginForm :user="user" />
v-if="isConfirmation"
type="is-success"
aria-close-label="Close notification"
>
Deine E-Mail-Adresse wurde erfolgreich bestätigt. Du kannst dich nun
anmelden.
</b-notification>
<LoginForm v-else :user="user" />
</div> </div>
</div> </div>
</section> </section>
@ -30,13 +22,17 @@ import UserTable from "@/components/UserTable.vue";
@Component({ components: { UserTable, LoginForm } }) @Component({ components: { UserTable, LoginForm } })
export default class Home extends Vue { export default class Home extends Vue {
private isConfirmation = false;
private user = new User(); private user = new User();
public async created(): Promise<void> { public async created(): Promise<void> {
if (this.$route.name === "confirm") this.isConfirmation = true; if (this.$route.name === "confirm") {
if (this.isConfirmation) {
await User.confirm(this.$route.params.uid, this.$route.params.token); await User.confirm(this.$route.params.uid, this.$route.params.token);
this.$router.push({ name: "login" });
this.$buefy.toast.open({
message:
"Deine E-Mail-Adresse wurde bestätigt. Du kannst dich nun anmelden.",
type: "is-success",
});
} }
} }
} }