Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ module.exports = {
accounting: true,
axios: true,
moment: true,
window: true
window: true,
kanvasSDK: true
}
}
1 change: 1 addition & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "@/config/cookies";
import "@/config/vee-validate";
import "@/config/sentry";
import "@/config/element-ui";
import "@/config/kanvasSDK";
import * as filters from "@/utils/filters";
import methods from "@/utils/methods";

Expand Down
22 changes: 22 additions & 0 deletions src/config/kanvasSDK.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import KanvasSDK from "client-sdk";
import store from "@/store";

const kanvasSDK = new KanvasSDK({
appKey: process.env.VUE_APPKEY,
endpoint: process.env.VUE_APP_BASE_API_URL,
domain: process.env.VUE_APP_DOMAIN,
cookies: true
})

kanvasSDK.auth.on("loggedIn", (token) => {
store.dispatch("User/setToken", token);
})

kanvasSDK.auth.on("loggedOut", () => {
store.dispatch("User/setToken", null);
})

window.kanvasSDK = kanvasSDK;

export default kanvasSDK;

40 changes: 26 additions & 14 deletions src/mixins/auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AuthContainer from "@v/auth/container";
import { mapState } from "vuex";

export default {
components: {
Expand All @@ -12,6 +13,11 @@ export default {
}
}
},
data() {
return {
isLoading: false
}
},
computed: {
allowUserRegistration() {
return this.appSettings.settings && Boolean(Number(this.appSettings.settings.allow_user_registration));
Expand All @@ -33,11 +39,13 @@ export default {
}
},
methods: {
handleResponse({ data }, isSignup = false) {
const auth = isSignup ? data.session : data;

Cookies.set("token", auth.token, { expires: new Date(auth.expires), path: "/", domain: process.env.VUE_APP_DOMAIN });
this.$store.dispatch("User/setToken", auth.token);
handleResponse(responseData, isSignup = false) {
if (responseData) {
// support old modules
const auth = isSignup ? responseData.session : responseData.data;
Cookies.set("token", auth.token, { expires: new Date(auth.expires), path: "/", domain: process.env.VUE_APP_DOMAIN });
this.$store.dispatch("User/setToken", auth.token);
}

if (isSignup) {
this.$modal.show("after-signup-wizard");
Expand All @@ -47,33 +55,37 @@ export default {
this.$router.replace({ name: "dashboard" });
this.$store.dispatch("Application/setIsLoading", false);
},
prepareData() {
const data = new FormData();
prepareData(asObject) {
const data = {};

Object.keys(this.form.fields).forEach((field) => {
const apiField = this.form.fields[field].map || field;

data.append(apiField, this.form.fields[field].value);
data[apiField] = this.form.fields[field].value;
});

if (!asObject) {
const formData = new FormData();
Object.entries(data).forEach(([key, value]) => {
formData.append(key, value)
})
}
return data;
},
submitData(isSignup) {
async submitData(isSignup) {
const data = this.prepareData();

axios({
url: `${this.form.endpoint}`,
method: "POST",
data
}).then((response) => {
this.handleResponse(response, isSignup);
}).then(({ data }) => {
this.handleResponse(data, isSignup);
}).catch((error) => {
this.$notify({
title: "Error",
text: error.response.data.errors.message,
type: "error"
});
});
})
},
validateInvitation() {
axios({
Expand Down
24 changes: 22 additions & 2 deletions src/views/auth/forgot-password.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ export default {
}
},
methods: {
handleResponse(response) {
handleResponse(data) {
this.$notify({
title: "Confirmation",
text: response.data,
text: data,
type: "success"
});

Expand All @@ -74,6 +74,26 @@ export default {
this.$router.push({
name: "login"
});
},

submitData() {
if (!this.isLoading) {
this.isLoading = true;
const data = this.prepareData(true);
kanvasSDK.auth.sendPasswordResetEmail(data.email)
.then((responseData) => {
this.handleResponse(responseData)
})
.catch(error => {
this.$notify({
title: "Error",
text: error.errors.message,
type: "error"
});
}).finally(() => {
this.isLoading = false;
})
}
}
}
}
Expand Down
24 changes: 23 additions & 1 deletion src/views/auth/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
</div>
<span class="text-danger">{{ errors.first("password") }}</span>

<button class="btn btn-primary btn-block my-4" type="submit">
<button class="btn btn-primary btn-block my-4" type="submit" :disabled="isLoading">
Sign In
<i v-if="isLoading" class="fa fa-circle-notch fa-spin" />
</button>
<social-auth :app-settings="appSettings" />
<div v-if="allowUserRegistration" class="text-center small">
Expand Down Expand Up @@ -89,6 +90,27 @@ export default {
endpoint: "/auth"
}
}
},
methods: {
submitData() {
if (!this.isLoading) {
this.isLoading = true;
const data = this.prepareData(true);
kanvasSDK.auth.login(data.email, data.password)
.then(() => {
this.handleResponse()
})
.catch(error => {
this.$notify({
title: "Error",
text: error.errors.message,
type: "error"
});
}).finally(() => {
this.isLoading = false;
})
}
}
}
}
</script>
24 changes: 22 additions & 2 deletions src/views/auth/reset-password.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,36 @@ export default {
}
},
methods: {
handleResponse(response) {
handleResponse(data) {
this.$notify({
title: "Confirmation",
text: response.data,
text: data,
type: "success"
});

this.$router.push({
name: "login"
});
},

submitData() {
if (!this.isLoading) {
this.isLoading = true;
const data = this.prepareData(true);
kanvasSDK.auth.resetPassword(data.new_password, data.verify_password,this.$route.params.resetKey)
.then((responseData) => {
this.handleResponse(responseData)
})
.catch(error => {
this.$notify({
title: "Error",
text: error.errors.message,
type: "error"
});
}).finally(() => {
this.isLoading = false;
})
}
}
}
}
Expand Down
24 changes: 23 additions & 1 deletion src/views/auth/sign-up.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@
</div>
</div>
<span class="text-danger">{{ errors.first("company") }}</span>
<button class="btn btn-primary btn-block my-4" type="submit">
<button class="btn btn-primary btn-block my-4" type="submit" :disabled="isLoading">
Sign Up
<i v-if="isLoading" class="fa fa-circle-notch fa-spin" />
</button>
<div class="text-center small">
Already have an account?
Expand Down Expand Up @@ -151,6 +152,27 @@ export default {
endpoint: "/users"
}
}
},
methods: {
submitData() {
if (!this.isLoading) {
this.isLoading = true;
const data = this.prepareData(true);
kanvasSDK.auth.register(data)
.then(() => {
this.handleResponse(null, true)
})
.catch(error => {
this.$notify({
title: "Error",
text: error.errors.message,
type: "error"
});
}).finally(() => {
this.isLoading = false;
})
}
}
}
}
</script>