/** * регистрируется новый человек */ public function testUserCreate() { $this->call('POST', 'api/v1/user', ['first_name' => 'Стас', 'last_name' => 'Михайлов', 'phone' => '79100000000']); $user = User::first(); $this->assertEquals(1, $user->id); $this->assertEquals(1, $user->student->user_id); $this->assertEquals(1, $user->teacher->user_id); }
public function setUp() { parent::setUp(); $user = User::wherePhone('79100000000')->first(); $user->teacher->enabled = 0; $user->student->enabled = 0; $user->push(); $this->userId = $user->id; }
/** * регистрируется новый человек */ public function testUserCreate() { $response = $this->call('POST', 'api/v1/user', ['first_name' => 'Стас', 'last_name' => 'Михайлов', 'phone' => '79100000000', 'password' => '12345678', 'password_confirmation' => '12345678']); $this->assertResponseStatus(201); $user = User::first(); $this->assertNotEmpty($user, $response); $this->assertEquals(1, $user->id); $this->assertEquals(1, $user->student->user_id); $this->assertEquals(1, $user->teacher->user_id); }
/** * Удаление пользователя и очистка его профилей, по REST запросу */ public function testUserDelete() { $this->assertEquals(1, UserAdmin::find($this->userId)->enabled); $this->assertEquals(1, UserStudent::find($this->userId)->enabled); $this->assertEquals(1, UserTeacher::find($this->userId)->enabled); $this->call('DELETE', "api/v1/user/{$this->userId}"); $this->assertTrue(empty(User::find($this->userId))); $this->assertEquals(0, UserAdmin::find($this->userId)->enabled); $this->assertEquals(0, UserStudent::find($this->userId)->enabled); $this->assertEquals(0, UserTeacher::find($this->userId)->enabled); }
/** * @throws \ErrorException */ private function deleteUser() { $this->user->admin->enabled = false; $this->user->teacher->enabled = false; $this->user->student->enabled = false; $result = $this->user->push(); $result &= $this->user->delete(); if (!$result) { throw new \ErrorException('Failed to delete data'); } $this->message = 'Данные успешно удалены'; }
public function loginFacebook() { /** * Bootstrap the example * *require_once __DIR__ . '/bootstrap.php'; */ $storage = new Session(); // Session storage $servicesCredentials['facebook']['key'] = '641605372625410'; $servicesCredentials['facebook']['secret'] = 'ddcc4fda61288b868a6ab30eae14400c'; // Setup the credentials for the requests $uriFactory = new \OAuth\Common\Http\Uri\UriFactory(); $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER); $currentUri->setHost($_SERVER['HTTP_HOST']); $currentUri->setQuery(''); $credentials = new Credentials($servicesCredentials['facebook']['key'], $servicesCredentials['facebook']['secret'], $currentUri->getAbsoluteUri()); // Instantiate the Facebook service using the credentials, http client and storage mechanism for the token /** @var $facebookService Facebook */ $serviceFactory = new \OAuth\ServiceFactory(); $facebookService = $serviceFactory->createService('facebook', $credentials, $storage, array()); if (!empty($_GET['code'])) { // This was a callback request from facebook, get the token $token = $facebookService->requestAccessToken($_GET['code']); // Send a request with it $result = json_decode($facebookService->request('/me'), true); // Show some of the resultant data echo 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name']; $user = User::register($result); } elseif (!empty($_GET['go']) && $_GET['go'] === 'go') { $url = $facebookService->getAuthorizationUri(); header('Location: ' . $url); } else { $url = $currentUri->getRelativeUri() . '?go=go'; echo "<a href='{$url}'>Login with Facebook!</a>"; } }
/** * Show the form for editing the specified resource. * * @param int $id * * @return Response */ public function edit($id) { $user = User::findOrFail($id, array('id', 'first_name', 'middle_name', 'last_name', 'email', 'phone')); $fields = array('last_name' => 'Фамилия', 'first_name' => 'Имя', 'middle_name' => 'Отчество', 'email' => 'Электронная почта', 'password' => 'Пароль', 'password_confirmation' => 'Подтверждение пароля'); return Response::json(array('user' => $user, 'edit_fields' => $fields)); }
/** * Show the form for editing the specified resource. * * @param int $id * * @return Response */ public function edit($id) { $user = User::whereEnabled(true)->findOrFail($id, array('id', 'first_name', 'middle_name', 'last_name')); return Response::json(array('student' => array('id' => $id, 'enabled' => UserStudent::find($id)->enabled, 'user' => $user), 'edit_fields' => array('enabled' => 'Назначить студентом'), 'required_fields' => array('enabled'))); }
/** * Display the specified resource. * * @param int $id * * @return Response */ public function show($id) { $user = User::findOrFail($id, array('id', 'first_name', 'middle_name', 'last_name', 'email', 'phone')); return Response::json($user); }