Extract some types
This commit is contained in:
@ -1,22 +1,23 @@
|
||||
<script>
|
||||
import { LOGIN, LOGIN_SUCCESS, TITLE } from "../store/mutation-types";
|
||||
import { TITLE } from "../store/mutation-types";
|
||||
import { LOGIN } from '../store/action-types'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
error: [],
|
||||
login: {
|
||||
user: "",
|
||||
user: "",
|
||||
password: ""
|
||||
},
|
||||
showPassword: false
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
mounted() {
|
||||
this.$store.commit(TITLE, "Login");
|
||||
},
|
||||
methods: {
|
||||
formSubmit (e) {
|
||||
formSubmit(e) {
|
||||
e.preventDefault();
|
||||
this.$store.dispatch(LOGIN, this.$data.login)
|
||||
.then(x => {
|
||||
@ -39,21 +40,23 @@ export default {
|
||||
<v-text-field v-model="login.user" type="text" label="Username" />
|
||||
</v-col>
|
||||
<v-col cols="12">
|
||||
<v-text-field v-model="login.password" label="Password"
|
||||
:append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'"
|
||||
<v-text-field
|
||||
v-model="login.password"
|
||||
label="Password"
|
||||
:append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'"
|
||||
:type="showPassword ? 'text' : 'password'"
|
||||
@click:append="showPassword = showPassword"
|
||||
:error-message="error"
|
||||
error-count="2"
|
||||
error />
|
||||
error
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<div class="form-group">
|
||||
{{ error }}
|
||||
</div>
|
||||
<div class="form-group">{{ error }}</div>
|
||||
<v-btn type="submit" @click="formSubmit">Login</v-btn>
|
||||
<p>
|
||||
New user? <router-link to="/register">Register</router-link> instead!
|
||||
New user?
|
||||
<router-link to="/register">Register</router-link>instead!
|
||||
</p>
|
||||
</v-container>
|
||||
</template>
|
@ -1,64 +1,5 @@
|
||||
<!--{{define "title"}}Register{{end}}
|
||||
|
||||
{{template "base" .}}
|
||||
|
||||
{{define "more-head"}}
|
||||
<script>
|
||||
function checkPasswordMatchUi() {
|
||||
if(checkPasswordMatch())
|
||||
$("#divCheckPasswordMatch").html("Passwords match.");
|
||||
else
|
||||
$("#divCheckPasswordMatch").html("Passwords do not match!");
|
||||
}
|
||||
|
||||
function checkPasswordMatch() {
|
||||
var password = $("#password").val();
|
||||
var confirmPassword = $("#password_confirm").val();
|
||||
return password == confirmPassword;
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$("#password, #password_confirm").keyup(checkPasswordMatchUi);
|
||||
$('#invalidCredentials').hide();
|
||||
$('#loginForm').ajaxForm({
|
||||
beforeSubmit: function(a, b, c) {
|
||||
var match = checkPasswordMatch();
|
||||
if(!match){
|
||||
$("#divCheckPasswordMatch").fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
|
||||
}
|
||||
return match;
|
||||
},
|
||||
success: function() {
|
||||
window.location.href = "/dashboard";
|
||||
},
|
||||
error: function() {
|
||||
$('#invalidCredentials').show();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
<form id="loginForm" action="/api/v1/user/register" method="POST" class="center-block">
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" name="password" id="password" class="form-control" placeholder="Password" />
|
||||
<input type="password" id="password_confirm" class="form-control" placeholder="Verify password" />
|
||||
</div>
|
||||
|
||||
<div id="divCheckPasswordMatch"></div>
|
||||
|
||||
<div id="invalidCredentials">
|
||||
Username already exists
|
||||
</div>
|
||||
|
||||
<input type="submit" value="Login" class="form-control" />
|
||||
|
||||
</form>
|
||||
{{end}}-->
|
||||
|
||||
<script>import { LOGIN_SUCCESS } from "../store/mutation-types";
|
||||
import { REGISTER } from "../store/action-types";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@ -73,13 +14,9 @@ export default {
|
||||
methods: {
|
||||
formSubmit (e) {
|
||||
e.preventDefault();
|
||||
fetch("/api/v1/user/register", {method: "POST", body: JSON.stringify(this.$data.login)})
|
||||
.then(x => x.json())
|
||||
.then(x => {
|
||||
this.$data.error = ""
|
||||
this.$store.commit(LOGIN_SUCCESS, x.token);
|
||||
})
|
||||
.catch(x => this.$data.error = ["Something went wrong!"]);
|
||||
this.$store.dispatch(REGISTER, this.$data.login)
|
||||
.then(() => this.$data.error = "")
|
||||
.catch(() => this.$data.error = ["Something went wrong!"]);
|
||||
|
||||
// TODO display invalidCredentials
|
||||
// TODO redirect to dashboard on success
|
||||
|
Reference in New Issue
Block a user