<commit_before><?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

if(Session::has('lang')){
    //Set the language
    App::setLocale(Session::get('lang'));
}

Route::get('/', [
    'as'   => 'landing',
    'uses' => 'HomeController@showWelcome'
]);

// About page
Route::get('about', ['as' => 'about', 'before' => 'auth', function() {
    return View::make('about');
}]);

// Info page
Route::get('help', ['as' => 'help', 'before' => 'auth', function() {
  return View::make('help');
}]);

Route::group(['prefix' => 'orgs'], function () {
    // List all organisations (for editing)
    Route::get('/', [
        'as' => 'orgs.index',
        function() {
            return View::make('orgs/index');
        }
    ]);
});

Route::group(['prefix' => 'school'], function () {
    // Create a new school
    Route::post('/register', [
        'as' => 'school.store',
        'uses' => 'SchoolController@store'
    ]);

    // List all schools
    Route::get('/', [
        'as'   => 'school.index',
        'uses' => 'SchoolController@index',
        'before' => 'admin'
    ]);

    // Show details of a certain school
    Route::get('/{id}', [
        'as'   => 'school.detail',
        'uses' => 'SchoolController@show',
        'before' => 'admin'
    ])->where('id', '[0-9]+');

    // Show the view to edit a school
    Route::get('/edit/{id}', [
        'as'   => 'school.edit',
        'uses' => 'SchoolController@edit'
    ])->where('id', '[0-9]+');

    // Update a school
    Route::post('/edit/{id}', [
        'as'   => 'school.update',
        'uses' => 'SchoolController@update',
        'before' => 'admin'
    ])->where('id', '[0-9]+');

    // Delete a school
    Route::get('/delete/{id}', [
        'as'   => 'school.delete',
        'uses' => 'SchoolController@destroy',
        'before' => 'admin'
    ])->where('id', '[0-9]+');
});


Route::group(['prefix' => 'profile'], function () {
    /*
      // Show list of users for a school
      Route::get('/', [
          'as' => 'user.index',
          'uses' => 'UserController@index'
      ]);
  */

    // Log user out TODO: post?
    Route::get('/logout', [
        'as'   => 'user.logout',
        'uses' => 'UserController@logout'
    ]);

    // Show the view to edit a user
    Route::get('/{id?}', [
        'as' => 'user.edit',
        'uses' => 'UserController@editUser'
    ])->where('id', '[0-9]+');

    // Add user to group
    Route::post('/{id}/roles', [
        'as' => 'user.addAdminRole',
        'uses' => 'UserController@promoteUserAdmin'
    ])->where('id', '[0-9]+');

    // Remover a user from group
    Route::delete('/{id}/roles', [
        'as' => 'user.removeAdminRole',
        'uses' => 'UserController@demoteUserAdmin'
    ])->where('id', '[0-9]+');

    // Update a user
    Route::post('/{id}', [
        'as'   => 'user.update',
        'uses' => 'UserController@updateUser'
    ])->where('id', '[0-9]+');

    // Register as a new user
    Route::post('/register', [
        'as' => 'user.register',
        'uses' => 'UserController@store'
    ]);

    // Create a new user (backoffice side)
    Route::post('/create', [
        'as' => 'user.create',
        'uses' => 'UserController@create'
    ]);

    // Authenticate user
    Route::post('/auth', [
        'as' => 'user.auth',
        'uses' => 'UserController@auth'
    ]);

    // Destroy a user
    Route::delete('/{id}', [
        'as'   => 'user.removeUserFromSchool',
        'uses' => 'UserController@removeUserFromSchool'
    ])->where('id', '[0-9]+');

    // GET: Reset the user's password with a hash received by mail
    Route::get('/reset/{hash}', [
        'as' => 'user.resetPassword',
        'uses' => 'UserController@resetPassword',
    ])->where([
        'hash' => '[a-zA-Z0-9]+'
    ]);

    // POST: send an email with the reset link
    Route::any('/sendReset/{mail}', [
        'as' => 'user.sendResetLink',
        'uses' => 'UserController@sendResetLink'
    ]);

    // POST: Reset the user's password
    // GET: Reset the user's password
    Route::any('/reset/{hash}', [
        'as' => 'user.resetPassword',
        'uses' => 'UserController@resetPassword',
    ])->where([
        'hash' => '[a-zA-Z0-9]+'
    ]);

});


Route::group(['prefix' => 'api/1'], function () {


    // Returns all events for the users organisation
    Route::get('/orgs', [
        'as' => 'api.schools',
        'uses' => 'ApiController@orgs'
    ]);

    // Returns all events for the users organisation
    Route::get('/orgs/{id}/events', [
        'as' => 'api.events',
        'uses' => 'ApiController@orgEvents'
    ]);

    // Returns all events for the users organisation
    Route::get('/orgs/{id}/users', [
        'as' => 'api.schoolUsers',
        'uses' => 'ApiController@orgUsers'
    ]);

    // Returns all events for the users organisation
    Route::get('/orgs/{id}/calendars', [
        'as' => 'api.schoolCalendars',
        'uses' => 'ApiController@orgCalendars'
    ]);

    // TODO: post API
});

/***
 * Manages all the calendar/event routes<commit_msg>renamed API routes for global use instead of only schools<commit_after><?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

if(Session::has('lang')){
    //Set the language
    App::setLocale(Session::get('lang'));
}

Route::get('/', [
    'as'   => 'landing',
    'uses' => 'HomeController@showWelcome'
]);

// About page
Route::get('about', ['as' => 'about', 'before' => 'auth', function() {
    return View::make('about');
}]);

// Info page
Route::get('help', ['as' => 'help', 'before' => 'auth', function() {
  return View::make('help');
}]);

Route::group(['prefix' => 'orgs'], function () {
    // List all organisations (for editing)
    Route::get('/', [
        'as' => 'orgs.index',
        function() {
            return View::make('orgs/index');
        }
    ]);
});

Route::group(['prefix' => 'school'], function () {
    // Create a new school
    Route::post('/register', [
        'as' => 'school.store',
        'uses' => 'SchoolController@store'
    ]);

    // List all schools
    Route::get('/', [
        'as'   => 'school.index',
        'uses' => 'SchoolController@index',
        'before' => 'admin'
    ]);

    // Show details of a certain school
    Route::get('/{id}', [
        'as'   => 'school.detail',
        'uses' => 'SchoolController@show',
        'before' => 'admin'
    ])->where('id', '[0-9]+');

    // Show the view to edit a school
    Route::get('/edit/{id}', [
        'as'   => 'school.edit',
        'uses' => 'SchoolController@edit'
    ])->where('id', '[0-9]+');

    // Update a school
    Route::post('/edit/{id}', [
        'as'   => 'school.update',
        'uses' => 'SchoolController@update',
        'before' => 'admin'
    ])->where('id', '[0-9]+');

    // Delete a school
    Route::get('/delete/{id}', [
        'as'   => 'school.delete',
        'uses' => 'SchoolController@destroy',
        'before' => 'admin'
    ])->where('id', '[0-9]+');
});


Route::group(['prefix' => 'profile'], function () {
    /*
      // Show list of users for a school
      Route::get('/', [
          'as' => 'user.index',
          'uses' => 'UserController@index'
      ]);
  */

    // Log user out TODO: post?
    Route::get('/logout', [
        'as'   => 'user.logout',
        'uses' => 'UserController@logout'
    ]);

    // Show the view to edit a user
    Route::get('/{id?}', [
        'as' => 'user.edit',
        'uses' => 'UserController@editUser'
    ])->where('id', '[0-9]+');

    // Add user to group
    Route::post('/{id}/roles', [
        'as' => 'user.addAdminRole',
        'uses' => 'UserController@promoteUserAdmin'
    ])->where('id', '[0-9]+');

    // Remover a user from group
    Route::delete('/{id}/roles', [
        'as' => 'user.removeAdminRole',
        'uses' => 'UserController@demoteUserAdmin'
    ])->where('id', '[0-9]+');

    // Update a user
    Route::post('/{id}', [
        'as'   => 'user.update',
        'uses' => 'UserController@updateUser'
    ])->where('id', '[0-9]+');

    // Register as a new user
    Route::post('/register', [
        'as' => 'user.register',
        'uses' => 'UserController@store'
    ]);

    // Create a new user (backoffice side)
    Route::post('/create', [
        'as' => 'user.create',
        'uses' => 'UserController@create'
    ]);

    // Authenticate user
    Route::post('/auth', [
        'as' => 'user.auth',
        'uses' => 'UserController@auth'
    ]);

    // Destroy a user
    Route::delete('/{id}', [
        'as'   => 'user.removeUserFromSchool',
        'uses' => 'UserController@removeUserFromSchool'
    ])->where('id', '[0-9]+');

    // GET: Reset the user's password with a hash received by mail
    Route::get('/reset/{hash}', [
        'as' => 'user.resetPassword',
        'uses' => 'UserController@resetPassword',
    ])->where([
        'hash' => '[a-zA-Z0-9]+'
    ]);

    // POST: send an email with the reset link
    Route::any('/sendReset/{mail}', [
        'as' => 'user.sendResetLink',
        'uses' => 'UserController@sendResetLink'
    ]);

    // POST: Reset the user's password
    // GET: Reset the user's password
    Route::any('/reset/{hash}', [
        'as' => 'user.resetPassword',
        'uses' => 'UserController@resetPassword',
    ])->where([
        'hash' => '[a-zA-Z0-9]+'
    ]);

});


Route::group(['prefix' => 'api/1'], function () {


    // Returns all events for the users organisation
    Route::get('/orgs', [
        'as' => 'api.orgs',
        'uses' => 'ApiController@orgs'
    ]);

    // Returns all events for the users organisation
    Route::get('/orgs/{id}/events', [
        'as' => 'api.events',
        'uses' => 'ApiController@orgEvents'
    ]);

    // Returns all events for the users organisation
    Route::get('/orgs/{id}/users', [
        'as' => 'api.orgUsers',
        'uses' => 'ApiController@orgUsers'
    ]);

    // Returns all events for the users organisation
    Route::get('/orgs/{id}/calendars', [
        'as' => 'api.orgCalendars',
        'uses' => 'ApiController@orgCalendars'
    ]);

    // TODO: post API
});

/***
 * Manages all the calendar/event routes
{'fraction_non_alphanumeric': 0.23967476670054513, 'fraction_numerical': 0.004250207890603344, 'mean_word_length': 2.1797884841363104, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 151, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5580646', 'n_tokens_mistral': 3447, 'n_tokens_neox': 3374, 'n_words': 764}