[O] Combine onEnter with loginClick

This commit is contained in:
Hykilpikonna
2020-05-25 21:15:17 -04:00
parent 96306afecf
commit 48b4b989b1
2 changed files with 16 additions and 23 deletions
+13 -20
View File
@@ -59,19 +59,10 @@ export default class Login extends Vue
}
/**
* When the user clicks, send the username and password to the server.
* When the user clicks, post the login request and process the response
* This is also called when the user hits enter on the input boxes.
*/
onLoginClick()
{
this.login()
}
/**
* Actually post the login request and process the response
*/
login()
loginClick()
{
// Make login button loading
this.loading = true;
@@ -79,8 +70,18 @@ export default class Login extends Vue
// Format it
this.username = this.username.toLowerCase().replace(/ /g, '').replace(/@.*/g, '');
// Actually login
this.login('/login', {username: this.username, password: this.password})
}
/**
* Actually post the request and process the response
*/
login(url: string, data: any)
{
// Fetch request
App.http.post('/login', {username: this.username, password: this.password}).then(response =>
App.http.post(url, data).then(response =>
{
// Check success
if (response.success)
@@ -114,14 +115,6 @@ export default class Login extends Vue
});
}
/**
* This is called when the user hits enter on the input boxes.
*/
onEnter()
{
this.onLoginClick();
}
/**
* Clear cookies
*/
+3 -3
View File
@@ -10,7 +10,7 @@
placeholder="SJP Username (Eg. flast21)"
:class="{'input-error': error !== ''}"
v-if="!disableInput"
@keyup.enter.native="onEnter">
@keyup.enter.native="loginClick">
</el-input>
<el-input v-model="password"
@@ -18,12 +18,12 @@
show-password=""
:class="{'input-error': error !== ''}"
v-if="!disableInput"
@keyup.enter.native="onEnter">
@keyup.enter.native="loginClick">
</el-input>
<div class="el-form-item__error custom">{{error}}</div>
<el-button plain type="primary" @click="onLoginClick" :loading="loading">Login</el-button>
<el-button plain type="primary" @click="loginClick" :loading="loading">Login</el-button>
</form>
</div>
</div>