Пример #1
0
 function get_for_user_date($user_id = 0, $date = '')
 {
     $sql = "SELECT m.* from " . $this->get_scope() . " m, meeting_user mu where m.id = mu.meeting_id and " . " mu.user_id = ? and m.deleted = 0 and m.ended IS NULL";
     $query_params = array(intval($user_id));
     if ($date) {
         $sql .= " AND m.date >= ? AND m.date <= ?";
         $query_params[] = $date;
         $query_params[] = timestamp_to_mysqldatetime(add_day(1, $date));
     } else {
         $sql .= " AND m.date >= ?";
         $query_params[] = timestamp_to_mysqldatetime(now());
     }
     $sql .= " ORDER by m.date ASC, m.time ASC";
     $query = $this->db->query($sql, $query_params);
     //echo $this->db->last_query();
     return $query->result();
 }
Пример #2
0
/**
 * Validates that a user can invite/add users to their projects
 * @param $user_id
 */
function validate_user_add($user_id, $invitee_uuid = '')
{
    $CI =& get_instance();
    $CI->load->model(array('Team', 'Subscription', 'Project', 'Plan'));
    $subscription = $CI->Subscription->load_by_field('user_id', $user_id);
    $user = $CI->User->load_fields($user_id, 'created');
    if ($subscription) {
        $plan = $CI->Plan->load($subscription->plan_id);
        $users = $CI->User->get_for_teams_owner($user_id);
        /** All the user to be invited to projects if they are already on the team */
        if ($invitee_uuid) {
            foreach ($users as $user) {
                if ($invitee_uuid === $user->uuid) {
                    return true;
                }
            }
        }
        $max_users = $plan->team_members + $subscription->additional_users;
        if (sizeof($users) >= $max_users) {
            if ($user_id == get_user_id()) {
                json_error(sprintf('You cannot invite any more users to your team.  Your plan allows you to invite up to %d users.', $max_users), null, 403);
            } else {
                json_error('You cannot accept this invite since the team owner does not have room for any more users on their plan.', null, 403);
            }
            exit;
        }
    } else {
        $expiration = add_day(FREE_TRIAL_LENGTH, $user->created);
        if ($expiration < now()) {
            json_error('Free Trial Expired', null, 402);
            exit;
        } else {
            $users = $CI->User->get_for_teams_owner($user_id);
            //array_print($users);
            if (sizeof($users) >= FREE_TRIAL_USERS) {
                if ($user_id == get_user_id()) {
                    json_error('You cannot invite any more users during your free trial.', null, 402);
                } else {
                    json_error('You cannot accept this invite since the team owner does not have room for any more users on their plan.', null, 403);
                }
                exit;
            }
        }
    }
}
Пример #3
0
 function sum_field_date($field = '', $days = 30)
 {
     $min_date = timestamp_to_mysqldate(add_day(-1 * $days));
     $this->db->where('created >=', $min_date);
     $this->db->select_sum($field);
     $query = $this->db->get($this->get_scope());
     $row = $query->row();
     return $row->{$field};
 }
Пример #4
0
 /**
  *
  * @SWG\Api(
  *   path="/login",
  *   description="API for user actions",
  * @SWG\Operation(
  *    method="POST",
  *    type="User",
  *    summary="Logs in a user",
  * @SWG\Parameter(
  *     name="username",
  *     description="Username of the user (Should be at least five characters long)",
  *     paramType="form",
  *     required=true,
  *     type="string"
  *     ),
  * @SWG\Parameter(
  *     name="password",
  *     description="Password of the user (Should be at least six characters long)",
  *     paramType="form",
  *     required=true,
  *     type="string"
  *     ),
  * @SWG\Parameter(
  *     name="invite_key",
  *     description="The invite key that the user is using to join a team",
  *     paramType="form",
  *     required=false,
  *     type="string"
  *     ),
  * @SWG\Parameter(
  *     name="invite_type",
  *     description="The invite type that the user is using (either 'team' or 'project')",
  *     paramType="form",
  *     required=false,
  *     type="string"
  *     )
  *   )
  * )
  */
 public function login_post()
 {
     $this->load->model(array('Team', 'Team_Invite', 'Project_Invite', 'Project', 'Subscription'));
     $this->load->library('form_validation');
     $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|xss_clean');
     $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[6]|xss_clean');
     $this->form_validation->set_rules('invite_key', 'Invite Key', 'trim|xss_clean');
     $this->form_validation->set_rules('invite_type', 'Invite Type', 'trim|xss_clean|callback_validate_invite_type');
     if ($this->form_validation->run() == FALSE) {
         json_error('There was a problem with your submission: ' . validation_errors(' ', ' '));
         exit;
     } else {
         $username = $this->post('username', TRUE);
         $password = $this->post('password', TRUE);
         $user = $this->User->login($username, $password);
         if ($user && $user->id) {
             session_clear();
             $invite = $this->validate_invite($user);
             if ($invite) {
                 $this->process_invite($invite, $user);
             }
             $this->session->set_userdata(SESS_USER_ID, $user->id);
             $team = $this->Team->get_active_for_user($user->id);
             if ($team) {
                 $this->session->set_userdata(SESS_TEAM_ID, $team->id);
             }
             $subscription = $this->Subscription->load_by_field('user_id', $user->id);
             if ($subscription && !$subscription->failed) {
                 $this->session->set_userdata(SESS_SUBSCRIPTION_ID, $subscription->id);
             }
             log_message('info', 'Login - User ID: ' . $user->id . ', Username: '******'The username/password you have entered are invalid.');
 }