Skip to content

Commit 37ad159

Browse files
Add code sample for users API.
Docs live at https://cloud.google.com/appengine/docs/php/users/
1 parent d8d2b4c commit 37ad159

File tree

6 files changed

+1307
-20
lines changed

6 files changed

+1307
-20
lines changed

appengine/standard/users/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Users & Google App Engine
2+
3+
This sample application demonstrates how to use Google App Engine's users API.
4+
5+
## Prerequisites
6+
7+
- Install [`composer`](https://getcomposer.org)
8+
- Install dependencies by running:
9+
10+
```sh
11+
composer install
12+
```
13+
14+
## Deploy to App Engine
15+
16+
**Prerequisites**
17+
18+
- Install the [Google Cloud SDK](https://developers.google.com/cloud/sdk/).
19+
20+
**Deploy with gcloud**
21+
22+
```
23+
gcloud config set project YOUR_PROJECT_ID
24+
gcloud preview app deploy
25+
gcloud preview app browse
26+
```
27+
28+
The last command will open `https://{YOUR_PROJECT_ID}.appspot.com/`
29+
in your browser.

appengine/standard/users/app.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright 2015 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
# [START get_current_user]
19+
use google\appengine\api\users\User;
20+
use google\appengine\api\users\UserService;
21+
use Silex\Application;
22+
23+
// create the Silex application
24+
$app = new Application();
25+
26+
$app->get('/', function () use ($app) {
27+
$user = UserService::getCurrentUser();
28+
29+
if (isset($user)) {
30+
return sprintf('Welcome, %s! (<a href="%s">sign out</a>)',
31+
$user->getNickname(),
32+
UserService::createLogoutUrl('/'));
33+
} else {
34+
return sprintf('<a href="%s">Sign in or register</a>',
35+
UserService::createLoginUrl('/'));
36+
}
37+
});
38+
# [END get_current_user]
39+
40+
return $app;

appengine/standard/users/app.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
runtime: php55
2+
threadsafe: yes
3+
api_version: 1
4+
5+
handlers:
6+
- url: .*
7+
script: index.php
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"require": {
3+
"silex/silex": "^1.3",
4+
"php-http/guzzle6-adapter": "^1.0",
5+
"google/apiclient": "^1.1"
6+
},
7+
"require-dev": {
8+
"symfony/browser-kit": "^3.0"
9+
}
10+
}

0 commit comments

Comments
 (0)