Added custom notification

This commit is contained in:
2017-10-26 14:59:49 +07:00
parent bc21934274
commit a106344dc8
15 changed files with 238 additions and 103 deletions

View File

@@ -43,7 +43,9 @@ class Api
}
}
if ($table == 'kategori') {
$get['count'] = count($get['data']);
if ($table == 'kategori' && $get['count'] != 0) {
if (isset($get['data'][0])) {
for ($i=0; $i < count($get['data']); $i++) {
$get['data'][$i]['posts'] = count(\App\Models\Pengumuman::showAll('pengumuman', [
@@ -58,8 +60,7 @@ class Api
]));
}
}
$get['count'] = count($get['data']);
header('Content-Type: application/json');
echo json_encode($get);
@@ -82,6 +83,7 @@ class Api
$put['status'] = true;
$put['data'] = $update;
$put['count'] = count($put['data']);
$put['message'] = ucfirst($table) . ' berhasil diubah';
}
header('Content-Type: application/json');
@@ -105,6 +107,7 @@ class Api
$post['status'] = true;
$post['data'] = $entry;
$post['count'] = count($post['data']);
$post['message'] = ucfirst($table) . ' berhasil ditambahkan';
}
header('Content-Type: application/json');

View File

@@ -39,14 +39,19 @@ class Home
$password = $args['password'];
$user = Access::showAll([
['username', '=', $username],
['flag', '=', 0]
['username', '=', $username]
]);
if ($user == false) {
$info = "Username/password salah";
$logged_in['status'] = $info;
$logged_in['status'] = false;
$logged_in['message'] = $info;
} else {
if ($user['flag'] != 0) {
$info = "User telah login";
$logged_in['status'] = false;
$logged_in['message'] = $info;
}
$hash = Hash::compare($password, $user['salt'], $user['password']);
if ($hash == true) {
@@ -66,11 +71,12 @@ class Home
$info = "Berhasil masuk";
$logged_in['status'] = true;
$logged_in['redirect_to'] = '/?s='.$session['id']."&u=".$session['uid'];
$logged_in['message'] = 'Berhasil login';
}
}
} else {
$info = "Username/password salah";
$logged_in['status'] = $info;
$logged_in['message'] = $info;
}
}
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
@@ -101,16 +107,18 @@ class Home
$info = "Berhasil keluar";
$logged_out['status'] = true;
$logged_out['redirect_to'] = '/';
$logged_out['redirect_to'] = '';
$logged_out['message'] = 'Berhasil logout';
} catch (\Exception $e) {
$logged_out['status'] = $e->getMessage();
$logged_out['status'] = false;
$logged_out['message'] = $e->getMessage();
}
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($logged_out);die();
}
// Session::flash('info', $info);
// Redirect::to('/');
Session::flash('info', $info);
Redirect::to('/');
}
public function register()
@@ -131,7 +139,7 @@ class Home
foreach ($args as $value) {
if ($value == '') {
$info = 'Semua data harus diisi';
$registered['status'] = 'false';
$registered['status'] = false;
$registered['message'] = $info;
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($registered);die();
@@ -183,7 +191,8 @@ class Home
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode([
'status' => true,
'route_to' => ''
'route_to' => '',
'message' => 'User berhasil ditambahkan'
]);die();
}
Session::flash('info', 'Registrasi berhasil');

View File

@@ -338,6 +338,7 @@ class Posts
}
$post['status'] = true;
$post['route_to'] = '';
$post['message'] = 'Pengumuman berhasil ditambahkan';
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($post);
die();
@@ -350,6 +351,7 @@ class Posts
public function put($args)
{
// echo json_encode($args); die();
$update = [];
if (isset($args['_addon'])) {
@@ -413,6 +415,7 @@ class Posts
if ($this->model->update($args, $id)) {
$update['status'] = true;
$update['route_to'] = '';
$update['message'] = 'Pengumuman berhasil diubah';
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
echo json_encode($update);
die();