OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library users_impl; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:appengine/api/users.dart'; |
| 10 |
| 11 import '../protobuf_api/user_service.dart'; |
| 12 import '../protobuf_api/rpc/rpc_service.dart'; |
| 13 import '../protobuf_api/internal/user_service.pb.dart' as pb; |
| 14 import '../server/http_wrapper.dart'; |
| 15 |
| 16 class UserRpcImpl extends UserService { |
| 17 static String _HTTP_HEADER_AUTH_DOMAIN = 'x-appengine-auth-domain'; |
| 18 static String _HTTP_HEADER_USER_EMAIL = 'x-appengine-user-email'; |
| 19 static String _HTTP_HEADER_USER_ID = 'x-appengine-user-id'; |
| 20 static String _HTTP_HEADER_USER_IS_ADMIN = 'x-appengine-user-is-admin'; |
| 21 |
| 22 final UserServiceClientRPCStub _clientRPCStub; |
| 23 User _currentUser; |
| 24 |
| 25 UserRpcImpl( |
| 26 RPCService rpcService, String ticket, AppengineHttpRequest request) |
| 27 : _clientRPCStub = new UserServiceClientRPCStub(rpcService, ticket) { |
| 28 var userEmail = request.headers.value(_HTTP_HEADER_USER_EMAIL); |
| 29 var userId = request.headers.value(_HTTP_HEADER_USER_ID); |
| 30 var userIsAdmin = request.headers.value(_HTTP_HEADER_USER_IS_ADMIN) == '1'; |
| 31 var authDomain = request.headers.value(_HTTP_HEADER_AUTH_DOMAIN); |
| 32 |
| 33 if (userEmail != null && !userEmail.isEmpty) { |
| 34 _currentUser = new User( |
| 35 authDomain: authDomain, |
| 36 email: userEmail, id: userId, |
| 37 isAdmin: userIsAdmin); |
| 38 } |
| 39 } |
| 40 |
| 41 User get currentUser => _currentUser; |
| 42 |
| 43 Future<String> createLoginUrl(String destination) { |
| 44 var request = new pb.CreateLoginURLRequest(); |
| 45 request.destinationUrl = destination; |
| 46 return _clientRPCStub.CreateLoginURL(request) |
| 47 .then((response) => response.loginUrl); |
| 48 } |
| 49 |
| 50 Future<String> createLogoutUrl(String destination) { |
| 51 var request = new pb.CreateLogoutURLRequest(); |
| 52 request.destinationUrl = destination; |
| 53 return _clientRPCStub.CreateLogoutURL(request) |
| 54 .then((response) => response.logoutUrl); |
| 55 } |
| 56 } |
OLD | NEW |