Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.30 KB | None | 0 0
  1. /**
  2. * First we will load all of this project's JavaScript dependencies which
  3. * includes Vue and other libraries. It is a great starting point when
  4. * building robust, powerful web applications using Vue and Laravel.
  5. */
  6.  
  7. require('./bootstrap');
  8.  
  9.  
  10. window.Vue = require('vue');
  11.  
  12. const app = new Vue({
  13. el: '#app',
  14. data: {
  15. title: 'Login',
  16. titleAdmin: 'Settings',
  17. editingUser: false,
  18. showSuccess: false,
  19. loginFailed: false,
  20. accountCreated: false,
  21. registerSuccessMessage: "Account successfully created! Please confirm your account to login.",
  22. loginFailureMessage: "",
  23. /*gameCreateSubmitted: false,
  24. gameCreateMessage: "",
  25. gameCreateAlert: null,
  26. userToken: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9qb2dvRGFNZW1vcmlhLmRldiIsImRhdGEiOnsidXNySWQiOjEsInVzck5hbWUiOiJhZG1pbiJ9fQ.6p9zbLWriXJ30QljZ0jDQj_BWMwaj6g5frqjvlG8S8s",
  27. newGame: {},
  28. games: [],
  29. myGames: [],
  30. selectedGameType: null*/
  31. userToken: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9qb2dvRGFNZW1vcmlhLmRldiIsImRhdGEiOnsidXNySWQiOjEsInVzck5hbWUiOiJhZG1pbiJ9fQ.6p9zbLWriXJ30QljZ0jDQj_BWMwaj6g5frqjvlG8S8s",
  32.  
  33. loginSubmitted: false,
  34. loginCreateAlert: null,
  35. loginCreateMessage: "",
  36. emailLogin: "",
  37. passwordLogin: "",
  38. loginPage: true,
  39. registerPage: false,
  40. nameRegister: "",
  41. nicknameRegister: "",
  42. emailRegister: "",
  43. passwordRegister: "",
  44. passwordConfirmationRegister: "",
  45. passwordRecoveryPage: false,
  46. loginAdminPage: true,
  47. passwordRecovery: false,
  48. passwordRecoveryMessage: "",
  49. users: [],
  50. reason_blocked: "",
  51. currentUserId: 0,
  52. blockingUser: false
  53. },
  54. methods: {
  55. login: function () {
  56. this.loginSubmitted = true;
  57.  
  58. if(this.emailLogin === "" && this.passwordLogin === "") {
  59. this.loginFailureMessage = "Username or password invalid";
  60. this.loginFailed = true;
  61. this.loginCreateAlert = {
  62. "alert": true,
  63. "alert-warning": true
  64. };
  65. return;
  66. }
  67.  
  68. var config = {
  69. headers: {
  70. "Accept": "application/json",
  71. "Content-Type": "application/json"
  72. }
  73. };
  74.  
  75. axios.post('api/login', {"email": this.emailLogin, "password": this.passwordLogin}, config)
  76. .then(response => {console.log("Success");
  77. this.userToken = response.data.data.api_token;
  78. this.loginPage = false;} );
  79.  
  80.  
  81. },
  82. openRegister: function () {
  83. this.registerPage = true;
  84. this.loginPage = false;
  85.  
  86. },
  87. register: function () {
  88. var config = {
  89. headers: {
  90. "Accept": "application/json",
  91. "Content-Type": "application/json"
  92. }
  93. };
  94.  
  95. axios.post('api/register', {"name": this.nameRegister,
  96. "nickname": this.nicknameRegister,
  97. "email": this.emailRegister,
  98. "password": this.passwordRegister,
  99. "password_confirmation": this.passwordConfirmationRegister}, config)
  100. .then(response => {console.log("Success");
  101. this.registerPage = false;
  102. this.loginPage = true;
  103. this.accountCreated = true;});
  104. },
  105. cancel: function () {
  106. this.loginPage = true;
  107. this.registerPage = false;
  108. },
  109. resetAdminPassword: function () {
  110. var config = {
  111. headers: {
  112. "Accept": "application/json",
  113. "Content-Type": "application/json"
  114. }
  115. };
  116.  
  117.  
  118.  
  119. axios.post('api/resetAdminPassword', config)
  120. .then(response => {console.log("Success");
  121. this.passwordRecovery = true;
  122. this.passwordRecoveryMessage = "Please check your email to recover your password";
  123. this.loginAdminPage = true;});
  124. },
  125. blockUser: function (id) {
  126. this.currentUserId = id;
  127. this.blockingUser = true;
  128. },
  129. block: function () {
  130. var config = {
  131. headers: {
  132. "Authorization": "Bearer " + this.userToken,
  133. "Accept": "application/json",
  134. "Content-Type": "application/json"
  135. }
  136. };
  137. axios.put('api/block/' + this.currentUserId, {'reason_blocked': this.reason_blocked},config)
  138. .then(response => {console.log("Success");
  139. this.blockingUser = false;});
  140. }
  141. /*------GAME LOBBY------createGame: function () {
  142. this.gameCreateSubmitted = true;
  143.  
  144. if(this.selectedGameType === null){
  145. this.gameCreateMessage = "Game type not selected";
  146. this.gameCreateAlert = {
  147. "alert": true,
  148. "alert-warning": true
  149. };
  150. return;
  151. }
  152. this.gameCreateMessage = "Game created";
  153. this.gameCreateAlert = {
  154. "alert": true,
  155. "alert-success": true
  156. };
  157.  
  158. var config = {
  159. headers: {
  160. "Authorization": "Bearer " + this.userToken,
  161. "Accept": "application/json",
  162. "Content-Type": "application/json"
  163. }
  164. };
  165. axios.post('api/game', {"type": this.selectedGameType}, config)
  166. .then(response => {console.log("Success");} );
  167.  
  168. config = {
  169. headers: {"Authorization": "Bearer " + this.userToken}
  170. };
  171. axios.get('api/game/pending', config)
  172. .then(response => {this.games = response.data.games;} );
  173. },
  174. joinGame: function (game_id) {
  175. var config = {
  176. headers: {
  177. "Authorization": "Bearer " + this.userToken,
  178. "Accept": "application/json",
  179. "Content-Type": "application/json"
  180. }
  181. };
  182. axios.put('api/game/' + game_id, null, config)
  183. .then(response => {
  184. console.log("Success");
  185. config = {
  186. headers: {"Authorization": "Bearer " + this.userToken}
  187. };
  188. axios.get('api/game/pending', config)
  189. .then(response => {this.games = response.data.games;} );
  190. } );
  191. },
  192. beginGame: function (game_id) {
  193. var config = {
  194. headers: {
  195. "Authorization": "Bearer " + this.userToken,
  196. "Accept": "application/json",
  197. "Content-Type": "application/json"
  198. }
  199. };
  200. axios.put('api/game/begin/' + game_id, null, config)
  201. .then(response => {
  202. console.log("Success");
  203. config = {
  204. headers: {"Authorization": "Bearer " + this.userToken}
  205. };
  206. axios.get('api/game/pending', config)
  207. .then(response => {this.myGames = response.data.games;} );
  208. } );
  209. }
  210. /*
  211. ,
  212. cancelGame: function (game_id) {
  213. var config = {
  214. headers: {
  215. "Authorization": "Bearer " + this.userToken,
  216. "Accept": "application/json",
  217. "Content-Type": "application/json"
  218. }
  219. };
  220. axios.put('api/game/cancel/' + game_id, null, config)
  221. .then(response => {
  222. console.log("Success");
  223. config = {
  224. headers: {"Authorization": "Bearer " + this.userToken}
  225. };
  226. axios.get('api/game/my', config)
  227. .then(response => {this.myGames = response.data.games;} );
  228. } );
  229. }
  230. */
  231. },
  232. mounted() {
  233. config = {
  234. headers: {"Authorization": "Bearer " + this.userToken}
  235. };
  236. axios.get('api/usersIndex')
  237. .then(response=>{
  238. this.users = response.data.data;} );
  239. /*-----LOBBY------var config = {
  240. headers: {"Authorization": "Bearer " + this.userToken}
  241. };
  242. axios.get('api/game/pending', config)
  243. .then(response => {this.games = response.data.games;} );*/
  244.  
  245. /*
  246. config = {
  247. headers: {"Authorization": "Bearer " + this.userToken}
  248. };
  249. axios.get('api/game/my', config)
  250. .then(response => {this.myGames = response.data.games;} );
  251. */
  252. }
  253. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement