Beispiel #1
0
 /**
  *
  * @SWG\Api(
  *   path="/",
  *   description="API for user actions",
  * @SWG\Operation(
  *    method="POST",
  *    type="User",
  *    summary="Registers a new user.  If the post includes an invite id, it will try to validate that invite id against a team invitation and add them to the team.  Otherwise, it will create a new team for that user",
  * @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"
  *     ),
  * @SWG\Parameter(
  *     name="fullname",
  *     description="Name of the user",
  *     paramType="form",
  *     required=true,
  *     type="string"
  *     ),
  * @SWG\Parameter(
  *     name="email",
  *     description="Email address of the user",
  *     paramType="form",
  *     required=true,
  *     type="string"
  *     ),
  * @SWG\Parameter(
  *     name="timezone",
  *     description="Timezone of the user",
  *     paramType="form",
  *     required=false,
  *     type="string"
  *     ),
  * @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"
  *     )
  *   )
  * )
  */
 public function index_post()
 {
     $this->load->model(array('Team', 'Team_Invite', 'Project_Invite', 'Project'));
     $this->load->helper('notification');
     /* Validate add */
     $this->load->library('form_validation');
     $this->form_validation->set_rules('invite_id', 'Invite ID', 'trim|alpha_dash|xss_clean');
     $this->form_validation->set_rules('fullname', 'Full Name', 'trim|required|xss_clean');
     $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|xss_clean|is_unique[user.username]');
     $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[6]|xss_clean');
     $this->form_validation->set_rules('email', 'Email', 'trim|xss_clean|valid_email|required|is_unique[user.email]');
     if ($this->form_validation->run() == FALSE) {
         $data = array();
         if (form_error('email') && form_error('username')) {
             $data['level'] = USER_SIGNUP_ERROR_USERNAME_EMAIL_LEVEL;
         } else {
             if (form_error('email')) {
                 $data['level'] = USER_SIGNUP_ERROR_EMAIL_LEVEL;
             } else {
                 if (form_error('username')) {
                     $data['level'] = USER_SIGNUP_ERROR_USERNAME_LEVEL;
                 }
             }
         }
         json_error('There was a problem with your submission: ' . validation_errors(' ', ' '), $data);
     } else {
         $data = array('fullname' => $this->post('fullname', TRUE), 'username' => $this->post('username', TRUE), 'email' => $this->post('email', TRUE), 'password' => $this->post('password', TRUE));
         $team_id = 0;
         /* Get the invite if there is an invite key/invite type on the request */
         $invite = $this->validate_invite();
         $user_id = $this->User->add($data);
         $user = $this->User->load($user_id);
         $this->session->set_userdata(SESS_USER_ID, $user->id);
         /* If the invite is not null, we will process the invite and add the new user to the team/project */
         if ($invite) {
             $this->process_invite($invite, $user);
         } else {
             $team_id = $this->Team->add(array('owner_id' => $user_id, 'name' => $user->fullname . '\'s Team'));
         }
         /* Set the team on the session */
         if ($team_id) {
             $this->session->set_userdata(SESS_TEAM_ID, $team_id);
             $user->team_id = $team_id;
         }
         try {
             notify_new_user($user->id, $this->post('password', TRUE));
         } catch (Exception $e) {
             log_message('error', "Error while notifying new user: " . $e->getMessage());
         }
         $this->response($this->decorate_object($user));
     }
 }
Beispiel #2
0
if ($api['query']['osfapi_key'] == 'new') {
    $valid_key = true;
    create_osfapi_key();
} else {
    $valid_key = check_key($api['query']['osfapi_key']);
    if ($valid_key) {
        $api['output']['action'] = $api['query']['action'];
        switch ($api['query']['action']) {
            case 'update_visitor':
                update_visitor();
                break;
            case 'update_settings':
                update_settings();
                break;
            case 'notify_new_user':
                notify_new_user();
                break;
            case 'get_key_data':
                get_key_data();
                break;
            case 'delete_message':
                delete_message();
                break;
            case 'get_chat_history':
                get_chat_history();
                break;
            case 'get_messages':
                get_messages();
                break;
            case 'get_visitor':
                get_visitor();