<?php namespace App\Controller; use \App\Models\Auth; class AuthController { public function signup() { $uname = $_GET["username"]; $password = $_GET["password"]; $uname = sanitize_input($uname); $auth = new Auth(); if($auth -> user_name_is_exists($uname)) { return error_response("signup", "Username already exists"); } $user = $auth -> signup($uname, $password); if(!$user) { return error_response("signup", "Unknown error"); } return success_response([ "user_id" => $user -> get_id() ]); } public function signin() { $uname = $_GET["username"]; $password = $_GET["password"]; $uname = sanitize_input($uname); $auth = new Auth(); $session = $auth -> signin($uname, $password); if(!$session) { return error_response("signin", "Wrong username or password"); } return success_response([ "session" => [ "token" => $session -> token, "user" => [ "id" => $session -> user() -> get_id(), "name" => $session -> user() -> name ] ] ]); } public function signout() { $token = sanitize_input($_GET["token"]); $auth = new Auth(); if(!$auth -> signout($token)) { return error_response("signout", "Unknown error"); } return success_response(); } }