All files / ui/src/views SignUp.vue

12.5% Statements 3/24
0% Branches 0/6
0% Functions 0/2
13.64% Lines 3/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170                                                                                                      3x 3x   3x                                                                                                                                                                                                                                      
<template>
  <div class="container text-center">
    <div class="card mx-auto">
      <div class="card-header">
        <span>SIGN UP</span>
      </div>
      <form @submit.prevent="submit">
        <div class="form-group">
          <label for="username">Username</label>
          <input
            v-model="userName"
            type="text"
            class="form-control"
            id="username"
            placeholder="Username"
            required
          />
        </div>
        <div class="form-group">
          <label for="email">Email ID</label>
          <input
            v-model="email"
            type="email"
            class="form-control"
            id="email"
            aria-describedby="emailHelp"
            placeholder="Email ID"
            required
          />
          <small id="emailHelp" class="form-text text-muted"
            >We'll never share your email with anyone else.</small
          >
        </div>
        <div class="form-group">
          <label for="password">Password</label>
          <input
            v-model="password"
            type="password"
            class="form-control"
            id="password"
            placeholder="Password"
            required
          />
        </div>
        <button class="button" type="submit">Sign Up</button>
      </form>
    </div>
  </div>
</template>
 
<script>
import UserService from "../UserService";
import router from "@/router";
 
export default {
  name: "SignUp",
  data() {
    return {
      userName: "",
      email: "",
      password: "",
    };
  },
  methods: {
    /**
     * @vuese
     * Sends the new user credentials to the data and registers the user.
     */
    async submit() {
      console.log("signed");
      let users = null;
      let duplicate = false;
 
      try {
        users = await UserService.getUsers();
        users = users.data;
        console.log(users);
      } catch (err) {
        window.alert(err);
      }
 
      console.log(users.length);
 
      for (let i = 0; i < users.length; i++) {
        console.log("username and email", users[i].userName);
        if (
          users[i].userName == this.userName ||
          users[i].email == this.email
        ) {
          duplicate = true;
          break;
        }
      }
 
      if (duplicate) window.alert("Username or Email already taken");
      else {
        await UserService.postUser(this.userName, this.email, this.password);
        window.alert("Account Created! Login to Continue.");
        router.push("/login");
      }
    },
  },
};
</script>
 
<style scoped>
.card {
  width: 26rem;
  height: 35rem;
  font-weight: bold;
  font-size: 0.9rem;
  padding: 0.5rem;
  margin-bottom: 2rem;
  border: none;
  outline: none;
  border-radius: 22px;
  background-color: #e0e5ec;
  box-shadow: 9px 9px 16px rgb(163, 177, 198, 0.6),
    -9px -9px 16px rgba(255, 255, 255, 0.5);
}
 
.card-header {
  font-weight: 100;
  font-family: Luminari, fantasy;
  font-size: 1.8rem;
  border: none;
  outline: none;
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  background-color: #e0e5ec;
  margin: 2rem 0rem;
}
 
.form-control {
  width: 25rem;
  height: max-content;
  font-weight: bold;
  padding: 1rem;
  font-size: 1.1rem;
  border: none;
  outline: none;
  border-radius: 22px;
  background-color: #e0e5ec;
  box-shadow: inset 9px 9px 16px rgb(163, 177, 198, 0.6),
    inset -9px -9px 16px rgba(255, 255, 255, 0.5);
  transition: box-shadow 500ms;
}
 
.button {
  width: 25rem;
  font-weight: bold;
  padding: 1rem;
  font-size: 1.1rem;
  margin: 1rem 0rem;
  border: none;
  outline: none;
  color: #007bff;
  border-radius: 22px;
  background-color: #e0e5ec;
  box-shadow: 9px 9px 16px rgb(163, 177, 198, 0.6),
    -9px -9px 16px rgba(255, 255, 255, 0.5);
  transition: box-shadow 500ms;
}
 
.button:hover {
  box-shadow: inset 9px 9px 16px rgb(163, 177, 198, 0.6),
    inset -9px -9px 16px rgba(255, 255, 255, 0.5);
}
</style>