Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit b2724cd

Browse files
committed
user model changes ping pong
1 parent f3d1352 commit b2724cd

File tree

6 files changed

+378
-406
lines changed

6 files changed

+378
-406
lines changed

src/api/auth.js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const eventHandler = new Vue();
88

99
let state = {
1010
auth: false,
11-
email: null,
11+
username: null,
1212
displayName: null,
1313
firstName: null,
1414
lastName: null,
@@ -28,37 +28,25 @@ async function offAuthStateChange(callback) {
2828
eventHandler.$on(eventKey, callback);
2929
}
3030

31-
async function login(email, password) {
31+
async function login(username, password) {
3232
await request(routes.userapi_login, {
3333
data: {
34-
username: email,
34+
username,
3535
password
3636
}
3737
});
3838
await fetchState();
3939
}
4040

41-
async function createAccount(email, password, firstName, lastName) {
42-
await request(
43-
routes.userapi_register,
44-
{
45-
data: {
46-
username: email,
47-
password,
48-
email,
49-
firstname: firstName,
50-
lastname: lastName
51-
}
52-
},
53-
false
54-
);
55-
await login(email, password);
41+
async function createAccount(data) {
42+
await request(routes.userapi_register, { data }, false);
43+
await login(data.username, data.password, false);
5644
}
5745

5846
async function fetchState() {
5947
const userData = await request(routes.userapi_hello, {}, state.auth);
6048
await setState({
61-
email: userData.email,
49+
username: userData.username,
6250
firstName: userData.firstname,
6351
lastName: userData.lastname,
6452
displayName: userData.firstname + " " + userData.lastname,

src/store/user.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const moduleName = "User";
66

77
function getDefaultState() {
88
return {
9+
username: "",
910
firstName: "",
1011
lastName: "",
1112
email: "",

src/views/Login.vue

Lines changed: 75 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,86 @@
11
<template>
2-
<v-row align="center" justify="center">
3-
<v-col cols="12" sm="8" md="4">
4-
<v-card flat class="mt-12">
5-
<v-toolbar color="secondary" dark flat>
6-
<v-toolbar-title>Login form</v-toolbar-title>
7-
</v-toolbar>
8-
<v-form @submit.prevent="validate" ref="form">
9-
<v-card-text>
10-
<v-text-field
11-
v-bind="fields.username"
12-
v-model="fields.username.value"
13-
:disabled="isSubmitting"
14-
/>
2+
<v-row align="center" justify="center">
3+
<v-col cols="12" sm="8" md="4">
4+
<v-card flat class="mt-12">
5+
<v-toolbar color="secondary" dark flat>
6+
<v-toolbar-title>Login form</v-toolbar-title>
7+
</v-toolbar>
8+
<v-form @submit.prevent="validate" ref="form">
9+
<v-card-text>
10+
<v-text-field
11+
v-bind="fields.username"
12+
v-model="fields.username.value"
13+
:disabled="isSubmitting"
14+
/>
1515

16-
<v-text-field
17-
v-bind="fields.password"
18-
v-model="fields.password.value"
19-
:disabled="isSubmitting"
20-
/>
21-
</v-card-text>
16+
<v-text-field
17+
v-bind="fields.password"
18+
v-model="fields.password.value"
19+
:disabled="isSubmitting"
20+
/>
21+
</v-card-text>
2222

23-
<v-card-text>
24-
<router-link :to="{ name: 'reset-password' }"
25-
>Forgot your password?</router-link
26-
>
27-
</v-card-text>
23+
<v-card-text>
24+
<router-link :to="{ name: 'reset-password' }">Forgot your password?</router-link>
25+
</v-card-text>
2826

29-
<v-card-actions>
30-
<v-spacer />
31-
<v-btn
32-
color="secondary darken-2"
33-
type="submit"
34-
dark
35-
:disabled="isSubmitting"
36-
>
37-
Sign In
38-
</v-btn>
39-
</v-card-actions>
40-
</v-form>
41-
</v-card>
42-
</v-col>
43-
</v-row>
27+
<v-card-actions>
28+
<v-spacer />
29+
<v-btn color="secondary darken-2" type="submit" dark :disabled="isSubmitting">Sign In</v-btn>
30+
</v-card-actions>
31+
</v-form>
32+
</v-card>
33+
</v-col>
34+
</v-row>
4435
</template>
4536

4637
<script>
4738
import { auth } from "@/api";
4839
export default {
49-
name: "login",
50-
methods: {
51-
async submit() {
52-
if (this.isSubmitting) {
53-
return;
54-
}
55-
this.isSubmitting = true;
56-
try {
57-
await auth.login(
58-
this.fields.username.value,
59-
this.fields.password.value
60-
);
61-
localStorage.setItem("lastEmail", this.fields.username.value);
62-
this.$store.dispatch("Snackbar/showInfo", "Successfully Logged In");
63-
this.$router.push({ name: "quiz" });
64-
} catch (err) {
65-
this.$store.dispatch("Snackbar/showError", err);
66-
}
67-
this.isSubmitting = false;
68-
},
69-
validate() {
70-
if (this.$refs.form.validate()) {
71-
this.submit();
72-
}
73-
}
74-
},
75-
data() {
76-
return {
77-
isSubmitting: false,
78-
fields: {
79-
username: {
80-
label: "Username",
81-
type: "text",
82-
value: localStorage.getItem("lastEmail"),
83-
rules: [v => !!v || "Please provide a username"]
84-
},
85-
password: {
86-
label: "Password",
87-
type: "password",
88-
value: "",
89-
rules: [v => !!v || "Please provide a password"]
90-
}
91-
}
92-
};
93-
}
40+
name: "login",
41+
methods: {
42+
async submit() {
43+
if (this.isSubmitting) {
44+
return;
45+
}
46+
this.isSubmitting = true;
47+
try {
48+
await auth.login(
49+
this.fields.username.value,
50+
this.fields.password.value
51+
);
52+
localStorage.setItem("lastUsername", this.fields.username.value);
53+
this.$store.dispatch("Snackbar/showInfo", "Successfully Logged In");
54+
this.$router.push({ name: "quiz" });
55+
} catch (err) {
56+
this.$store.dispatch("Snackbar/showError", err);
57+
}
58+
this.isSubmitting = false;
59+
},
60+
validate() {
61+
if (this.$refs.form.validate()) {
62+
this.submit();
63+
}
64+
}
65+
},
66+
data() {
67+
return {
68+
isSubmitting: false,
69+
fields: {
70+
username: {
71+
label: "Username",
72+
type: "text",
73+
value: localStorage.getItem("lastEmail"),
74+
rules: [v => !!v || "Please provide a username"]
75+
},
76+
password: {
77+
label: "Password",
78+
type: "password",
79+
value: "",
80+
rules: [v => !!v || "Please provide a password"]
81+
}
82+
}
83+
};
84+
}
9485
};
9586
</script>

src/views/Register/Step1.vue

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,60 @@
11
<template>
2-
<v-form @submit.prevent="validate" ref="form" v-model="isValid">
3-
<v-card-text>
4-
<v-text-field
5-
v-bind="fields.parentEmail"
6-
v-model="fields.parentEmail.value"
7-
:disabled="isSubmitting"
8-
/>
9-
<v-text-field
10-
v-bind="fields.password"
11-
v-model="fields.password.value"
12-
:disabled="isSubmitting"
13-
/>
14-
<v-text-field
15-
v-bind="fields.passwordConfirm"
16-
v-model="fields.passwordConfirm.value"
17-
:disabled="isSubmitting"
18-
/>
19-
</v-card-text>
2+
<v-form @submit.prevent="validate" ref="form" v-model="isValid">
3+
<v-card-text>
4+
<v-text-field
5+
v-bind="fields.username"
6+
v-model="fields.username.value"
7+
:disabled="isSubmitting"
8+
/>
9+
<v-text-field
10+
v-bind="fields.parentEmail"
11+
v-model="fields.parentEmail.value"
12+
:disabled="isSubmitting"
13+
/>
14+
<v-text-field v-bind="fields.password" v-model="fields.password.value" :disabled="isSubmitting" />
15+
<v-text-field
16+
v-bind="fields.passwordConfirm"
17+
v-model="fields.passwordConfirm.value"
18+
:disabled="isSubmitting"
19+
/>
20+
</v-card-text>
2021

21-
<v-card-actions>
22-
<v-spacer />
23-
<v-btn color="secondary darken-2" type="submit" :disabled="isSubmitting">
24-
Next
25-
<v-progress-circular
26-
size="14"
27-
class="ml-3"
28-
indeterminate
29-
v-if="isSubmitting"
30-
/>
31-
</v-btn>
32-
</v-card-actions>
33-
</v-form>
22+
<v-card-actions>
23+
<v-spacer />
24+
<v-btn color="secondary darken-2" type="submit" :disabled="isSubmitting">
25+
Next
26+
<v-progress-circular size="14" class="ml-3" indeterminate v-if="isSubmitting" />
27+
</v-btn>
28+
</v-card-actions>
29+
</v-form>
3430
</template>
3531

3632
<script>
3733
export default {
38-
name: "register-step-1",
39-
props: ["fields"],
40-
methods: {
41-
async submit() {
42-
if (this.isSubmitting) {
43-
return;
44-
}
45-
this.isSubmitting = true;
46-
const cb = () => {
47-
this.isSubmitting = false;
48-
};
49-
this.$emit("submit", cb);
50-
},
51-
validate() {
52-
if (this.$refs.form.validate()) {
53-
this.submit();
54-
}
55-
}
56-
},
57-
data() {
58-
return {
59-
isValid: false,
60-
isSubmitting: false
61-
};
62-
}
34+
name: "register-step-1",
35+
props: ["fields"],
36+
methods: {
37+
async submit() {
38+
if (this.isSubmitting) {
39+
return;
40+
}
41+
this.isSubmitting = true;
42+
const cb = () => {
43+
this.isSubmitting = false;
44+
};
45+
this.$emit("submit", cb);
46+
},
47+
validate() {
48+
if (this.$refs.form.validate()) {
49+
this.submit();
50+
}
51+
}
52+
},
53+
data() {
54+
return {
55+
isValid: false,
56+
isSubmitting: false
57+
};
58+
}
6359
};
6460
</script>

0 commit comments

Comments
 (0)