public function add_user() { $this->common->authenticate(); $user_id = $this->input->post('user_id'); $table_id = $this->input->post('table_id'); $day = $this->input->post('day'); $message = $this->common->get_message('add_user', array('add_success', 'add_failure', 'have_table')); if (is_numeric($user_id) && is_numeric($table_id)) { $result = $this->tables_model->arrange_to_add_user_in_table($user_id, $table_id, $day); switch ($result) { case JOIN_TABLE_SUCCESSFULLY: $this->load->model('users_model'); $user = Users_model::get_user_by('id', $user_id); $data = array('status' => 'success', 'message' => $message['add_success'], 'user' => $user); break; case JOIN_TABLE_FAILED: $data = array('status' => 'failure', 'message' => $message['add_failure']); break; case HAVE_SEAT_IN_TABLE: $data = array('status' => 'failure', 'message' => $message['have_table']); break; } } else { $data = array('status' => 'failure', 'message' => $message['add_failure']); } echo json_encode($data); }
/** * User have read replies of comment * * @param int $user_id * @param int $comment_id * @param array $reply_ids * @return bool */ function have_read_replies_comment($user_id, $comment_id, $reply_ids) { $read_replies_for_comment = array(); $reply_ids_for_comments = array(); $read_replies_for_comment['comment'] = $comment_id; $read_replies_for_comment['replies'] = $reply_ids; $this->load->model('users_model'); $user = Users_model::get_user_by('id', $user_id); $reply_ids_for_comments = (array) json_decode($user->read_replies_comments); $reply_ids_for_comments[] = $read_replies_for_comment; $this->db->where('id', $user_id); return $this->db->update('users', array('read_replies_comments' => json_encode($reply_ids_for_comments))); }
/** * Change password of user * url: http://localhost/change_password * Method: PUT * @param int $int * @param string $current_password * @param string $new_password * @param string $confirm_new_password * @return json */ function change_password_put() { $this->authenticate(); $messages_lang = $this->common->set_language_for_server_api('users_api', array('change_password_success', 'change_password_failure', 'password_not_match')); $user_id = $this->put('user_id'); $current_password = $this->put('current_password'); $new_password = $this->put('new_password'); $confirm_new_password = $this->put('confirm_new_password'); $this->verify_required_params(array('user_id', 'current_password', 'new_password', 'confirm_new_password')); $response = array(); if ($new_password != $confirm_new_password) { $response['status'] = $messages_lang['failure']; $response['message'] = $messages_lang['password_not_match']; } else { $res = $this->users_model->change_password($user_id, $current_password, $new_password); if ($res == TRUE) { $result = Users_model::get_user_by('id', $user_id); $issue_at = time(); $user['authentication_token'] = $this->jwt->encode(array('iat' => $issue_at, 'nbf' => $issue_at + 10, 'exp' => $issue_at + 172800, 'email' => $result->email, 'tok' => $result->authentication_token, 'password' => $new_password), $this->config->item("secret_key")); $response['status'] = $messages_lang['success']; $response['message'] = $messages_lang['change_password_success']; $response['data'] = $user; } else { $response['status'] = $messages_lang['failure']; $response['message'] = $messages_lang['change_password_failure']; } } $this->response($response, 200); }
public function store_announcement() { $this->load->model('users_model'); $data['user_id'] = (int) $this->session->userdata('logged_in')['user_id']; $data['title'] = $this->input->post('subject'); $data['content'] = $this->input->post('content'); $data['meal_date'] = $this->input->post('lunch_date'); $announcement_for = $this->input->post('announcement_for'); $users = array(); switch ($announcement_for) { case ANNOUNCEMENT_USER: $data['user'] = $this->input->post('user'); $users[] = Users_model::get_user_by('id', $data['user']); break; case ANNOUNCEMENT_TABLE: $data['table'] = $this->input->post('table'); $this->load->model('tables_model'); $users = Tables_model::get_users_in_table($data['table']); break; case ANNOUNCEMENT_SHIFT: $data['shift'] = $this->input->post('shift'); $this->load->model('shifts_model'); $users = Shifts_model::get_users_by_shift($data['shift']); break; default: $data['user'] = '******'; $users = Users_model::get_all_users(); break; } list($result, $announcement_id) = Announcements_model::insert_announcement($data); if ($result) { $registation_ids = array(); if ($users != NULL) { foreach ($users as $user) { if ($user->gcm_regid != NULL) { $registation_ids[] = $user->gcm_regid; } } } $user = array(); $user['avatar_content_file'] = $this->session->userdata('logged_in')['avatar_content_file']; $user['email'] = $this->session->userdata('logged_in')['email']; $user['id'] = (int) $this->session->userdata('logged_in')['user_id']; if ($registation_ids != NULL) { $send_notification['data'] = array('type' => 'announcement', 'announcement' => array('id' => (int) $announcement_id, 'title' => $data['title'], 'content' => $data['content'], 'meal_date' => $data['meal_date'], 'read_flag' => FALSE, 'number_of_replies' => 0, 'number_of_have_read_replies' => 0, 'created_at' => date('Y-m-d H:i:s'), 'email' => $user['email'], 'avatar_content_file' => $user['avatar_content_file'], 'user_id' => $user['id'])); $this->common->send_notification($registation_ids, $send_notification); } return TRUE; } else { return FALSE; } }
public function load_edit_user_view($user_id) { $user = Users_model::get_user_by('id', $user_id); $image_data['file_name'] = $user->avatar_file_name; $this->session->set_userdata('upload', $image_data); $message = array('title', 'manage_users', 'email', 'password', 'confirm_password', 'what_taste', 'edit', 'want_vegan_meal', 'first_name', 'last_name', 'floor', 'shift', 'admin', 'user', 'role', 'image_upload', 'avatar', 'change_password', 'change_shift', 'yes', 'cancel'); $data = $this->common->set_language_and_data('edit_user', $message); $this->load->model('floors_model'); $data['floors'] = Floors_model::get_all_floors(); $this->load->model('shifts_model'); $data['shifts'] = Shifts_model::get_all_shifts(); $data['user'] = $user; $this->common->load_view('admin/users/edit_user', $data); }