feat: implement some api; add md editor to app; login and signup logic.

This commit is contained in:
2021-12-30 20:04:00 +08:00
parent 1a0e8f8de7
commit 853132f1a8
61 changed files with 3205 additions and 149 deletions
+16
View File
@@ -0,0 +1,16 @@
import 'package:angel3_auth/angel3_auth.dart';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_orm/angel3_orm.dart' as orm;
import 'package:dde_gesture_manager_api/models.dart';
Future<void> configureServer(Angel app) async {
var auth = AngelAuth<User>(
jwtKey: app.configuration['jwt_secret'],
allowCookie: false,
deserializer: (p) async => (UserQuery()..where!.id.equals(int.parse(p)))
.getOne(app.container!.make<orm.QueryExecutor>())
.then((value) => value.value),
serializer: (p) => p.id ?? '',
);
await auth.configureServer(app);
}
+4
View File
@@ -1,8 +1,12 @@
import 'dart:async';
import 'package:angel3_framework/angel3_framework.dart';
import 'orm.dart' as orm;
import 'jwt.dart' as jwt;
import 'redis_cache.dart' as redis_cache;
Future configureServer(Angel app) async {
// Include any plugins you have made here.
await app.configure(orm.configureServer);
await app.configure(jwt.configureServer);
await app.configure(redis_cache.configureServer);
}
@@ -0,0 +1,36 @@
import 'dart:convert';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:logging/logging.dart';
import 'package:neat_cache/neat_cache.dart';
Future<void> configureServer(Angel app) async {
final _log = Logger('RedisPlugin');
if (app.container == null) {
_log.severe('Angel3 container is null');
throw StateError('Angel.container is null. All authentication will fail.');
}
var appContainer = app.container!;
final cache = RedisCache(app.configuration);
appContainer.registerSingleton(cache);
}
class RedisCache {
late Cache cache;
RedisCache(Map config) {
var redisConfig = config['redis'] as Map? ?? {};
final cacheProvider = Cache.redisCacheProvider(
Uri(
scheme: 'redis',
host: redisConfig['host'],
port: redisConfig['port'],
userInfo: redisConfig['password'],
),
commandTimeLimit: const Duration(seconds: 1),
);
cache = Cache(cacheProvider).withCodec(utf8);
}
}