Skip to content

Commit

Permalink
feat: c2corg#3713 show ToS checkbox if ToS error on login
Browse files Browse the repository at this point in the history
  • Loading branch information
florentcadot committed Feb 25, 2024
1 parent fbe8b6b commit 498a758
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/js/apis/c2c/UserProfileService.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ function UserProfileService(api) {
};
}

UserProfileService.prototype.login = function (username, password) {
UserProfileService.prototype.login = function (username, password, acceptTos) {
return this.api.post('/users/login', {
username,
password,
discourse: true,
accept_tos: acceptTos,
});
};

Expand Down
4 changes: 2 additions & 2 deletions src/js/vue-plugins/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export default function install(Vue) {
},

methods: {
signIn(username, password) {
return c2c.userProfile.login(username, password).then((response) => {
signIn(username, password, acceptTos) {
return c2c.userProfile.login(username, password, acceptTos).then((response) => {
this.lang = response.data.lang;
this.token = response.data.token;
this.roles = response.data.roles;
Expand Down
36 changes: 32 additions & 4 deletions src/views/user/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
icon="key"
/>

<div class="field" v-if="showLoginTerms">
<div class="control">
<label class="checkbox">
<input type="checkbox" v-model="loginTermsAgreed" />
<span class="has-text-weight-bold" v-translate>I have read and agree to the terms of service</span>
(<router-link :to="termsRoute" v-translate>link</router-link>).
</label>
</div>
</div>

<div class="has-text-weight-bold is-centered has-text-centered mb-1" v-translate>
Beware of case-sensitive login and password
</div>
Expand Down Expand Up @@ -74,8 +84,8 @@
<label class="checkbox">
<input type="checkbox" v-model="termsAgreed" />
&nbsp;
<span class="has-text-weight-bold" v-translate>I have read and agree to the terms of use</span>
(<router-link :to="{ name: 'article', params: { id: 106731 } }" v-translate>link</router-link>).
<span class="has-text-weight-bold" v-translate>I have read and agree to the terms of service</span>
(<router-link :to="termsRoute" v-translate>link</router-link>).
</label>
</div>
</div>
Expand Down Expand Up @@ -225,10 +235,16 @@ export default {
redirectionStillDone: false,
promise: {},
loginTermsAgreed: undefined,
termsRoute: { name: 'article', params: { id: 106731 } },
};
},
computed: {},
computed: {
showLoginTerms() {
return this.loginTermsAgreed !== undefined;
},
},
watch: {
$route: 'load',
Expand Down Expand Up @@ -313,8 +329,20 @@ export default {
}
},
isTermsError(e) {
const { status } = e.response;
const { errors } = e.response.data;
const messageErrors = errors.map((e) => e.description);
return status === 403 && messageErrors.includes('Terms of Service need to be accepted');
},
signin() {
this.promise = this.$user.signIn(this.username, this.password).then(this.onSuccessSigin);
this.promise = this.$user
.signIn(this.username, this.password, this.loginTermsAgreed)
.then(this.onSuccessSigin)
.catch((e) => {
this.loginTermsAgreed = this.isTermsError(e) ? false : undefined;
});
},
onSuccessSigin(data) {
Expand Down

0 comments on commit 498a758

Please sign in to comment.