Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Side by Side Diff: pkg/immi_samples/lib/login_presenter.dart

Issue 2035023003: Remove service-compiler related code. (Closed) Base URL: git@github.com:dartino/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dartino 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 import 'dart:convert';
6
7 import 'package:crypto/crypto.dart';
8 import 'package:immi/dart/immi.dart';
9
10 // Export generated code for nodes in login_presenter.immi
11 import 'package:immi/dart/login_presenter.dart';
12 export 'package:immi/dart/login_presenter.dart';
13
14 class LoginPresenter {
15 static const String _emptyNameOrPassword =
16 'Login failed. Empty name or password.';
17
18 Node state;
19 String url;
20 String user;
21
22 LoginPresenter(this.url) {
23 state = new LoggedOutStateNode(login: login, message: '');
24 }
25
26 LoginNode present(Node prev) {
27 return new LoginNode(state: state);
28 }
29
30 void login(String name, String password) {
31 user = name;
32 if (name == '' || password == '') {
33 state = new LoggedOutStateNode(login: login,
34 message: _emptyNameOrPassword);
35 } else {
36 HttpsRequestNode request =
37 new HttpsRequestNode(url: url,
38 authorization: _createAuthToken(name, password),
39 handleResponse: _handleResponse);
40 state = new LoginRequestStateNode(request: request);
41 }
42 }
43
44 String _createAuthToken(String name, String password) {
45 List<int> bytes = UTF8.encode('$name:$password');
46 String base64 = CryptoUtils.bytesToBase64(bytes);
47 return 'Basic $base64';
48 }
49
50 void _handleResponse(String data) {
51 // TODO(zarah): implement this and return depending on data.
52 state = new LoggedInStateNode(logout: logout, user: user);
53 }
54
55 void logout() {
56 state = new LoggedOutStateNode(login: login, message: '');
57 }
58 }
OLDNEW
« no previous file with comments | « pkg/immi_samples/lib/ios/ImmiSamples/ViewPresenter.h ('k') | pkg/immi_samples/lib/login_presenter.immi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698