feat: Allow to activate trusted accounts only

This commit is contained in:
aldrin 2021-08-03 11:41:58 +02:00
parent 0f1cd98a80
commit d656370aef
5 changed files with 40 additions and 44 deletions

View file

@ -12,7 +12,7 @@ async function api_request(
method: HTTPMethod,
endpoint: string,
successStatus: number,
data: any,
data?: any,
authToken?: string
) {
const init = {
@ -40,13 +40,15 @@ async function api_request(
}
export class User {
email: string | undefined;
pk: number | undefined;
password: string | undefined;
username: string | null = null;
isAuthenticated = false;
isTrusted = false;
private token = "";
/**
* Activate the corresponding LDAP account.
*/
async activate(): Promise<void> {
await api_request("POST", "users/activate", 204, {
password: this.password,
@ -74,21 +76,16 @@ export class User {
// successful logins are followed by a redirect
if (res.redirected && res.status === 200) {
this.isAuthenticated = true;
await this.retrieve();
} else {
throw new APIError("", "");
}
}
async save(): Promise<void> {
await api_request(
"PATCH",
"users/me",
200,
{
username: this.username,
},
this.token
);
async retrieve(): Promise<void> {
const data = await api_request("GET", "users/me", 200);
this.pk = data.pk;
this.isTrusted = data.trust_bridge.is_trusted;
}
async signup(): Promise<void> {

View file

@ -2,7 +2,7 @@
<div>
<b-notification type="is-info" aria-close-label="Close notification">
Dein Konto ist noch nicht aktiv.
<a @click="activate()">Jetzt aktivieren</a>
<a v-if="user.isTrusted" @click="activate()">Jetzt aktivieren</a>
</b-notification>
<table class="table is-fullwidth">
<tbody>

View file

@ -27,23 +27,9 @@ export default class Home extends mixins(NotifyMixin) {
private user = new User();
public async created(): Promise<void> {
if (this.$route.name === "confirm") {
await this.doConfirm();
} else if (!this.user.isAuthenticated && this.$route.name !== "login") {
if (!this.user.isAuthenticated && this.$route.name !== "login") {
this.$router.push({ name: "login" });
}
}
private async doConfirm() {
try {
await User.confirm(this.$route.params.uid, this.$route.params.token);
this.$router.push({ name: "login" });
this.showSuccess(
"Deine E-Mail-Adresse wurde bestätigt. Du kannst dich nun anmelden."
);
} catch {
this.showError();
}
}
}
</script>