/** * Store a newly created resource in storage. * * @return Response */ public function store(CreateUserRequest $request) { $token = BetaToken::where('token', $request->beta_token)->firstOrFail(); if ($token->user !== null) { return \Response::json(['message' => 'token_already_used'], 403); } $user = User::create($request->all()); $user->password = bcrypt($user->password); $user->save(); $user->betaToken()->save($token); return \Response::json(['message' => 'ok'], 200); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create(); $userIds = Cotr\User::lists('id')->all(); for ($i = 0; $i < 10; $i++) { $userId = $faker->optional(0.5)->randomElement($userIds); if ($userId !== null) { if (($key = array_search($userId, $userIds)) !== false) { unset($userIds[$key]); } } BetaToken::create(['token' => str_random(5), 'user_id' => $userId]); } }
// authentication Route::post('authenticate', 'Auth\\AuthController@authenticate'); Route::post('authenticate/refresh_token', 'Auth\\AuthController@refreshToken'); // password reset Route::post('password/email', 'Auth\\PasswordController@postEmail'); Route::post('password/reset', 'Auth\\PasswordController@postReset'); // user Route::post('user', 'UserController@store'); Route::get('user/email_exists/{email}', 'UserController@emailExists'); Route::get('user/username_exists/{username}', 'UserController@usernameExists'); // rpg site Route::get('rpg_site/name_exists/{name}', 'RpgSiteController@nameExists'); Route::get('rpg_site/url_exists/{url}', 'RpgSiteController@urlExists')->where('url', '(.*)'); // beta token check Route::post('betatoken/{token}', function ($token) { $token = BetaToken::where('token', $token)->firstOrFail(); if ($token->user !== null) { return \Response::json(['message' => 'token_already_used'], 403); } return \Response::json(['message' => 'ok'], 200); }); }); Route::group(['prefix' => 'api', 'middleware' => ['cors', 'jwt.auth']], function () { // get authenticated user Route::get('authenticate/user', 'Auth\\AuthController@getAuthenticatedUser'); // user Route::resource('user', 'UserController', ['except' => ['create', 'store', 'edit']]); // rpg site Route::get('rpg_site/proposed', 'RpgSiteController@getProposed'); Route::post('rpg_site/approve/{id}', 'RpgSiteController@approve'); Route::resource('rpg_site', 'RpgSiteController', ['except' => ['create', 'edit']]);