Fix login page (#80)

Co-authored-by: Marioneq <marioneq4958@gmail.com>
Co-authored-by: Zaptyp <43276401+Zaptyp@users.noreply.github.com>
This commit is contained in:
Patryk 2022-02-03 09:59:38 +01:00 committed by GitHub
parent 5a208feec0
commit 069ff795bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 48 deletions

View file

@ -2,21 +2,23 @@ import axios, { AxiosResponse } from 'axios';
import Cookies from 'universal-cookie'; import Cookies from 'universal-cookie';
export default { export default {
register: async (email: string, password: string, symbol: string): Promise<AxiosResponse> => { login: async (email: string, password: string, symbol: string, diaryUrl: string)
: Promise<AxiosResponse> => {
const cookies = new Cookies(); const cookies = new Cookies();
const response = await axios({ const response = await axios({
method: 'post', method: 'POST',
url: 'http://localhost:8000/api/login', url: 'http://localhost:8000/api/login',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-CSRFToken': cookies.get('csrf-token'), 'X-CSRFToken': cookies.get('csrftoken'),
}, },
data: { data: {
loginName: email, loginName: email,
Password: password, Password: password,
Symbol: symbol, Symbol: symbol,
diaryUrl: 'http://cufs.fakelog.tk/', diaryUrl,
}, },
withCredentials: true,
}); });
document.cookie = response.headers['Set-Cookie']; document.cookie = response.headers['Set-Cookie'];

View file

@ -30,12 +30,14 @@
/> />
<v-select <v-select
color="red" color="red"
v-model="selectedSymbol" :items="diaryNames"
v-model="selectedDiary"
item-value=""
v-on:change="itemSelected()"
label="Symbol"
selection="index"
:disabled="inputDisabled" :disabled="inputDisabled"
label="Wybierz odmianę dziennika UONET+"
outlined outlined
:items="domains"
v-on:change="fakelog()"
item-color="red" item-color="red"
/> />
</v-col> </v-col>
@ -50,64 +52,54 @@
</v-col> </v-col>
</div> </div>
</template> </template>
<script>
<script lang="ts">
import Vue from 'vue'; import Vue from 'vue';
import login from '../../api/login'; import login from '../../api/login';
import diary from '../../assets/data/diary.json';
export default { interface Login {
login: string
password: string
symbol: string
diaryNames: Array<string>
selectedDiary: string
inputDisabled: boolean
}
export default Vue.extend({
name: 'UserLogin', name: 'UserLogin',
data() { data: (): Login => ({
return { login: '',
inputDisabled: false, password: '',
login: '', symbol: '',
password: '', diaryNames: [],
selectedSymbols: '', selectedDiary: '',
symbols: '', inputDisabled: false,
domains: [ }),
'Vulcan', created() {
'Fakelog', this.diaryNames = diary.diaries.map((item): string => item.name);
],
};
}, },
methods: { methods: {
async loginUser() { async loginUser() {
this.inputDisabled = true;
Vue.set(this.$store.state, 'isLoading', true); Vue.set(this.$store.state, 'isLoading', true);
const index = diary.diaries.findIndex((item) => item.name === this.selectedSymbol); const index = diary.diaries.findIndex((item) => item.name === this.selectedDiary);
const response = await login.login(this.login, this.password, const response = await login.login(this.login, this.password,
'powiatwulkanowy', diary.diaries[index].url); 'powiatwulkanowy', diary.diaries[index].url);
this.$store.state.loginData = response.data; this.$store.state.loginData = response.data;
if (this.$store.state.loginData.data.students.data.length > 1) { if (this.$store.state.loginData.data.students.data.length > 1) {
this.$store.state.showStudentsList = true;
this.$store.state.isLoading = false; this.$store.state.isLoading = false;
this.$store.state.showStudentsList = true;
} else {
alert('Dane logowania są nie prawidłowe!');
} }
}, },
itemSelected() {
fakelog() { if (this.selectedDiary === 'Fakelog') {
if (this.selectedSymbol === 'Fakelog') { this.login = 'jan@fakelog.tk';
this.login = 'jan@fakelog.cf';
this.password = 'jan123'; this.password = 'jan123';
this.symbol = 'powiatwulkanowy'; this.symbol = 'powiatwulkanowy';
} }
}, },
}, },
}; });
</script> </script>
<style>
#App{
padding: 10px;
}
#nag{
text-align: center;
font-weight: 300;
font-size: 1.3pc;
margin-bottom: 1pc;
}
#buttonOne{
margin-right: auto;
display: block;
float: left;
}
</style>

View file

@ -7,6 +7,7 @@
"importHelpers": true, "importHelpers": true,
"moduleResolution": "node", "moduleResolution": "node",
"skipLibCheck": true, "skipLibCheck": true,
"resolveJsonModule": true,
"esModuleInterop": true, "esModuleInterop": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"sourceMap": true, "sourceMap": true,