Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- import hx.entity.db.Entities;
- import hx.entity.db.Entity;
- import rpc.RPC;
- import rpc.RPCHandler;
- @:rpc(server)
- class ServerAPI extends RPCHandler implements RPC {
- @:rpc public function isServerAlive():Bool {
- return true;
- }
- @:rpc public function signIn(username:String, password:String):Bool {
- return performSignIn(username, password);
- }
- @:rpc public function register(fullName:String, emailAddress:String, username:String, password:String):String {
- var users = Entities.find({
- properties: [
- "username" => username
- ]
- });
- if (users.length != 0) {
- return "Username already taken";
- }
- var user = Entities.add();
- user.property("fullName", fullName);
- user.property("emailAddress", emailAddress);
- user.property("username", username);
- user.property("password", password);
- return null;
- }
- private function performSignIn(username:String, password:String):Bool {
- var users = Entities.find({
- properties: [
- "username" => username,
- "password" => password
- ]
- });
- return (users.length == 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement