map to new back
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
.flex.items-center.cursor-pointer(@click="changeView", v-if="!wrongData && user.password")
|
||||
img(:src="!isView ? eye_close : eye_open")
|
||||
.flex.items-center.gap-x-8px.-ml-2
|
||||
q-checkbox(@click="persist", v-model="person", type="checkbox")
|
||||
q-checkbox(v-model="person", type="checkbox")
|
||||
.flex.non-italic.font-medium.base Запомнить меня
|
||||
base-button(
|
||||
:disable="disabledButton",
|
||||
@@ -60,67 +60,49 @@ export default {
|
||||
eye_close,
|
||||
eye_open,
|
||||
authorized: true,
|
||||
user: { username: "", password: "" },
|
||||
user: {},
|
||||
userData: {},
|
||||
person: false,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
wrongData() {
|
||||
return !this.authorized && !this.user.username && !this.user.password;
|
||||
return !this.authorized;
|
||||
},
|
||||
changeType() {
|
||||
return !this.isView ? "password" : "text";
|
||||
},
|
||||
disabledButton() {
|
||||
return this.user.username && this.user.password ? false : true;
|
||||
return !(this.user.username && this.user.password);
|
||||
},
|
||||
showBorder() {
|
||||
return !this.authorized && !this.user.username && !this.user.password
|
||||
? true
|
||||
: false;
|
||||
return !this.authorized && !this.user.username && !this.user.password;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
changeView() {
|
||||
this.isView = !this.isView;
|
||||
},
|
||||
persist() {
|
||||
if (!this.person) return;
|
||||
localStorage.username = this.user.username;
|
||||
localStorage.password = this.user.password;
|
||||
},
|
||||
async auth() {
|
||||
let res = await fetchWrapper.get("auth/users/me/");
|
||||
res = await res;
|
||||
let data = await fetchWrapper.get(`accounts/users/${res.id}/detail`);
|
||||
data = await data;
|
||||
this.userData = data;
|
||||
localStorage.setItem("userData", JSON.stringify(this.userData));
|
||||
this.userData = await fetchWrapper.get("users/me");
|
||||
},
|
||||
login() {
|
||||
fetchWrapper
|
||||
.post("auth/jwt/create/", {
|
||||
username: this.user.username,
|
||||
.post("auth/login", {
|
||||
user_name: this.user.username,
|
||||
password: this.user.password,
|
||||
})
|
||||
.then((token) => {
|
||||
if (token.access) {
|
||||
localStorage.setItem("tokenAccess", token.access);
|
||||
this.auth().then(() => this.$router.push("/"));
|
||||
} else {
|
||||
this.authorized = false;
|
||||
this.user.username = "";
|
||||
this.user.password = "";
|
||||
this.$router.push("/login");
|
||||
}
|
||||
.then(() => {
|
||||
this.auth().then(() => this.$router.push("/"));
|
||||
})
|
||||
.catch(() => {
|
||||
this.authorized = false;
|
||||
this.user.username = "";
|
||||
this.user.password = "";
|
||||
this.$router.push("/login");
|
||||
});
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
if (localStorage.username) this.user.username = localStorage.username;
|
||||
if (localStorage.password) this.user.password = localStorage.password;
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user