소스 검색

Implements Dummy Register alogn with Login

Nikatlas 6 년 전
부모
커밋
9c0e5bc310
3개의 변경된 파일35개의 추가작업 그리고 1개의 파일을 삭제
  1. 9 0
      src/Game/services/UserService.js
  2. 25 0
      src/Game/views/demo/Login.js
  3. 1 1
      src/Game/views/misc/Button.js

+ 9 - 0
src/Game/services/UserService.js

@@ -8,6 +8,15 @@ class UserService {
         this.__load();
     }
 
+    register(username, password) {
+        let data = {
+            username,
+            password
+        };
+        return Net.post('users/register', data)
+            .then((res) => res.json());
+    }
+
     login(username, password) {
         let data = {
             username,

+ 25 - 0
src/Game/views/demo/Login.js

@@ -25,11 +25,16 @@ class Login extends PIXI.Container{
         let loginBtn = new Button({GameLayer, width: 100});
         this.addChild(loginBtn);
 
+        let registerBtn = new Button({GameLayer, width: 100});
+        this.addChild(registerBtn);
+
         // Set Properties
         emailText.setText("Username/Email");
         passwordText.setText("Password");
         loginBtn.setText("Login");
         loginBtn.scaleTo(0.75);
+        registerBtn.setText("Register");
+        registerBtn.scaleTo(0.5);
 
         // Position It
         emailText.position.set	(0, -150);
@@ -37,11 +42,13 @@ class Login extends PIXI.Container{
         passwordText.position.set(0,-50);
         password.position.set 	(0,0);
         loginBtn.position.set	(0,	100);
+        registerBtn.position.set(0,	220);
 
         // Events
         this.email = email;
         this.password = password;
         loginBtn.onClick((e) => this.login(e));
+        registerBtn.onClick((e) => this.register(e));
     }
 
     login() {
@@ -63,6 +70,24 @@ class Login extends PIXI.Container{
     	});
     }
 
+    register() {
+		let e = this.email.getValue();
+    	let p = this.password.getValue();
+
+    	// UserService Singleton to be called
+    	UserService.register(e,p)
+    	.then((data) => {
+            console.log(data);
+            this.login();
+            return true;
+    	})
+    	.catch((err) => {
+    		console.log(err);
+    		alert(JSON.stringify(err));
+    		//throw err;
+    	});
+    }
+
     onLogin = (fn) => {
     	this._onLogin = fn;
     }

+ 1 - 1
src/Game/views/misc/Button.js

@@ -66,7 +66,7 @@ class Button extends GuiableContainer{
 
     onClick(fn) {
         this.sprite.on('pointerdown', (e) => fn(e));
-        this.sprite.on('mouseup', (e) => fn(e));
+        //this.sprite.on('mouseup', (e) => fn(e));
         return this;
     }