Guest User

Untitled

a guest
May 6th, 2018
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.06 KB | None | 0 0
  1. <template>
  2. <div id="studentRegister" class="login_page fill-height">
  3. <v-container fluid fill-height>
  4. <v-layout align-center justify-center>
  5. <v-flex xs11 sm8 md5 lg4 xl3>
  6. <v-card>
  7. <v-progress-linear height="4" class="animated fadeIn" :indeterminate="true" color="orange" v-if="login"></v-progress-linear>
  8. <v-form @submit.stop.prevent="submit" class="animated fadeIn pa-3">
  9. <v-layout row wrap class="my-4 align-center">
  10. <v-flex class="xs3 align-content-start">
  11. <v-btn flat icon @click="$router.push('/')">
  12. <v-icon>arrow_back</v-icon>
  13. </v-btn>
  14. </v-flex>
  15. <v-flex class="xs9 align-start">
  16. <legend class="title">Welcome to IIB</legend>
  17. </v-flex>
  18. </v-layout>
  19. </v-form>
  20. </v-card>
  21. </v-flex>
  22. </v-layout>
  23. </v-container>
  24. <div v-if="!checkName">
  25. <v-form @submit.stop.prevent="submit">
  26. <legend>Welcome to IIB</legend><br>
  27. <div v-if="!checkName">
  28. <span class="redText" v-if="idCheck">Please check your Student ID.</span>
  29. <span class="greenText" v-if="idCheckCount">Fill in your ID.</span>
  30. <md-input-container md-theme="green">
  31. <md-icon>account_circle</md-icon>
  32. <label>Student Id</label>
  33. <md-input placeholder="Student Id" v-model="id" maxlength="6" type="number" required></md-input>
  34. </md-input-container>
  35. <span class="redText" v-if="dateCheckSpan">Please check your date.</span>
  36. <md-input-container md-theme="green">
  37. <md-icon>date_range</md-icon>
  38. <label>Date of Birth</label>
  39. <md-input maxlength="10" minlength="10" placeholder="DD/MM/YYYY" onkeyup="this.value=this.value.replace(/^(\d\d)()$/g,'$1/$2').replace(/^(\d\d\/\d\d)()$/g,'$1/$2').replace(/[^\d\/]/g,'')" v-model="dob" required></md-input>
  40. </md-input-container>
  41. <md-button class="md-raised md-primary " md-theme="green" type="submit">Register</md-button><br>
  42. </div>
  43. </v-form>
  44. </div>
  45. <form v-if="checkName" @submit.stop.prevent="submitUsernameAndPass">
  46. <div>
  47. <span class="md-body-1">Welcome</span>
  48. <span class="md-body-2 greenText"><br> {{ name }}</span><br>
  49. <md-input-container md-theme="green">
  50. <md-icon>&#xE8E8;
  51. <md-tooltip class="md-body-1">Choose a unique username.</md-tooltip>
  52. </md-icon>
  53. <label>Username</label>
  54. <md-input v-on:blur.native="checkUsername" placeholder="Username" minlength="4" v-model="username" required maxlength="15"></md-input>
  55. <md-icon md-theme="green" v-if="usernameCheck">&#xE877;</md-icon>
  56. </md-input-container>
  57. <span class="greenText" v-show="userNameCount">Atleast choose 4 characters.</span>
  58. <span class="redText" v-show="userNameTaken">This username is already taken. Please try another one</span>
  59. <span class="greenText" v-show="userNameAvailable">Username is available.</span>
  60. <md-input-container md-has-password md-theme="green" required>
  61. <label>Password</label>
  62. <md-icon md-theme="green" v-if="passMatch">&#xE877;</md-icon>
  63. <md-input placeholder="Password" type="password" v-model="password" required minlength="4"></md-input>
  64. </md-input-container>
  65. <span class="redText" v-show="passCount">Password must be atleast 4 character long.</span>
  66. <md-input-container md-theme="green">
  67. <label>Confirm Password</label>
  68. <md-icon md-theme="green" v-if="passMatch">&#xE877;</md-icon>
  69. <md-input placeholder="Confirm Password" v-model="passwordTwo" type="password" minlength="4"></md-input>
  70. </md-input-container>
  71. <span class="redText" v-show="passNotMatch">Password do not match.</span>
  72. <span class="greenText" v-show="passMatch">Password match. Now click on register.</span><br>
  73. <md-button class="md-primary md-raised" md-theme="green" type="submit">Register</md-button>
  74. </div>
  75. </form>
  76.  
  77. </div>
  78. </div>
  79. </div>
  80. </template>
  81.  
  82. <script>
  83. import axios from "axios";
  84. import moment from "moment";
  85.  
  86. export default {
  87. name: "studentRegister",
  88. data() {
  89. return {
  90. id: "",
  91. dob: "",
  92. name: "",
  93. username: "",
  94. password: "",
  95. passwordTwo: "",
  96. passCount: false,
  97. passMatch: false,
  98. passNotMatch: false,
  99. checkName: false,
  100. usernameCheck: false,
  101. idCheck: false,
  102. idCheckCount: false,
  103. dateCheckSpan: false,
  104. userNameTaken: false,
  105. userNameCount: false,
  106. userNameAvailable: false
  107. };
  108. },
  109. watch: {
  110. username: function() {
  111. this.username = this.username.replace(/\s+/g, "-").toLowerCase();
  112. if (this.username.length == 1 || this.username.length < 4) {
  113. this.userNameCount = true;
  114. this.userNameAvailable = false;
  115. } else {
  116. this.userNameCount = false;
  117. }
  118. },
  119. password: function() {
  120. if (
  121. this.password.length == 1 ||
  122. (this.password.length < 4 && this.password === this.passwordTwo)
  123. ) {
  124. this.passCount = true;
  125. this.passMatch = true;
  126. } else if (this.password.length > 1) {
  127. this.passCount = false;
  128. this.passMatch = false;
  129. this.passNotMatch = true;
  130. }
  131. },
  132. passwordTwo: function() {
  133. if (this.password === this.passwordTwo) {
  134. this.passMatch = true;
  135. this.passNotMatch = false;
  136. } else if (this.password !== this.passwordTwo) {
  137. this.passMatch = false;
  138. this.passNotMatch = true;
  139. } else {
  140. this.passMatch = false;
  141. this.passNotMatch = false;
  142. }
  143. },
  144. dob: function() {
  145. if (this.dob.length > 9) {
  146. let dateCheck = moment(this.dob, "DD/MM/YYYY", true).isValid();
  147. if (dateCheck == false) {
  148. this.dateCheckSpan = true;
  149. } else {
  150. this.dateCheckSpan = false;
  151. }
  152. }
  153. },
  154. id: function() {
  155. if (this.id.length > 0 && this.id.length < 5) {
  156. this.idCheckCount = true;
  157. this.idcheck = false;
  158. } else if (this.id.length > 6) {
  159. this.idCheckCount = false;
  160. this.idCheck = true;
  161. } else if (this.id.length == 6) {
  162. this.idCheckCount = false;
  163. this.idCheck = false;
  164. }
  165. }
  166. },
  167. methods: {
  168. submit() {
  169. const self = this;
  170. if (this.dateCheckSpan == true) {
  171. this.swalDateCheck();
  172. } else if (this.idCheck == true || this.idCheckCount == true) {
  173. this.swalIdCheck();
  174. } else {
  175. axios
  176. .post("http://localhost:3000/student/getname", {
  177. id: this.id,
  178. dob: this.dob
  179. })
  180. .then(response => {
  181. if (response.data.success) {
  182. self.checkName = true;
  183. self.name = response.data.name;
  184. } else {
  185. self.swalWrongIdOrDob();
  186. this.id = " ";
  187. this.dob = "";
  188. }
  189. })
  190. .catch(error => self.swalSE());
  191. }
  192. },
  193. checkUsername() {
  194. const self = this;
  195. let usernameLength = this.username.length;
  196. if (usernameLength > 3) {
  197. axios
  198. .post("http://localhost:3000/student/checkusername", {
  199. username: this.username
  200. })
  201. .then(response => {
  202. let usernameCheckResponse = response.data.success;
  203. if (usernameCheckResponse == true) {
  204. self.usernameCheck = false;
  205. self.userNameTaken = true;
  206. self.userNameAvailable = false;
  207. } else if (usernameCheckResponse == false) {
  208. self.usernameCheck = true;
  209. self.userNameAvailable = true;
  210. self.userNameTaken = false;
  211. }
  212. })
  213. .catch(error => console.log(error));
  214. }
  215. },
  216. submitUsernameAndPass() {
  217. const self = this;
  218. if (
  219. this.passMatch == true &&
  220. this.usernameCheck == true &&
  221. this.userNameTaken == false &&
  222. this.userNameAvailable == true
  223. ) {
  224. axios
  225. .post("http://localhost:3000/student/saveusernameandpassword", {
  226. id: this.id,
  227. username: this.username,
  228. password: this.password
  229. })
  230. .then(response => {
  231. if (response.data.success) {
  232. self.swalS();
  233. self.$router.push("/login");
  234. } else {
  235. self.swalE();
  236. }
  237. })
  238. .catch(error => console.log(error));
  239. } else if (this.userNameAvailable == false) {
  240. this.swalUsername();
  241. } else if (this.passMatch == false) {
  242. this.swalPassword();
  243. }
  244. },
  245. swalS() {
  246. this.$swal("Hurray...", "You can now log in!!!", "success");
  247. },
  248. swalE() {
  249. this.$swal(
  250. "Sorry...",
  251. "But something was wrong with your data.",
  252. "error"
  253. );
  254. },
  255. swalSE() {
  256. this.$swal(
  257. "Server not responding",
  258. "Looks like server is not responding. Please call on +91 7030616809",
  259. "error"
  260. );
  261. },
  262. swalUsername() {
  263. this.$swal(
  264. "Sorry...",
  265. "Looks like Somebody else got that name. Please use another username.",
  266. "info"
  267. );
  268. },
  269. swalPassword() {
  270. this.$swal("Sorry...", "Your password do not match.", "info");
  271. },
  272. swalWrongIdOrDob() {
  273. this.$swal(
  274. "Sorry...",
  275. "Looks like you have already registered or your Student ID and DOB don't match.",
  276. "info"
  277. );
  278. },
  279. swalDateCheck() {
  280. this.$swal(
  281. "Date...",
  282. "Your date don't match with our Calendar.",
  283. "error"
  284. );
  285. },
  286. swalIdCheck() {
  287. this.$swal(
  288. "Student ID...",
  289. "Looks like there is a problem with your ID.",
  290. "info"
  291. );
  292. }
  293. }
  294. };
  295. </script>
Add Comment
Please, Sign In to add comment