diff --git a/src/js/apis/c2c/UserProfileService.js b/src/js/apis/c2c/UserProfileService.js index 5b5ab4e246..b32f50cd49 100644 --- a/src/js/apis/c2c/UserProfileService.js +++ b/src/js/apis/c2c/UserProfileService.js @@ -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, }); }; diff --git a/src/js/vue-plugins/user.js b/src/js/vue-plugins/user.js index f3e6d6f1fb..4f1ab8e9fd 100644 --- a/src/js/vue-plugins/user.js +++ b/src/js/vue-plugins/user.js @@ -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; diff --git a/src/views/user/LoginView.vue b/src/views/user/LoginView.vue index cc106fcf1a..80fc378740 100644 --- a/src/views/user/LoginView.vue +++ b/src/views/user/LoginView.vue @@ -23,6 +23,18 @@ icon="key" /> +
+
+ +
+
+
Beware of case-sensitive login and password
@@ -74,8 +86,8 @@ @@ -225,10 +237,16 @@ export default { redirectionStillDone: false, promise: {}, + loginTermsAgreed: undefined, + termsRoute: { name: 'article', params: { id: 106731 } }, }; }, - computed: {}, + computed: { + showLoginTerms() { + return this.loginTermsAgreed !== undefined; + }, + }, watch: { $route: 'load', @@ -313,8 +331,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) {