Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. <template>
  2. <b-container>
  3. <h3>Login into Academics Management</h3>
  4. <b-form @submit.prevent="onSubmit" @reset="onReset">
  5. <b-form-group label="Username" description="Enter your username">
  6. <b-input name="username" placeholder="Your username" v-model.trim="username" required />
  7. </b-form-group>
  8. <b-form-group label="Password" description="Enter your password">
  9. <b-input
  10. name="password"
  11. type="password"
  12. placeholder="Your password"
  13. v-model="password"
  14. required
  15. />
  16. </b-form-group>
  17. <b-button type="reset" class="btn-warning">Reset</b-button>
  18. <b-button type="Submit" class="btn-success">Submit</b-button>
  19. </b-form>
  20. </b-container>
  21. </template>
  22. <script>
  23. export default {
  24. auth: false,
  25. data() {
  26. return {
  27. username: null,
  28. password: null
  29. };
  30. },
  31. methods: {
  32. onSubmit() {
  33. let promise = this.$auth.loginWith("local", {
  34. data: {
  35. username: this.username,
  36. password: this.password
  37. }
  38. });
  39. promise.then(() => {
  40. this.$toast.success("You are logged in!");
  41. // check if the user $auth.user object is set
  42. console.log(this.$auth.user);
  43. // TODO redirect based on the user role
  44. // eg:
  45. // if (this.$auth.user.groups.includes('Teacher')) {
  46. // this.$router.push('url-to-teacher-subjects')
  47. // } else if (...) {
  48. // ...
  49. // }
  50. });
  51. promise.catch(() => {
  52. this.$toast.error(
  53. "Sorry, you cant login. Ensure your credentials are correct"
  54. );
  55. });
  56. },
  57. onReset() {
  58. this.username = null;
  59. this.password = null;
  60. }
  61. }
  62. };
  63. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement