@sowell/quasar-app-extension-auth 0.3.5 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
  <q-card style="max-width: 343px; border-radius: 10px; background: #f4f5f6">
3
3
  <q-card-section class="text-center q-mt-lg">
4
4
  <img
5
- v-if="sendEmailSuccess && !passwordUpdated"
5
+ v-if="emailSended"
6
6
  src="../../assets/mailbox.svg"
7
7
  style="width: 175px; height: 150px"
8
8
  />
@@ -12,7 +12,7 @@
12
12
  style="width: 100px; height: 80px"
13
13
  />
14
14
  <img
15
- v-if="!sendEmailSuccess && !passwordUpdated"
15
+ v-if="emailNotSend"
16
16
  src="../../assets/error.svg"
17
17
  style="width: 100px; height: 80px"
18
18
  />
@@ -24,26 +24,14 @@
24
24
  style="font-size: 24px; font-weight: 600"
25
25
  data-cy="resetErrorMessage"
26
26
  >
27
- {{
28
- sendEmailSuccess
29
- ? $t("auth.emailVerification")
30
- : !passwordUpdated
31
- ? $t("auth.loginFailed")
32
- : $t("auth.passwordChanged")
33
- }}
27
+ {{ messageTitle }}
34
28
  </div>
35
29
  <div
36
30
  data-cy="resetMessage"
37
31
  class="text-subtitle1 q-mt-sm text-center"
38
32
  style="font-size: 16px; font-weight: 400"
39
33
  >
40
- {{
41
- sendEmailSuccess
42
- ? $t("auth.emailSent")
43
- : !passwordUpdated
44
- ? $t("auth.emailNotRecognize")
45
- : $t("auth.passwordUpdated")
46
- }}
34
+ {{ messageSubtitle }}
47
35
  </div>
48
36
  <div
49
37
  class="q-mt-sm text-center q-mb-xl"
@@ -55,7 +43,7 @@
55
43
  </q-card-section>
56
44
  <q-card-actions class="q-ml-lg q-mr-lg q-mb-lg">
57
45
  <q-btn
58
- v-if="!sendEmailSuccess && !passwordUpdated"
46
+ v-if="emailNotSend"
59
47
  data-cy="submit-login"
60
48
  :label="$t('auth.reSend')"
61
49
  color="primary"
@@ -72,7 +60,7 @@
72
60
  unelevated
73
61
  style="background: #fff"
74
62
  flat
75
- @click="passwordUpdated ? $emit('goToLoginPage') : ''"
63
+ @click="handlePasswordUpdate"
76
64
  no-caps
77
65
  :label="$t('auth.close')"
78
66
  color="dark"
@@ -83,21 +71,19 @@
83
71
  </template>
84
72
 
85
73
  <script lang="ts">
86
- import { defineComponent } from "vue";
74
+ import { defineComponent, computed } from "vue";
75
+ import { useI18n } from "vue-i18n";
87
76
 
88
77
  export default defineComponent({
89
78
  props: {
90
79
  emailResetPassword: {
91
80
  type: String,
92
- required: true,
93
81
  },
94
82
  sendEmailSuccess: {
95
83
  type: Boolean,
96
- required: true,
97
84
  },
98
85
  loading: {
99
86
  type: Boolean,
100
- required: true,
101
87
  },
102
88
  passwordUpdated: {
103
89
  type: Boolean,
@@ -105,10 +91,48 @@ export default defineComponent({
105
91
  },
106
92
  emit: ["retypeEmail", "goToLoginPage"],
107
93
  setup(props: any, { emit }: any) {
94
+ const { t } = useI18n();
95
+
96
+ const messageSubtitle = computed(() =>
97
+ props.sendEmailSuccess
98
+ ? t("auth.emailSent")
99
+ : !props.passwordUpdated
100
+ ? t("auth.emailNotRecognize")
101
+ : t("auth.passwordUpdated"),
102
+ );
103
+ const messageTitle = computed(() =>
104
+ props.sendEmailSuccess
105
+ ? t("auth.emailVerification")
106
+ : !props.passwordUpdated
107
+ ? t("auth.loginFailed")
108
+ : t("auth.passwordChanged"),
109
+ );
110
+
111
+ const emailNotSend = computed(
112
+ () => !props.sendEmailSuccess && !props.passwordUpdated,
113
+ );
114
+ const emailSended = computed(
115
+ () => props.sendEmailSuccess && !props.passwordUpdated,
116
+ );
117
+
108
118
  const retypeEmail = () => {
109
119
  emit("retypeEmail");
110
120
  };
111
- return { retypeEmail };
121
+
122
+ const handlePasswordUpdate = () =>{
123
+ if(props.passwordUpdated){
124
+ emit("goToLoginPage")
125
+ }
126
+ }
127
+
128
+ return {
129
+ messageSubtitle,
130
+ messageTitle,
131
+ emailNotSend,
132
+ emailSended,
133
+ handlePasswordUpdate,
134
+ retypeEmail,
135
+ };
112
136
  },
113
137
  });
114
138
  </script>
@@ -48,7 +48,7 @@
48
48
  autofocus
49
49
  >
50
50
  <template #prepend>
51
- <q-icon :name="ionMailOutline" />
51
+ <q-icon :name="icons.ionMailOutline" />
52
52
  </template>
53
53
  </q-input>
54
54
  </div>
@@ -57,7 +57,7 @@
57
57
  <q-card-actions class="q-ml-lg q-mr-lg q-mb-lg row justify-center">
58
58
  <q-btn
59
59
  color="primary"
60
- :icon="ionPaperPlaneOutline"
60
+ :icon="icons.ionPaperPlaneOutline"
61
61
  style="max-width: 330px"
62
62
  data-cy="sendEmails"
63
63
  no-caps
@@ -87,11 +87,14 @@ export default defineComponent({
87
87
  const sendEmail = () => {
88
88
  emit("resetPassword", email.value);
89
89
  };
90
+
90
91
  return {
91
- sendEmail,
92
92
  email,
93
- ionMailOutline,
94
- ionPaperPlaneOutline,
93
+ sendEmail,
94
+ icons: {
95
+ ionMailOutline,
96
+ ionPaperPlaneOutline,
97
+ },
95
98
  };
96
99
  },
97
100
  });
@@ -0,0 +1,108 @@
1
+ <template>
2
+ <q-card>
3
+ <q-page class="row bg-white">
4
+ <div class="col-6 q-pa-xl row justify-center">
5
+ <div class="left-side full-width full-height">
6
+ <img
7
+ class="logo"
8
+ src="../../assets/Sowell-logo.svg"
9
+ alt="Logo sowell"
10
+ />
11
+ <div class="bottom column justify-center full-height">
12
+ <div
13
+ class="q-mb-sm"
14
+ style="font-size: 34px; font-weight: 600; line-height: 40px"
15
+ >
16
+ {{ FORGOTTEN_PASSWORD_TITLE }}
17
+ </div>
18
+ <div class="text-subtitle1 q-mt-sm q-mb-lg">
19
+ {{ FORGOTTEN_PASSWORD_SUBTITLE }}
20
+ </div>
21
+ <div class="q-mt-lg q-ml-xs q-mb-xs text-semi-bold">
22
+ {{ $t("auth.email") }}
23
+ </div>
24
+ <q-input
25
+ v-model="email"
26
+ dense
27
+ outlined
28
+ bg-color="white"
29
+ data-cy="emailReset"
30
+ autofocus
31
+ />
32
+ <div class="q-mt-lg row">
33
+ <q-btn
34
+ color="primary"
35
+ :icon-right="icons.ionPaperPlaneOutline"
36
+ style="max-width: 330px"
37
+ data-cy="sendEmails"
38
+ align="center"
39
+ no-caps
40
+ unelevated
41
+ :label="$t('common.reset')"
42
+ class="btn-min"
43
+ @click="sendEmail"
44
+ v-close-popup
45
+ />
46
+ </div>
47
+ </div>
48
+ </div>
49
+ </div>
50
+ <div class="col-6 bg-image row justify-center items-center">
51
+ <img
52
+ class="illustration"
53
+ src="../../assets/Illustration-password.svg"
54
+ alt=""
55
+ />
56
+ </div>
57
+ </q-page>
58
+ </q-card>
59
+ </template>
60
+
61
+ <script lang="ts">
62
+ // @ts-ignore
63
+ import { defineComponent, ref } from "vue";
64
+ import prompts from "app/quasar.extensions.json";
65
+ import { ionPaperPlaneOutline } from "@quasar/extras/ionicons-v5";
66
+
67
+ export default defineComponent({
68
+ name: "WebSendMail",
69
+ emit: ["resetPassword"],
70
+ setup(props: any, { emit }: any) {
71
+ const {
72
+ "@sowell/auth": { FORGOTTEN_PASSWORD_TITLE, FORGOTTEN_PASSWORD_SUBTITLE },
73
+ } = prompts;
74
+ const email = ref("");
75
+ const sendEmail = () => {
76
+ emit("resetPassword", email.value);
77
+ };
78
+ return {
79
+ email,
80
+ FORGOTTEN_PASSWORD_TITLE,
81
+ FORGOTTEN_PASSWORD_SUBTITLE,
82
+ sendEmail,
83
+ icons: {
84
+ ionPaperPlaneOutline,
85
+ },
86
+ };
87
+ },
88
+ });
89
+ </script>
90
+
91
+ <style>
92
+ .bg-image {
93
+ background: #eef8fd;
94
+ height: 100vh !important;
95
+ }
96
+ .bottom {
97
+ margin-top: -80px;
98
+ }
99
+ .logo {
100
+ width: 210px;
101
+ }
102
+ .left-side {
103
+ max-width: 500px;
104
+ }
105
+ .illustration {
106
+ width: 600px;
107
+ }
108
+ </style>
@@ -0,0 +1,87 @@
1
+ <template>
2
+ <q-card>
3
+ <q-card-section class="top">
4
+ <div class="full-width button-close row justify-end">
5
+ <q-btn
6
+ unelevated
7
+ :icon="icons.ionCloseOutline"
8
+ flat
9
+ round
10
+ no-caps
11
+ color="dark"
12
+ v-close-popup
13
+ />
14
+ </div>
15
+ <div class="row justify-center">
16
+ <img :src="image" />
17
+ </div>
18
+ </q-card-section>
19
+
20
+ <q-card-section class="content q-pl-lg q-pr-lg">
21
+ <h5 class="q-mt-sm q-mb-md text-center text-dark">
22
+ {{ title }}
23
+ </h5>
24
+ <div class="text-subtitle1 q-mt-sm text-center text-dark">
25
+ {{ content }}
26
+ </div>
27
+ </q-card-section>
28
+ <q-card-actions class="row full-width justify-center q-mb-lg">
29
+ <q-btn
30
+ class="bg-white submitBtn"
31
+ unelevated
32
+ outline
33
+ no-caps
34
+ :label="$t('auth.close')"
35
+ @click="passwordUpdated ? $emit('goToLoginPage') : ''"
36
+ color="primary"
37
+ v-close-popup
38
+ />
39
+ </q-card-actions>
40
+ </q-card>
41
+ </template>
42
+ <script lang="ts">
43
+ import { defineComponent, computed } from "vue";
44
+ import userNotFound from "../../assets/User-not-found.svg";
45
+ import passwordUpdated from "../../assets/Ok-illustration.svg";
46
+ import emailVerification from "../../assets/Email-sent.svg";
47
+ import { ionCloseOutline } from "@quasar/extras/ionicons-v5";
48
+
49
+ export default defineComponent({
50
+ name: "swInfoDialog",
51
+ props: {
52
+ title: { type: String, required: true },
53
+ content: { type: String, required: true },
54
+ image: { type: String, required: true },
55
+ passwordUpdated: { type: Boolean },
56
+ },
57
+ emit: ["goToLoginPage"],
58
+ setup(props: any) {
59
+ const image = computed(() => {
60
+ switch (props.image) {
61
+ case "userNotFound":
62
+ return userNotFound;
63
+
64
+ case "passwordUpdated":
65
+ return passwordUpdated;
66
+
67
+ case "emailVerification":
68
+ return emailVerification;
69
+ }
70
+ });
71
+ return { image, icons: { ionCloseOutline } };
72
+ },
73
+ });
74
+ </script>
75
+ <style lang="sass">
76
+ .top
77
+ background: #EEF8FD
78
+
79
+ img
80
+ width: 277px
81
+
82
+ .submitBtn
83
+ width: 254px
84
+
85
+ .content
86
+ max-width: 429px
87
+ </style>
@@ -47,7 +47,7 @@
47
47
  :input-style="{ fontSize: '14px', fontWeight: '500' }"
48
48
  >
49
49
  <template #prepend>
50
- <q-icon :name="ionMailOutline" />
50
+ <q-icon :name="icons.ionMailOutline" />
51
51
  </template>
52
52
  </q-input>
53
53
  </div>
@@ -69,11 +69,13 @@
69
69
  :input-style="{ fontSize: '14px', fontWeight: '600' }"
70
70
  >
71
71
  <template #prepend>
72
- <q-icon :name="ionLockClosedOutline" />
72
+ <q-icon :name="icons.ionLockClosedOutline" />
73
73
  </template>
74
74
  <template #append>
75
75
  <q-icon
76
- :name="showPassword ? ionEyeOffOutline : ionEyeOutline "
76
+ :name="
77
+ showPassword ? icons.ionEyeOffOutline : icons.ionEyeOutline
78
+ "
77
79
  class="cursor-pointer q-mr-sm"
78
80
  @click="showPassword = !showPassword"
79
81
  />
@@ -128,171 +130,51 @@
128
130
  </template>
129
131
 
130
132
  <script lang="ts">
131
- import isEmail from "validator/es/lib/isEmail";
132
- import { defineComponent, ref, onMounted } from "vue";
133
- import { $api, $prompts, $router, $store } from "../../injects";
134
- import { useQuasar } from "quasar";
135
- import { useI18n } from "vue-i18n";
136
- import { AxiosError, AxiosResponse } from "axios";
137
- import prompts from "app/quasar.extensions.json";
133
+ import { defineComponent } from "vue";
134
+
138
135
  import SendEmail from "../dialogs/SendEmail.vue";
139
136
  import SowellMessage from "../dialogs/Message.vue";
140
- import {
141
- ionMailOutline,
142
- ionLockClosedOutline,
143
- ionEyeOutline,
144
- ionEyeOffOutline,
145
- ionAlertCircleOutline,
146
- ionCloseOutline
147
- } from "@quasar/extras/ionicons-v5";
148
-
149
- interface HeadersInterface {
150
- headers: {
151
- "x-requested-roles"?: string
152
- }
153
- }
137
+ import { useAuth } from "composables/auth";
154
138
 
155
139
  export default defineComponent({
156
140
  name: "Auth",
157
141
  components: { SendEmail, SowellMessage },
158
142
  setup() {
159
143
  const {
160
- "@sowell/auth": { X_REQUESTED_ROLES },
161
- } = prompts;
162
- const email = ref("");
163
- const password = ref("");
164
- const loading = ref(false);
165
- const showPassword = ref(false);
166
- const forgottenPassword = ref(false);
167
- const isReset = ref(false);
168
- const sendEmailSuccess = ref(false);
169
- const emailResetPassword = ref("");
170
- const { post } = $api();
171
- const {
172
- LOCAL_SUCCESS_REDIRECTION_ROUTE,
173
- AUTH_SERVER_SIGNING_ROUTE,
174
- AUTH_SERVER_RESET_PASSWORD_ROUTE,
144
+ email,
145
+ password,
146
+ loading,
147
+ showPassword,
148
+ validations,
149
+ forgottenPassword,
150
+ emailResetPassword,
151
+ isReset,
152
+ sendEmailSuccess,
153
+ authState,
175
154
  APP_SERVER_BASE_URL,
176
- } = $prompts();
177
- const $q = useQuasar();
178
- const { push, replace } = $router();
179
- const { dispatch, getters } = $store();
180
- const { t } = useI18n();
181
-
182
- onMounted(() => {
183
- if (getters["token/getRaw"]) {
184
- replace(LOCAL_SUCCESS_REDIRECTION_ROUTE);
185
- }
186
- });
187
-
188
- const validations = ref({
189
- email: [
190
- (val: string) => !!val || t("auth.emailPresenceError"),
191
- (val: string) => isEmail(val.trim()) || t("auth.emailValidationError"),
192
- ],
193
- password: [(val: string) => !!val || t("auth.passwordPresenceError")],
194
- });
155
+ onSubmit,
156
+ retypeEmail,
157
+ isSubmitBtnDisabled,
158
+ icons,
159
+ } = useAuth();
195
160
 
196
- const resetPassword = (email: string) => {
161
+ const resetPassword = async (email: string) => {
197
162
  const data = {
198
163
  auth: {
199
164
  email,
200
165
  base: APP_SERVER_BASE_URL,
201
166
  },
202
167
  };
203
-
204
-
205
- post(AUTH_SERVER_RESET_PASSWORD_ROUTE, data)
206
- .then(() => {
207
- forgottenPassword.value = false;
208
- isReset.value = true;
168
+ try {
169
+ forgottenPassword.value = false;
170
+ await authState.resetPassword(data).then(() => {
209
171
  sendEmailSuccess.value = true;
210
- })
211
- .catch(() => {
212
172
  isReset.value = true;
213
173
  });
214
- };
215
-
216
- const retypeEmail = () => {
217
- forgottenPassword.value = true
218
- }
219
-
220
- const onSubmit = () => {
221
- loading.value = true;
222
- const data = {
223
- auth: {
224
- email: email.value,
225
- password: password.value,
226
- },
227
- };
228
- const options: HeadersInterface = {
229
- headers:{}
230
- };
231
- // @ts-ignore
232
- let requestedRoles = window.Cypress ? window.Cypress.requestedRoles : X_REQUESTED_ROLES;
233
- if (requestedRoles) options.headers["x-requested-roles"] = requestedRoles;
234
-
235
- post(AUTH_SERVER_SIGNING_ROUTE, data, options)
236
- .then((response: AxiosResponse) => {
237
- const token = response.data.jwt;
238
- dispatch("token/updateRaw", token);
239
- push(LOCAL_SUCCESS_REDIRECTION_ROUTE);
240
- })
241
- .catch((error: AxiosError) => {
242
- loading.value = false;
243
- switch (error.response?.status) {
244
- case 403:
245
- $q.notify({
246
- message: t("auth.403"),
247
- color: "negative",
248
- icon: ionAlertCircleOutline,
249
- position: "top",
250
- actions: [
251
- {
252
- color: "white",
253
- icon: ionCloseOutline,
254
- },
255
- ],
256
- });
257
- break;
258
- case 404:
259
- $q.notify({
260
- message: t("auth.404"),
261
- color: "negative",
262
- icon: ionAlertCircleOutline,
263
- position: "top",
264
- actions: [
265
- {
266
- color: "white",
267
- icon: ionCloseOutline,
268
- },
269
- ],
270
- });
271
- break;
272
- default:
273
- $q.notify({
274
- message: t("auth.loginFailed"),
275
- color: "negative",
276
- icon: ionAlertCircleOutline,
277
- position: "top",
278
- actions: [
279
- {
280
- color: "white",
281
- icon: ionCloseOutline,
282
- },
283
- ],
284
- });
285
- }
286
- });
287
- };
288
-
289
- const isSubmitBtnDisabled = () => {
290
- return !(
291
- email.value &&
292
- isEmail(email.value) &&
293
- password.value &&
294
- password.value.length > 5
295
- );
174
+ } catch {
175
+ sendEmailSuccess.value = false;
176
+ isReset.value = true;
177
+ }
296
178
  };
297
179
 
298
180
  return {
@@ -301,18 +183,15 @@ export default defineComponent({
301
183
  loading,
302
184
  showPassword,
303
185
  validations,
304
- isSubmitBtnDisabled,
305
- onSubmit,
306
186
  forgottenPassword,
307
187
  emailResetPassword,
308
- resetPassword,
309
188
  isReset,
310
- retypeEmail,
311
189
  sendEmailSuccess,
312
- ionMailOutline,
313
- ionLockClosedOutline,
314
- ionEyeOutline,
315
- ionEyeOffOutline,
190
+ onSubmit,
191
+ resetPassword,
192
+ isSubmitBtnDisabled,
193
+ retypeEmail,
194
+ icons,
316
195
  };
317
196
  },
318
197
  });