Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function auth_get() {
- $id_users = $this->get('id_users');
- if($id_users === NULL) {
- $auth = $this->distro->getAuth();
- } else {
- $auth = $this->distro->getAuth($id_users);
- }
- if($auth) {
- $this->response([
- "Status" => true,
- "Message" => "Berhasil Mendapatkan Data!",
- "Data" => $auth
- ],REST_Controller::HTTP_OK);
- } else {
- $this->response([
- "Status" => false,
- "Message" => "Data Users Gagal Dapatkan"
- ],REST_Controller::HTTP_BAD_REQUEST);
- }
- }
- public function userRegister_post(){
- $user_email = $this->post("email");
- $user_username = $this->post("username");
- $user_password = $this->post("password");
- $checkEmail = $this->distro->checkUserByEmail($user_email);
- if(count($checkEmail) == 0){
- $checkUsername = $this->distro->checkUserByUsername($user_username);
- if(count($checkUsername) == 0) {
- $user_data = [
- 'email' => $user_email,
- 'username' => $user_username,
- 'password' => password_hash(base64_encode($user_password), PASSWORD_DEFAULT),
- ];
- $createUser = $this->distro->createUser($user_data);
- if($createUser > 0){
- $this->response([
- "status" => TRUE,
- "code" => 200,
- "message" => "USER CREATED",
- "data" => $user_data
- ], REST_Controller::HTTP_CREATED);
- } else {
- $this->response([
- "status" => FALSE,
- "code" => 400,
- "message" => "FAILED TO CREATE USER"
- ], REST_Controller::HTTP_BAD_REQUEST);
- }
- } else {
- $this->response([
- "status" => FALSE,
- "code" => 400,
- "message" => "USERNAME HAS TAKEN"
- ], REST_Controller::HTTP_BAD_REQUEST);
- }
- } else {
- $this->response([
- "status" => FALSE,
- "code" => 400,
- "message" => "USER WITH EMAIL IS EXIST"
- ], REST_Controller::HTTP_BAD_REQUEST);
- }
- }
- public function user_delete() {
- $id_users = $this->delete('id_users');
- if($id_users === NULL) {
- $this->response([
- "status" => false,
- "message" => "Silahkan Masukkan Id User!"
- ],REST_Controller::HTTP_BAD_REQUEST);
- } else {
- if($this->distro->deleteUsers($id_users) > 0) {
- $this->response([
- "Status" => true,
- "Message" => "Data User Berhasil Dihapus!"
- ],REST_Controller::HTTP_NO_CONTENT);
- } else {
- $this->response([
- "status" => false,
- "Message" => "Gagal Menghapus Data User! Tidak Ada ID Yang Cocok!"
- ],REST_Controller::HTTP_BAD_REQUEST);
- }
- }
- }
- public function auth_post(){
- $user_email = $this->post('email');
- $user_password = password_hash(base64_encode($this->post('password')), PASSWORD_DEFAULT);
- $checkEmail = $this->distro->checkUserByEmail($user_email);
- if(count($checkEmail) > 0){
- $user = $checkEmail[0];
- $verify = password_verify(base64_encode($user_password), $user['password']);
- if($verify){
- $this->response([
- "status" => TRUE,
- "code" => 200,
- "message" => "Login Successfull!",
- "data" => $user
- ], REST_Controller::HTTP_OK);
- } else {
- $this->response([
- "status" => FALSE,
- "code" => 400,
- "message" => "Wrong Email/Password",
- "password" => $password
- ], REST_Controller::HTTP_BAD_REQUEST);
- }
- } else {
- $this->response([
- "status" => FALSE,
- "code" => 404,
- "message" => "Account not found!"
- ], REST_Controller::HTTP_NOT_FOUND);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement