Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <template>
- <div class="container">
- <div class="row justify-content-center">
- <div class="col-md-6">
- <div class="card">
- <div class="card-header">Login</div>
- <div class="card-body">
- <form @submit.prevent="login">
- <p v-if="errors.length">
- <b>Please correct the following error(s):</b>
- <ul>
- <li v-for="error in errors">{{ error }}</li>
- </ul>
- </p>
- <div class="form-group">
- <label for="username">Email ID</label>
- <input type="email" class="form-control" name="username" id="username" v-model="email" required>
- </div>
- <div class="form-group">
- <label for="password">Password</label>
- <input type="password" class="form-control" name="password" id="password" v-model="password" required>
- </div>
- <div class="form-group">
- <router-link to="/auth/reset" class="btn btn-link">
- <i class="fas fa-info-circle"></i> Forgot Your Password?
- </router-link>
- </div>
- <button type="submit" class="btn btn-primary">Login</button>
- </form>
- </div>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script>
- export default {
- data () {
- return {
- errors: [],
- email: '',
- password: '',
- }
- },
- methods: {
- login: function () {
- this.errors = [];
- if (this.emailValidate(this.email) && this.passValidate(this.password)) {
- this.errors = [];
- axios.post(api_url + '/auth/login', {
- 'username': this.email,
- 'password': this.password,
- })
- .then((res) => {
- console.log(res.status);
- if (res.status) {
- alert('test status');
- }
- })
- .catch((err) => console.error(err));
- }
- },
- emailValidate: function (email) {
- var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
- var emailCheck = re.test(String(email).toLowerCase());
- console.log(emailCheck);
- if (!emailCheck || emailCheck === '') {
- this.errors.push("Invalid Email.");
- return false;
- }
- return true;
- },
- passValidate: function (password) {
- if (password.length < 6) {
- this.errors.push("Invalid Password.");
- return false;
- }
- return true;
- }
- }
- }
- </script>
Add Comment
Please, Sign In to add comment