From c6b9785d912004abf8f3d8311c9f2c1a231b446f Mon Sep 17 00:00:00 2001 From: sunshine <1913599913@qq.com> Date: Tue, 28 Jul 2020 13:22:19 +0800 Subject: [PATCH] gitee --- .../.flutter-plugins-dependencies | 1 + github_client_app/README.md | 8 ++ .../ios/Flutter/flutter_export_environment.sh | 9 +- github_client_app/jsons/access.json | 8 ++ github_client_app/jsons/giteeClient.json | 4 + github_client_app/jsons/profile.json | 1 + github_client_app/jsons/repo.json | 106 +++++++++++------ github_client_app/jsons/user.json | 47 ++++---- .../{i10n-arb => l10n-arb}/intl_messages.arb | 14 ++- .../{i10n-arb => l10n-arb}/intl_zh_CN.arb | 12 +- github_client_app/lib/common/git_api.dart | 80 ++++++++++--- .../lib/l10n/localization_intl.dart | 5 +- github_client_app/lib/l10n/messages_all.dart | 18 +-- .../lib/l10n/messages_messages.dart | 19 +-- .../lib/l10n/messages_zh_CN.dart | 19 +-- github_client_app/lib/models/access.dart | 18 +++ github_client_app/lib/models/access.g.dart | 26 ++++ github_client_app/lib/models/giteeClient.dart | 14 +++ .../lib/models/giteeClient.g.dart | 19 +++ github_client_app/lib/models/index.dart | 2 + github_client_app/lib/models/profile.dart | 2 + github_client_app/lib/models/profile.g.dart | 4 + github_client_app/lib/models/repo.dart | 55 +++++++-- github_client_app/lib/models/repo.g.dart | 112 ++++++++++++++---- github_client_app/lib/models/user.dart | 25 ++-- github_client_app/lib/models/user.g.dart | 50 +++++--- github_client_app/lib/routes/home_page.dart | 2 +- github_client_app/lib/routes/login.dart | 34 +++++- 28 files changed, 533 insertions(+), 181 deletions(-) create mode 100644 github_client_app/.flutter-plugins-dependencies create mode 100644 github_client_app/jsons/access.json create mode 100644 github_client_app/jsons/giteeClient.json rename github_client_app/{i10n-arb => l10n-arb}/intl_messages.arb (84%) rename github_client_app/{i10n-arb => l10n-arb}/intl_zh_CN.arb (85%) create mode 100644 github_client_app/lib/models/access.dart create mode 100644 github_client_app/lib/models/access.g.dart create mode 100644 github_client_app/lib/models/giteeClient.dart create mode 100644 github_client_app/lib/models/giteeClient.g.dart diff --git a/github_client_app/.flutter-plugins-dependencies b/github_client_app/.flutter-plugins-dependencies new file mode 100644 index 0000000..e32ece6 --- /dev/null +++ b/github_client_app/.flutter-plugins-dependencies @@ -0,0 +1 @@ +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"fluttertoast","path":"/Users/yiliang/installation/flutter/.pub-cache/hosted/pub.flutter-io.cn/fluttertoast-3.1.3/","dependencies":[]},{"name":"path_provider","path":"/Users/yiliang/installation/flutter/.pub-cache/hosted/pub.flutter-io.cn/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/Users/yiliang/installation/flutter/.pub-cache/hosted/pub.flutter-io.cn/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/Users/yiliang/installation/flutter/.pub-cache/hosted/pub.flutter-io.cn/sqflite-1.3.1/","dependencies":[]}],"android":[{"name":"fluttertoast","path":"/Users/yiliang/installation/flutter/.pub-cache/hosted/pub.flutter-io.cn/fluttertoast-3.1.3/","dependencies":[]},{"name":"path_provider","path":"/Users/yiliang/installation/flutter/.pub-cache/hosted/pub.flutter-io.cn/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/Users/yiliang/installation/flutter/.pub-cache/hosted/pub.flutter-io.cn/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/Users/yiliang/installation/flutter/.pub-cache/hosted/pub.flutter-io.cn/sqflite-1.3.1/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/yiliang/installation/flutter/.pub-cache/hosted/pub.flutter-io.cn/path_provider_macos-0.0.4+3/","dependencies":[]},{"name":"shared_preferences_macos","path":"/Users/yiliang/installation/flutter/.pub-cache/hosted/pub.flutter-io.cn/shared_preferences_macos-0.0.1+10/","dependencies":[]},{"name":"sqflite","path":"/Users/yiliang/installation/flutter/.pub-cache/hosted/pub.flutter-io.cn/sqflite-1.3.1/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/yiliang/installation/flutter/.pub-cache/hosted/pub.flutter-io.cn/path_provider_linux-0.0.1+2/","dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/yiliang/installation/flutter/.pub-cache/hosted/pub.flutter-io.cn/shared_preferences_linux-0.0.2+1/","dependencies":["path_provider_linux"]}],"windows":[],"web":[{"name":"shared_preferences_web","path":"/Users/yiliang/installation/flutter/.pub-cache/hosted/pub.flutter-io.cn/shared_preferences_web-0.1.2+7/","dependencies":[]}]},"dependencyGraph":[{"name":"fluttertoast","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-07-28 13:21:09.002757","version":"1.17.5"} \ No newline at end of file diff --git a/github_client_app/README.md b/github_client_app/README.md index 7a1c731..81452d7 100644 --- a/github_client_app/README.md +++ b/github_client_app/README.md @@ -1,3 +1,11 @@ +# 将登录不了的git客户端修改为了gitee客户端 +1、文字国际化修改为gitee +2、修改json、实体更换为gitee用户、repo改为gitee返回格式 +3、新增 giteeClient.json、access.json +4、在登录时,填写gitee 应用数据。并且持久化处理 +# 需要自己的码云创建一个第三应用登录的授权 +- [https://gitee.com/api/v5/oauth_doc#/list-item-3](https://gitee.com/api/v5/oauth_doc#/list-item-3) + # github_client_app A Github client APP built with Flutter diff --git a/github_client_app/ios/Flutter/flutter_export_environment.sh b/github_client_app/ios/Flutter/flutter_export_environment.sh index c5eab91..e80f366 100755 --- a/github_client_app/ios/Flutter/flutter_export_environment.sh +++ b/github_client_app/ios/Flutter/flutter_export_environment.sh @@ -1,12 +1,11 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=/Users/duwen/Documents/flutter" -export "FLUTTER_APPLICATION_PATH=/Users/duwen/Documents/code/flutter_in_action/github_client_app" -export "FLUTTER_TARGET=/Users/duwen/Documents/code/flutter_in_action/github_client_app/lib/main.dart" +export "FLUTTER_ROOT=/Users/yiliang/installation/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/yiliang/AndroidStudioProjects/git_demo/flutter_in_action_source_code/github_client_app" +export "FLUTTER_TARGET=lib/main.dart" export "FLUTTER_BUILD_DIR=build" export "SYMROOT=${SOURCE_ROOT}/../build/ios" export "OTHER_LDFLAGS=$(inherited) -framework Flutter" -export "FLUTTER_FRAMEWORK_DIR=/Users/duwen/Documents/flutter/bin/cache/artifacts/engine/ios" +export "FLUTTER_FRAMEWORK_DIR=/Users/yiliang/installation/flutter/bin/cache/artifacts/engine/ios" export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NUMBER=1" -export "TRACK_WIDGET_CREATION=true" diff --git a/github_client_app/jsons/access.json b/github_client_app/jsons/access.json new file mode 100644 index 0000000..3bf2009 --- /dev/null +++ b/github_client_app/jsons/access.json @@ -0,0 +1,8 @@ +{ + "access_token": "", + "token_type": "", + "expires_in": 86400, + "refresh_token": "", + "scope": "projects user_info issues notes", + "created_at": 1595902217 +} \ No newline at end of file diff --git a/github_client_app/jsons/giteeClient.json b/github_client_app/jsons/giteeClient.json new file mode 100644 index 0000000..5d72822 --- /dev/null +++ b/github_client_app/jsons/giteeClient.json @@ -0,0 +1,4 @@ +{ + "client_id": "", + "client_secret": "" +} \ No newline at end of file diff --git a/github_client_app/jsons/profile.json b/github_client_app/jsons/profile.json index b0cde6d..73e1903 100644 --- a/github_client_app/jsons/profile.json +++ b/github_client_app/jsons/profile.json @@ -1,5 +1,6 @@ { "user":"$user", + "giteeClient": "$giteeClient", "token":"", "theme":5678, "cache":"$cacheConfig", diff --git a/github_client_app/jsons/repo.json b/github_client_app/jsons/repo.json index 46ac8dc..a750916 100644 --- a/github_client_app/jsons/repo.json +++ b/github_client_app/jsons/repo.json @@ -1,46 +1,74 @@ { - "id": 1296269, - "name": "Hello-World", - "full_name": "octocat/Hello-World", + "id": 123, + "full_name": "", + "human_name": "", + "url": "", + "namespace": { + "id": 123, + "type": "", + "name": "", + "path": "", + "html_url": "" + }, + "path": "", + "name": "", "owner": "$user", - "parent":"$repo", - "private": false, - "html_url": "https://github.com/octocat/Hello-World", - "description": "This your first repo!", + "description": "", + "private": true, + "public": false, + "internal": false, "fork": false, - "homepage": "https://github.com", - "language": "JavaScript", - "forks_count": 9, - "stargazers_count": 80, - "watchers_count": 80, - "size": 108, - "default_branch": "master", - "open_issues_count": 0, - "topics": [ - "octocat", - "atom", - "electron", - "API" - ], + "html_url": "", + "ssh_url": "", + "forks_url": "", + "keys_url": "", + "collaborators_url": "", + "hooks_url": "", + "branches_url": "", + "tags_url": "", + "blobs_url": "", + "stargazers_url": "", + "contributors_url": "", + "commits_url": "", + "comments_url": "", + "issue_comment_url": "", + "issues_url": "", + "pulls_url": "", + "milestones_url": "", + "notifications_url": "", + "labels_url": "", + "releases_url": "", + "recommend": false, + "homepage": "", + "language": "", + "forks_count": 0, + "stargazers_count": 0, + "watchers_count": 3, + "default_branch": "", + "open_issues_count": 1, "has_issues": true, - "has_projects": true, "has_wiki": true, - "has_pages": false, - "has_downloads": true, - "pushed_at": "2011-01-26T19:06:43Z", - "created_at": "2011-01-26T19:01:12Z", - "updated_at": "2011-01-26T19:14:43Z", - "permissions": { - "admin": false, - "push": false, - "pull": true + "issue_comment": false, + "can_comment": true, + "pull_requests_enabled": true, + "has_page": false, + "license": null, + "outsourced": false, + "project_creator": "", + "members": [ + "SUNbrightness" + ], + "pushed_at": "", + "created_at": "", + "updated_at": "", + "parent": null, + "paas": null, + "stared": false, + "watched": true, + "permission": { + "pull": true, + "push": true, + "admin": false }, - "subscribers_count": 42, - "license": { - "key": "mit", - "name": "MIT License", - "spdx_id": "MIT", - "url": "https://api.github.com/licenses/mit", - "node_id": "MDc6TGljZW5zZW1pdA==" - } + "relation": "" } \ No newline at end of file diff --git a/github_client_app/jsons/user.json b/github_client_app/jsons/user.json index c1db03a..a2f7c60 100644 --- a/github_client_app/jsons/user.json +++ b/github_client_app/jsons/user.json @@ -1,23 +1,30 @@ { - "login": "octocat", - "id": 1, - "avatar_url": "https://github.com/images/error/octocat_happy.gif", - "url": "https://api.github.com/users/octocat", + "id": 123, + "login": "SUNbrightness", + "name": "sunshine", + "avatar_url": "", + "url": "", + "html_url": "", + "followers_url": "", + "following_url": "", + "gists_url": "", + "starred_url": "", + "subscriptions_url": "", + "organizations_url": "", + "repos_url": "", + "events_url": "", + "received_events_url": "", "type": "User", - "site_admin": false, - "name": "monalisa octocat", - "company": "GitHub", - "blog": "https://github.com/blog", - "location": "San Francisco", - "email": "octocat@github.com", - "hireable": false, - "bio": "There once was...", - "public_repos": 2, - "public_gists": 1, - "followers": 20, + "blog": null, + "weibo": null, + "bio": null, + "public_repos": 5, + "public_gists": 0, + "followers": 0, "following": 0, - "created_at": "2008-01-14T04:33:35Z", - "updated_at": "2008-01-14T04:33:35Z", - "total_private_repos": 100, - "owned_private_repos": 100 -} \ No newline at end of file + "stared": 7, + "watched": 35, + "created_at": "2018-06-03T09:12:18+08:00", + "updated_at": "2020-07-28T09:46:36+08:00", + "email": null +} diff --git a/github_client_app/i10n-arb/intl_messages.arb b/github_client_app/l10n-arb/intl_messages.arb similarity index 84% rename from github_client_app/i10n-arb/intl_messages.arb rename to github_client_app/l10n-arb/intl_messages.arb index 9fa35f3..3150c08 100644 --- a/github_client_app/i10n-arb/intl_messages.arb +++ b/github_client_app/l10n-arb/intl_messages.arb @@ -1,12 +1,12 @@ { - "@@last_modified": "2019-08-11T18:39:59.060353", + "@@last_modified": "2020-07-28T10:49:02.499268", "title": "Flutter APP", "@title": { "description": "Title for the Demo application", "type": "text", "placeholders": {} }, - "home": "Github", + "home": "Gitee", "@home": { "type": "text", "placeholders": {} @@ -61,6 +61,16 @@ "type": "text", "placeholders": {} }, + "clientIdRequired": "clientId required!", + "@clientIdRequired": { + "type": "text", + "placeholders": {} + }, + "clientSecretRequired": "clientSecret required!", + "@clientSecretRequired": { + "type": "text", + "placeholders": {} + }, "userNameOrPasswordWrong": "User name or password is not correct!", "@userNameOrPasswordWrong": { "type": "text", diff --git a/github_client_app/i10n-arb/intl_zh_CN.arb b/github_client_app/l10n-arb/intl_zh_CN.arb similarity index 85% rename from github_client_app/i10n-arb/intl_zh_CN.arb rename to github_client_app/l10n-arb/intl_zh_CN.arb index 496a474..029cc63 100644 --- a/github_client_app/i10n-arb/intl_zh_CN.arb +++ b/github_client_app/l10n-arb/intl_zh_CN.arb @@ -6,7 +6,7 @@ "type": "text", "placeholders": {} }, - "home": "Github客户端", + "home": "码云客户端", "@home": { "type": "text", "placeholders": {} @@ -61,6 +61,16 @@ "type": "text", "placeholders": {} }, + "clientIdRequired": "clientId 不能为空!", + "@clientIdRequired": { + "type": "text", + "placeholders": {} + }, + "clientSecretRequired": "clientSecret 不能为空!", + "@clientSecretRequired": { + "type": "text", + "placeholders": {} + }, "userNameOrPasswordWrong": "用户名或密码不正确", "@userNameOrPasswordWrong": { "type": "text", diff --git a/github_client_app/lib/common/git_api.dart b/github_client_app/lib/common/git_api.dart index 69caa44..c01939e 100644 --- a/github_client_app/lib/common/git_api.dart +++ b/github_client_app/lib/common/git_api.dart @@ -5,8 +5,14 @@ import 'package:dio/adapter.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import '../index.dart'; +import '../index.dart'; +import '../models/access.dart'; class Git { + + //请求授权的权限范围 + String _scope ="projects user_info issues notes"; + // 在网络请求过程中可能会需要使用当前的context信息,比如在请求失败时 // 打开一个新路由,而打开新路由需要context信息。 Git([this.context]) { @@ -16,11 +22,7 @@ class Git { BuildContext context; Options _options; static Dio dio = new Dio(BaseOptions( - baseUrl: 'https://api.github.com/', - headers: { - HttpHeaders.acceptHeader: "application/vnd.github.squirrel-girl-preview," - "application/vnd.github.symmetra-preview+json", - }, + baseUrl: 'https://gitee.com/' )); static void init() { @@ -34,7 +36,7 @@ class Git { (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) { client.findProxy = (uri) { - return "PROXY 10.95.249.53:8888"; + return "PROXY 10.0.3.2:5555"; }; //代理工具会提供一个抓包的自签名证书,会通不过证书校验,所以我们禁用证书校验 client.badCertificateCallback = @@ -44,25 +46,61 @@ class Git { } // 登录接口,登录成功后返回用户信息 - Future login(String login, String pwd) async { - String basic = 'Basic ' + base64.encode(utf8.encode('$login:$pwd')); - var r = await dio.get( - "/users/$login", - options: _options.merge(headers: { - HttpHeaders.authorizationHeader: basic - }, extra: { - "noCache": true, //本接口禁用缓存 - }), + Future login(String login, String pwd,String clientId,String clientSecret) async { + //持久化该client信息 + Global.profile.giteeClient= GiteeClient()..client_id = clientId ..client_secret=clientSecret; + Global.saveProfile(); + + + var data = { + "grant_type":"password", + "scope":_scope, + "client_id":clientId, + "client_secret":clientSecret, + "username":login, + "password":pwd + }; + Response response=await dio.request( + "/oauth/token", + data: data, + options:_options.merge( + method: "post", + contentType: "application/x-www-form-urlencoded", + extra: { + "noCache": true, //本接口禁用缓存 + } + ), ); - //登录成功后更新公共头(authorization),此后的所有请求都会带上用户身份信息 - dio.options.headers[HttpHeaders.authorizationHeader] = basic; + var access = Access.fromJson(response.data); + + + + //清空所有缓存 Global.netCache.cache.clear(); //更新profile中的token信息 - Global.profile.token = basic; + Global.profile.token = access.access_token; + return getUserInfo(login, pwd); + } + + + //获取已经授权的用户信息 + Future getUserInfo(String login, String pwd) async { + var r = await dio.get( + "/api/v5/user", + queryParameters:{ + "access_token":Global.profile.token + }, + options: _options.merge(extra: { + "noCache": true, //本接口禁用缓存 + }), + ); return User.fromJson(r.data); } + + + //获取用户项目列表 Future> getRepos( {Map queryParameters, //query参数,用于接收分页信息 @@ -71,8 +109,12 @@ class Git { // 列表下拉刷新,需要删除缓存(拦截器中会读取这些信息) _options.extra.addAll({"refresh": true, "list": true}); } + + //添加授权信息 + queryParameters["access_token"]=Global.profile.token; + var r = await dio.get( - "user/repos", + "/api/v5/user/repos", queryParameters: queryParameters, options: _options, ); diff --git a/github_client_app/lib/l10n/localization_intl.dart b/github_client_app/lib/l10n/localization_intl.dart index 206ae53..c29efe7 100644 --- a/github_client_app/lib/l10n/localization_intl.dart +++ b/github_client_app/lib/l10n/localization_intl.dart @@ -26,7 +26,7 @@ class GmLocalizations { ); } - String get home => Intl.message('Github', name: 'home'); + String get home => Intl.message('Gitee', name: 'home'); String get language => Intl.message('Language', name: 'language'); @@ -45,6 +45,9 @@ class GmLocalizations { String get userNameRequired => Intl.message("User name required!" , name: 'userNameRequired'); String get password => Intl.message('Password', name: 'password'); String get passwordRequired => Intl.message('Password required!', name: 'passwordRequired'); + String get clientIdRequired => Intl.message('clientId required!', name: 'clientIdRequired'); + String get clientSecretRequired => Intl.message('clientSecret required!', name: 'clientSecretRequired'); + String get userNameOrPasswordWrong=>Intl.message('User name or password is not correct!', name: 'userNameOrPasswordWrong'); String get logout => Intl.message('logout', name: 'logout'); String get logoutTip => Intl.message('Are you sure you want to quit your current account?', name: 'logoutTip'); diff --git a/github_client_app/lib/l10n/messages_all.dart b/github_client_app/lib/l10n/messages_all.dart index c5ac8ce..7730b65 100644 --- a/github_client_app/lib/l10n/messages_all.dart +++ b/github_client_app/lib/l10n/messages_all.dart @@ -2,11 +2,17 @@ // This is a library that looks up messages for specific locales by // delegating to the appropriate library. +// Ignore issues from commonly used lints in this file. +// ignore_for_file:implementation_imports, file_names, unnecessary_new +// ignore_for_file:unnecessary_brace_in_string_interps, directives_ordering +// ignore_for_file:argument_type_not_assignable, invalid_assignment +// ignore_for_file:prefer_single_quotes, prefer_generic_function_type_aliases +// ignore_for_file:comment_references + import 'dart:async'; import 'package:intl/intl.dart'; import 'package:intl/message_lookup_by_library.dart'; -// ignore: implementation_imports import 'package:intl/src/intl_helpers.dart'; import 'messages_messages.dart' as messages_messages; @@ -14,13 +20,11 @@ import 'messages_zh_CN.dart' as messages_zh_cn; typedef Future LibraryLoader(); Map _deferredLibraries = { -// ignore: unnecessary_new 'messages': () => new Future.value(null), -// ignore: unnecessary_new 'zh_CN': () => new Future.value(null), }; -MessageLookupByLibrary _findExact(localeName) { +MessageLookupByLibrary _findExact(String localeName) { switch (localeName) { case 'messages': return messages_messages.messages; @@ -38,16 +42,12 @@ Future initializeMessages(String localeName) async { (locale) => _deferredLibraries[locale] != null, onFailure: (_) => null); if (availableLocale == null) { - // ignore: unnecessary_new return new Future.value(false); } var lib = _deferredLibraries[availableLocale]; - // ignore: unnecessary_new await (lib == null ? new Future.value(false) : lib()); - // ignore: unnecessary_new initializeInternalMessageLookup(() => new CompositeMessageLookup()); messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor); - // ignore: unnecessary_new return new Future.value(true); } @@ -59,7 +59,7 @@ bool _messagesExistFor(String locale) { } } -MessageLookupByLibrary _findGeneratedMessagesFor(locale) { +MessageLookupByLibrary _findGeneratedMessagesFor(String locale) { var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null); if (actualLocale == null) return null; diff --git a/github_client_app/lib/l10n/messages_messages.dart b/github_client_app/lib/l10n/messages_messages.dart index 9f20142..39e4564 100644 --- a/github_client_app/lib/l10n/messages_messages.dart +++ b/github_client_app/lib/l10n/messages_messages.dart @@ -3,28 +3,29 @@ // messages from the main program should be duplicated here with the same // function name. -// ignore_for_file: unnecessary_brace_in_string_interps +// Ignore issues from commonly used lints in this file. +// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new +// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering +// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases +// ignore_for_file:unused_import, file_names import 'package:intl/intl.dart'; import 'package:intl/message_lookup_by_library.dart'; -// ignore: unnecessary_new final messages = new MessageLookup(); -// ignore: unused_element -final _keepAnalysisHappy = Intl.defaultLocale; - -// ignore: non_constant_identifier_names -typedef MessageIfAbsent(String message_str, List args); +typedef String MessageIfAbsent(String messageStr, List args); class MessageLookup extends MessageLookupByLibrary { - get localeName => 'messages'; + String get localeName => 'messages'; final messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "auto" : MessageLookupByLibrary.simpleMessage("Auto"), "cancel" : MessageLookupByLibrary.simpleMessage("cancel"), - "home" : MessageLookupByLibrary.simpleMessage("Github"), + "clientIdRequired" : MessageLookupByLibrary.simpleMessage("clientId required!"), + "clientSecretRequired" : MessageLookupByLibrary.simpleMessage("clientSecret required!"), + "home" : MessageLookupByLibrary.simpleMessage("Gitee"), "language" : MessageLookupByLibrary.simpleMessage("Language"), "login" : MessageLookupByLibrary.simpleMessage("Login"), "logout" : MessageLookupByLibrary.simpleMessage("logout"), diff --git a/github_client_app/lib/l10n/messages_zh_CN.dart b/github_client_app/lib/l10n/messages_zh_CN.dart index 2588c6e..8f3ff3b 100644 --- a/github_client_app/lib/l10n/messages_zh_CN.dart +++ b/github_client_app/lib/l10n/messages_zh_CN.dart @@ -3,28 +3,29 @@ // messages from the main program should be duplicated here with the same // function name. -// ignore_for_file: unnecessary_brace_in_string_interps +// Ignore issues from commonly used lints in this file. +// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new +// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering +// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases +// ignore_for_file:unused_import, file_names import 'package:intl/intl.dart'; import 'package:intl/message_lookup_by_library.dart'; -// ignore: unnecessary_new final messages = new MessageLookup(); -// ignore: unused_element -final _keepAnalysisHappy = Intl.defaultLocale; - -// ignore: non_constant_identifier_names -typedef MessageIfAbsent(String message_str, List args); +typedef String MessageIfAbsent(String messageStr, List args); class MessageLookup extends MessageLookupByLibrary { - get localeName => 'zh_CN'; + String get localeName => 'zh_CN'; final messages = _notInlinedMessages(_notInlinedMessages); static _notInlinedMessages(_) => { "auto" : MessageLookupByLibrary.simpleMessage("跟随系统"), "cancel" : MessageLookupByLibrary.simpleMessage("取消"), - "home" : MessageLookupByLibrary.simpleMessage("Github客户端"), + "clientIdRequired" : MessageLookupByLibrary.simpleMessage("clientId 不能为空!"), + "clientSecretRequired" : MessageLookupByLibrary.simpleMessage("clientSecret 不能为空!"), + "home" : MessageLookupByLibrary.simpleMessage("码云客户端"), "language" : MessageLookupByLibrary.simpleMessage("语言"), "login" : MessageLookupByLibrary.simpleMessage("登录"), "logout" : MessageLookupByLibrary.simpleMessage("注销"), diff --git a/github_client_app/lib/models/access.dart b/github_client_app/lib/models/access.dart new file mode 100644 index 0000000..bfa8fc7 --- /dev/null +++ b/github_client_app/lib/models/access.dart @@ -0,0 +1,18 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'access.g.dart'; + +@JsonSerializable() +class Access { + Access(); + + String access_token; + String token_type; + num expires_in; + String refresh_token; + String scope; + num created_at; + + factory Access.fromJson(Map json) => _$AccessFromJson(json); + Map toJson() => _$AccessToJson(this); +} diff --git a/github_client_app/lib/models/access.g.dart b/github_client_app/lib/models/access.g.dart new file mode 100644 index 0000000..f6e2001 --- /dev/null +++ b/github_client_app/lib/models/access.g.dart @@ -0,0 +1,26 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'access.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Access _$AccessFromJson(Map json) { + return Access() + ..access_token = json['access_token'] as String + ..token_type = json['token_type'] as String + ..expires_in = json['expires_in'] as num + ..refresh_token = json['refresh_token'] as String + ..scope = json['scope'] as String + ..created_at = json['created_at'] as num; +} + +Map _$AccessToJson(Access instance) => { + 'access_token': instance.access_token, + 'token_type': instance.token_type, + 'expires_in': instance.expires_in, + 'refresh_token': instance.refresh_token, + 'scope': instance.scope, + 'created_at': instance.created_at + }; diff --git a/github_client_app/lib/models/giteeClient.dart b/github_client_app/lib/models/giteeClient.dart new file mode 100644 index 0000000..914af29 --- /dev/null +++ b/github_client_app/lib/models/giteeClient.dart @@ -0,0 +1,14 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'giteeClient.g.dart'; + +@JsonSerializable() +class GiteeClient { + GiteeClient(); + + String client_id; + String client_secret; + + factory GiteeClient.fromJson(Map json) => _$GiteeClientFromJson(json); + Map toJson() => _$GiteeClientToJson(this); +} diff --git a/github_client_app/lib/models/giteeClient.g.dart b/github_client_app/lib/models/giteeClient.g.dart new file mode 100644 index 0000000..7cec4ff --- /dev/null +++ b/github_client_app/lib/models/giteeClient.g.dart @@ -0,0 +1,19 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'giteeClient.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +GiteeClient _$GiteeClientFromJson(Map json) { + return GiteeClient() + ..client_id = json['client_id'] as String + ..client_secret = json['client_secret'] as String; +} + +Map _$GiteeClientToJson(GiteeClient instance) => + { + 'client_id': instance.client_id, + 'client_secret': instance.client_secret + }; diff --git a/github_client_app/lib/models/index.dart b/github_client_app/lib/models/index.dart index 4428d5d..2540d72 100644 --- a/github_client_app/lib/models/index.dart +++ b/github_client_app/lib/models/index.dart @@ -1,4 +1,6 @@ export 'repo.dart' ; export 'cacheConfig.dart' ; export 'user.dart' ; +export 'access.dart' ; +export 'giteeClient.dart' ; export 'profile.dart' ; diff --git a/github_client_app/lib/models/profile.dart b/github_client_app/lib/models/profile.dart index 4fbc70c..92e41b3 100644 --- a/github_client_app/lib/models/profile.dart +++ b/github_client_app/lib/models/profile.dart @@ -1,5 +1,6 @@ import 'package:json_annotation/json_annotation.dart'; import "user.dart"; +import "giteeClient.dart"; import "cacheConfig.dart"; part 'profile.g.dart'; @@ -8,6 +9,7 @@ class Profile { Profile(); User user; + GiteeClient giteeClient; String token; num theme; CacheConfig cache; diff --git a/github_client_app/lib/models/profile.g.dart b/github_client_app/lib/models/profile.g.dart index ddde7f3..d2f7c9d 100644 --- a/github_client_app/lib/models/profile.g.dart +++ b/github_client_app/lib/models/profile.g.dart @@ -11,6 +11,9 @@ Profile _$ProfileFromJson(Map json) { ..user = json['user'] == null ? null : User.fromJson(json['user'] as Map) + ..giteeClient = json['giteeClient'] == null + ? null + : GiteeClient.fromJson(json['giteeClient'] as Map) ..token = json['token'] as String ..theme = json['theme'] as num ..cache = json['cache'] == null @@ -22,6 +25,7 @@ Profile _$ProfileFromJson(Map json) { Map _$ProfileToJson(Profile instance) => { 'user': instance.user, + 'giteeClient': instance.giteeClient, 'token': instance.token, 'theme': instance.theme, 'cache': instance.cache, diff --git a/github_client_app/lib/models/repo.dart b/github_client_app/lib/models/repo.dart index 74d210d..04d65b8 100644 --- a/github_client_app/lib/models/repo.dart +++ b/github_client_app/lib/models/repo.dart @@ -7,34 +7,65 @@ class Repo { Repo(); num id; - String name; String full_name; + String human_name; + String url; + Map namespace; + String path; + String name; User owner; - Repo parent; - bool private; - String html_url; String description; + bool private; + bool public; + bool internal; bool fork; + String html_url; + String ssh_url; + String forks_url; + String keys_url; + String collaborators_url; + String hooks_url; + String branches_url; + String tags_url; + String blobs_url; + String stargazers_url; + String contributors_url; + String commits_url; + String comments_url; + String issue_comment_url; + String issues_url; + String pulls_url; + String milestones_url; + String notifications_url; + String labels_url; + String releases_url; + bool recommend; String homepage; String language; num forks_count; num stargazers_count; num watchers_count; - num size; String default_branch; num open_issues_count; - List topics; bool has_issues; - bool has_projects; bool has_wiki; - bool has_pages; - bool has_downloads; + bool issue_comment; + bool can_comment; + bool pull_requests_enabled; + bool has_page; + String license; + bool outsourced; + String project_creator; + List members; String pushed_at; String created_at; String updated_at; - Map permissions; - num subscribers_count; - Map license; + String parent; + String paas; + bool stared; + bool watched; + Map permission; + String relation; factory Repo.fromJson(Map json) => _$RepoFromJson(json); Map toJson() => _$RepoToJson(this); diff --git a/github_client_app/lib/models/repo.g.dart b/github_client_app/lib/models/repo.g.dart index 285cbeb..3254885 100644 --- a/github_client_app/lib/models/repo.g.dart +++ b/github_client_app/lib/models/repo.g.dart @@ -9,68 +9,128 @@ part of 'repo.dart'; Repo _$RepoFromJson(Map json) { return Repo() ..id = json['id'] as num - ..name = json['name'] as String ..full_name = json['full_name'] as String + ..human_name = json['human_name'] as String + ..url = json['url'] as String + ..namespace = json['namespace'] as Map + ..path = json['path'] as String + ..name = json['name'] as String ..owner = json['owner'] == null ? null : User.fromJson(json['owner'] as Map) - ..parent = json['parent'] == null - ? null - : Repo.fromJson(json['parent'] as Map) - ..private = json['private'] as bool - ..html_url = json['html_url'] as String ..description = json['description'] as String + ..private = json['private'] as bool + ..public = json['public'] as bool + ..internal = json['internal'] as bool ..fork = json['fork'] as bool + ..html_url = json['html_url'] as String + ..ssh_url = json['ssh_url'] as String + ..forks_url = json['forks_url'] as String + ..keys_url = json['keys_url'] as String + ..collaborators_url = json['collaborators_url'] as String + ..hooks_url = json['hooks_url'] as String + ..branches_url = json['branches_url'] as String + ..tags_url = json['tags_url'] as String + ..blobs_url = json['blobs_url'] as String + ..stargazers_url = json['stargazers_url'] as String + ..contributors_url = json['contributors_url'] as String + ..commits_url = json['commits_url'] as String + ..comments_url = json['comments_url'] as String + ..issue_comment_url = json['issue_comment_url'] as String + ..issues_url = json['issues_url'] as String + ..pulls_url = json['pulls_url'] as String + ..milestones_url = json['milestones_url'] as String + ..notifications_url = json['notifications_url'] as String + ..labels_url = json['labels_url'] as String + ..releases_url = json['releases_url'] as String + ..recommend = json['recommend'] as bool ..homepage = json['homepage'] as String ..language = json['language'] as String ..forks_count = json['forks_count'] as num ..stargazers_count = json['stargazers_count'] as num ..watchers_count = json['watchers_count'] as num - ..size = json['size'] as num ..default_branch = json['default_branch'] as String ..open_issues_count = json['open_issues_count'] as num - ..topics = json['topics'] as List ..has_issues = json['has_issues'] as bool - ..has_projects = json['has_projects'] as bool ..has_wiki = json['has_wiki'] as bool - ..has_pages = json['has_pages'] as bool - ..has_downloads = json['has_downloads'] as bool + ..issue_comment = json['issue_comment'] as bool + ..can_comment = json['can_comment'] as bool + ..pull_requests_enabled = json['pull_requests_enabled'] as bool + ..has_page = json['has_page'] as bool + ..license = json['license'] as String + ..outsourced = json['outsourced'] as bool + ..project_creator = json['project_creator'] as String + ..members = json['members'] as List ..pushed_at = json['pushed_at'] as String ..created_at = json['created_at'] as String ..updated_at = json['updated_at'] as String - ..permissions = json['permissions'] as Map - ..subscribers_count = json['subscribers_count'] as num - ..license = json['license'] as Map; + ..parent = json['parent'] as String + ..paas = json['paas'] as String + ..stared = json['stared'] as bool + ..watched = json['watched'] as bool + ..permission = json['permission'] as Map + ..relation = json['relation'] as String; } Map _$RepoToJson(Repo instance) => { 'id': instance.id, - 'name': instance.name, 'full_name': instance.full_name, + 'human_name': instance.human_name, + 'url': instance.url, + 'namespace': instance.namespace, + 'path': instance.path, + 'name': instance.name, 'owner': instance.owner, - 'parent': instance.parent, - 'private': instance.private, - 'html_url': instance.html_url, 'description': instance.description, + 'private': instance.private, + 'public': instance.public, + 'internal': instance.internal, 'fork': instance.fork, + 'html_url': instance.html_url, + 'ssh_url': instance.ssh_url, + 'forks_url': instance.forks_url, + 'keys_url': instance.keys_url, + 'collaborators_url': instance.collaborators_url, + 'hooks_url': instance.hooks_url, + 'branches_url': instance.branches_url, + 'tags_url': instance.tags_url, + 'blobs_url': instance.blobs_url, + 'stargazers_url': instance.stargazers_url, + 'contributors_url': instance.contributors_url, + 'commits_url': instance.commits_url, + 'comments_url': instance.comments_url, + 'issue_comment_url': instance.issue_comment_url, + 'issues_url': instance.issues_url, + 'pulls_url': instance.pulls_url, + 'milestones_url': instance.milestones_url, + 'notifications_url': instance.notifications_url, + 'labels_url': instance.labels_url, + 'releases_url': instance.releases_url, + 'recommend': instance.recommend, 'homepage': instance.homepage, 'language': instance.language, 'forks_count': instance.forks_count, 'stargazers_count': instance.stargazers_count, 'watchers_count': instance.watchers_count, - 'size': instance.size, 'default_branch': instance.default_branch, 'open_issues_count': instance.open_issues_count, - 'topics': instance.topics, 'has_issues': instance.has_issues, - 'has_projects': instance.has_projects, 'has_wiki': instance.has_wiki, - 'has_pages': instance.has_pages, - 'has_downloads': instance.has_downloads, + 'issue_comment': instance.issue_comment, + 'can_comment': instance.can_comment, + 'pull_requests_enabled': instance.pull_requests_enabled, + 'has_page': instance.has_page, + 'license': instance.license, + 'outsourced': instance.outsourced, + 'project_creator': instance.project_creator, + 'members': instance.members, 'pushed_at': instance.pushed_at, 'created_at': instance.created_at, 'updated_at': instance.updated_at, - 'permissions': instance.permissions, - 'subscribers_count': instance.subscribers_count, - 'license': instance.license + 'parent': instance.parent, + 'paas': instance.paas, + 'stared': instance.stared, + 'watched': instance.watched, + 'permission': instance.permission, + 'relation': instance.relation }; diff --git a/github_client_app/lib/models/user.dart b/github_client_app/lib/models/user.dart index 9bbdb2b..e088c76 100644 --- a/github_client_app/lib/models/user.dart +++ b/github_client_app/lib/models/user.dart @@ -6,27 +6,34 @@ part 'user.g.dart'; class User { User(); - String login; num id; + String login; + String name; String avatar_url; String url; + String html_url; + String followers_url; + String following_url; + String gists_url; + String starred_url; + String subscriptions_url; + String organizations_url; + String repos_url; + String events_url; + String received_events_url; String type; - bool site_admin; - String name; - String company; String blog; - String location; - String email; - bool hireable; + String weibo; String bio; num public_repos; num public_gists; num followers; num following; + num stared; + num watched; String created_at; String updated_at; - num total_private_repos; - num owned_private_repos; + String email; factory User.fromJson(Map json) => _$UserFromJson(json); Map toJson() => _$UserToJson(this); diff --git a/github_client_app/lib/models/user.g.dart b/github_client_app/lib/models/user.g.dart index 47e70b1..6d986f0 100644 --- a/github_client_app/lib/models/user.g.dart +++ b/github_client_app/lib/models/user.g.dart @@ -8,49 +8,63 @@ part of 'user.dart'; User _$UserFromJson(Map json) { return User() - ..login = json['login'] as String ..id = json['id'] as num + ..login = json['login'] as String + ..name = json['name'] as String ..avatar_url = json['avatar_url'] as String ..url = json['url'] as String + ..html_url = json['html_url'] as String + ..followers_url = json['followers_url'] as String + ..following_url = json['following_url'] as String + ..gists_url = json['gists_url'] as String + ..starred_url = json['starred_url'] as String + ..subscriptions_url = json['subscriptions_url'] as String + ..organizations_url = json['organizations_url'] as String + ..repos_url = json['repos_url'] as String + ..events_url = json['events_url'] as String + ..received_events_url = json['received_events_url'] as String ..type = json['type'] as String - ..site_admin = json['site_admin'] as bool - ..name = json['name'] as String - ..company = json['company'] as String ..blog = json['blog'] as String - ..location = json['location'] as String - ..email = json['email'] as String - ..hireable = json['hireable'] as bool + ..weibo = json['weibo'] as String ..bio = json['bio'] as String ..public_repos = json['public_repos'] as num ..public_gists = json['public_gists'] as num ..followers = json['followers'] as num ..following = json['following'] as num + ..stared = json['stared'] as num + ..watched = json['watched'] as num ..created_at = json['created_at'] as String ..updated_at = json['updated_at'] as String - ..total_private_repos = json['total_private_repos'] as num - ..owned_private_repos = json['owned_private_repos'] as num; + ..email = json['email'] as String; } Map _$UserToJson(User instance) => { - 'login': instance.login, 'id': instance.id, + 'login': instance.login, + 'name': instance.name, 'avatar_url': instance.avatar_url, 'url': instance.url, + 'html_url': instance.html_url, + 'followers_url': instance.followers_url, + 'following_url': instance.following_url, + 'gists_url': instance.gists_url, + 'starred_url': instance.starred_url, + 'subscriptions_url': instance.subscriptions_url, + 'organizations_url': instance.organizations_url, + 'repos_url': instance.repos_url, + 'events_url': instance.events_url, + 'received_events_url': instance.received_events_url, 'type': instance.type, - 'site_admin': instance.site_admin, - 'name': instance.name, - 'company': instance.company, 'blog': instance.blog, - 'location': instance.location, - 'email': instance.email, - 'hireable': instance.hireable, + 'weibo': instance.weibo, 'bio': instance.bio, 'public_repos': instance.public_repos, 'public_gists': instance.public_gists, 'followers': instance.followers, 'following': instance.following, + 'stared': instance.stared, + 'watched': instance.watched, 'created_at': instance.created_at, 'updated_at': instance.updated_at, - 'total_private_repos': instance.total_private_repos, - 'owned_private_repos': instance.owned_private_repos + 'email': instance.email }; diff --git a/github_client_app/lib/routes/home_page.dart b/github_client_app/lib/routes/home_page.dart index f0fcca7..21ee298 100644 --- a/github_client_app/lib/routes/home_page.dart +++ b/github_client_app/lib/routes/home_page.dart @@ -36,7 +36,7 @@ class _HomeRouteState extends State { refresh: refresh, queryParameters: { 'page': page, - 'page_size': 20, + 'per_page': 20, }, ); //把请求到的新数据添加到items中 diff --git a/github_client_app/lib/routes/login.dart b/github_client_app/lib/routes/login.dart index 57cb872..94d33a2 100644 --- a/github_client_app/lib/routes/login.dart +++ b/github_client_app/lib/routes/login.dart @@ -8,6 +8,8 @@ class LoginRoute extends StatefulWidget { class _LoginRouteState extends State { TextEditingController _unameController = new TextEditingController(); TextEditingController _pwdController = new TextEditingController(); + TextEditingController _clientIdController = new TextEditingController(); + TextEditingController _clientSecretController = new TextEditingController(); bool pwdShow = false; GlobalKey _formKey = new GlobalKey(); bool _nameAutoFocus = true; @@ -19,6 +21,12 @@ class _LoginRouteState extends State { if (_unameController.text != null) { _nameAutoFocus = false; } + //自动填充上次填写的giteeClient信息 + if(Global.profile.giteeClient!=null){ + _clientIdController.text = Global.profile.giteeClient.client_id; + _clientSecretController.text = Global.profile.giteeClient.client_secret; + } + super.initState(); } @@ -68,6 +76,30 @@ class _LoginRouteState extends State { return v.trim().isNotEmpty ? null : gm.passwordRequired; }, ), + TextFormField( + controller: _clientIdController, + decoration: InputDecoration( + labelText: "clientId", + hintText: "clientId", + prefixIcon: Icon(Icons.compare_arrows), + ), + //校验密码(不能为空) + validator: (v) { + return v.trim().isNotEmpty ? null : gm.clientIdRequired; + }, + ), + TextFormField( + controller: _clientSecretController, + decoration: InputDecoration( + labelText: "clientSecret", + hintText: "clientSecret", + prefixIcon: Icon(Icons.compare_arrows), + ), + //校验密码(不能为空) + validator: (v) { + return v.trim().isNotEmpty ? null : gm.clientSecretRequired; + }, + ), Padding( padding: const EdgeInsets.only(top: 25), child: ConstrainedBox( @@ -94,7 +126,7 @@ class _LoginRouteState extends State { User user; try { user = await Git(context) - .login(_unameController.text, _pwdController.text); + .login(_unameController.text, _pwdController.text,_clientIdController.text,_clientSecretController.text); // 因为登录页返回后,首页会build,所以我们传false,更新user后不触发更新 Provider.of(context, listen: false).user = user; } catch (e) {