Advertisement
Guest User

Untitled

a guest
Feb 11th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.30 KB | None | 0 0
  1. package;
  2.  
  3. import hx.entity.db.Entities;
  4. import hx.entity.db.Entity;
  5. import rpc.RPC;
  6. import rpc.RPCHandler;
  7.  
  8. @:rpc(server)
  9. class ServerAPI extends RPCHandler implements RPC {
  10.     @:rpc public function isServerAlive():Bool {
  11.         return true;
  12.     }
  13.    
  14.     @:rpc public function signIn(username:String, password:String):Bool {
  15.         return performSignIn(username, password);
  16.     }
  17.    
  18.     @:rpc public function register(fullName:String, emailAddress:String, username:String, password:String):String {
  19.         var users = Entities.find({
  20.             properties: [
  21.                 "username" => username
  22.             ]
  23.         });
  24.         if (users.length != 0) {
  25.             return "Username already taken";
  26.         }
  27.        
  28.         var user = Entities.add();
  29.         user.property("fullName", fullName);
  30.         user.property("emailAddress", emailAddress);
  31.         user.property("username", username);
  32.         user.property("password", password);
  33.        
  34.         return null;
  35.     }
  36.    
  37.     private function performSignIn(username:String, password:String):Bool {
  38.         var users = Entities.find({
  39.             properties: [
  40.                 "username" => username,
  41.                 "password" => password
  42.             ]
  43.         });
  44.         return (users.length == 1);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement