diff --git a/.idea/runConfigurations/Start_Server__PRODUCTION_.xml b/.idea/runConfigurations/Start_Server__PRODUCTION_.xml
new file mode 100644
index 00000000..f10a5567
--- /dev/null
+++ b/.idea/runConfigurations/Start_Server__PRODUCTION_.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/Users_Tests.xml b/.idea/runConfigurations/Users_Tests.xml
new file mode 100644
index 00000000..a5f788b5
--- /dev/null
+++ b/.idea/runConfigurations/Users_Tests.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/analysis_options.yaml b/analysis_options.yaml
new file mode 100644
index 00000000..e69de29b
diff --git a/bin/server.dart b/bin/server.dart
index cf61b66a..48d5fdb2 100755
--- a/bin/server.dart
+++ b/bin/server.dart
@@ -4,7 +4,6 @@ import 'dart:async';
import 'dart:io';
import 'package:angel/angel.dart';
import 'package:angel_diagnostics/angel_diagnostics.dart';
-import 'package:angel_framework/angel_framework.dart';
import 'package:intl/intl.dart';
main() async {
diff --git a/lib/angel.dart b/lib/angel.dart
index 17bfe66a..d8a008ef 100644
--- a/lib/angel.dart
+++ b/lib/angel.dart
@@ -6,6 +6,7 @@ import 'package:angel_framework/angel_framework.dart';
import 'src/config/config.dart' as configuration;
import 'src/routes/routes.dart' as routes;
import 'src/services/services.dart' as services;
+export 'src/services/services.dart';
/// Creates and configures the server instance.
Future createServer() async {
diff --git a/lib/src/config/config.dart b/lib/src/config/config.dart
index 7dde821b..32df5a6b 100644
--- a/lib/src/config/config.dart
+++ b/lib/src/config/config.dart
@@ -5,9 +5,11 @@ import 'dart:io';
import 'package:angel_configuration/angel_configuration.dart';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_mustache/angel_mustache.dart';
+import 'plugins/plugins.dart' as plugins;
/// This is a perfect place to include configuration and load plug-ins.
configureServer(Angel app) async {
await app.configure(loadConfigurationFile());
await app.configure(mustache(new Directory('views')));
+ await plugins.configureServer(app);
}
diff --git a/lib/src/config/plugins/plugins.dart b/lib/src/config/plugins/plugins.dart
new file mode 100644
index 00000000..e7b41621
--- /dev/null
+++ b/lib/src/config/plugins/plugins.dart
@@ -0,0 +1,9 @@
+/// Custom plugins go here.
+library angel.config.plugins;
+
+import 'dart:async';
+import 'package:angel_framework/angel_framework.dart';
+
+Future configureServer(Angel app) async {
+ // Include any plugins you have made here.
+}
\ No newline at end of file
diff --git a/lib/src/models/user.dart b/lib/src/models/user.dart
index 8ea11446..8478f23b 100644
--- a/lib/src/models/user.dart
+++ b/lib/src/models/user.dart
@@ -26,18 +26,18 @@ class User extends Model {
factory User.fromMap(Map data) => new User(
id: data['id'],
- email: data["email"],
- username: data["username"],
- password: data["password"],
- roles: data["roles"]);
+ email: data['email'],
+ username: data['username'],
+ password: data['password'],
+ roles: data['roles']);
Map toJson() {
return {
- "id": id,
- "email": email,
- "username": username,
- "password": password,
- "roles": roles
+ 'id': id,
+ 'email': email,
+ 'username': username,
+ 'password': password,
+ 'roles': roles
};
}
}
diff --git a/lib/src/routes/controllers/auth.dart b/lib/src/routes/controllers/auth.dart
index d28d7fa7..b5c37d4f 100644
--- a/lib/src/routes/controllers/auth.dart
+++ b/lib/src/routes/controllers/auth.dart
@@ -4,17 +4,17 @@ import 'package:angel_auth/angel_auth.dart';
import 'package:angel_framework/angel_framework.dart';
import '../../services/user.dart';
-@Expose("/api/auth")
+@Expose('/api/auth')
class AuthController extends Controller {
final AngelAuth auth = new AngelAuth();
- deserializer(String id) async => app.service("api/users").read(id);
+ deserializer(String id) async => app.service('api/users').read(id);
serializer(User user) async => user.id;
/// Attempt to log a user in
verifier(UserService Users) {
return (String username, String password) async {
- List users = await Users.index({"username": username});
+ List users = await Users.index({'username': username});
if (users.isNotEmpty) {
var hash = hashPassword(password);
@@ -36,14 +36,14 @@ class AuthController extends Controller {
await app.configure(auth);
}
- bool loggedIn(RequestContext req) => req.session["userId"] != null;
+ bool loggedIn(RequestContext req) => req.session['userId'] != null;
- @Expose("/login", method: "POST")
+ @Expose('/login', method: 'POST')
login(RequestContext req) async {
// Include log-in logic here...
}
- @Expose("/register", method: "POST")
+ @Expose('/register', method: 'POST')
register(RequestContext req, UserService Users) async {
// And your registration logic...
}
diff --git a/lib/src/routes/routes.dart b/lib/src/routes/routes.dart
index 89eabd92..0f55859e 100644
--- a/lib/src/routes/routes.dart
+++ b/lib/src/routes/routes.dart
@@ -26,7 +26,7 @@ configureAfter(Angel app) async {
// Default error handler
app.onError(
- (e, req, res) async => res.render("error", {"message": e.message}));
+ (e, req, res) async => res.render('error', {'message': e.message}));
}
configureServer(Angel app) async {
diff --git a/lib/src/services/services.dart b/lib/src/services/services.dart
index 8cc3c9b1..85603148 100644
--- a/lib/src/services/services.dart
+++ b/lib/src/services/services.dart
@@ -7,7 +7,7 @@ import 'package:mongo_dart/mongo_dart.dart';
import 'user.dart' as User;
configureServer(Angel app) async {
- Db db = new Db(app.properties["mongo_db"]);
+ Db db = new Db(app.properties['mongo_db']);
await db.open();
await app.configure(User.configureServer(db));
diff --git a/lib/src/services/user.dart b/lib/src/services/user.dart
index d59199d7..25858367 100644
--- a/lib/src/services/user.dart
+++ b/lib/src/services/user.dart
@@ -8,9 +8,9 @@ export '../models/user.dart';
configureServer(Db db) {
return (Angel app) async {
- app.use("/api/users", new UserService(db.collection("users")));
+ app.use('/api/users', new UserService(db.collection('users')));
- HookedService service = app.service("api/users");
+ HookedService service = app.service('api/users');
app.container.singleton(service.inner);
};
}
@@ -32,7 +32,7 @@ class UserService extends Service {
@override
index([Map params]) {
- if (params != null && params.containsKey("provider")) {
+ if (params != null && params.containsKey('provider')) {
// Nobody needs to see the entire user list except for the server.
throw new AngelHttpException.Forbidden();
}
@@ -42,19 +42,19 @@ class UserService extends Service {
@override
create(data, [Map params]) {
- if (params != null && params.containsKey("provider")) {
+ if (params != null && params.containsKey('provider')) {
// Deny creating users to the public - this should be done by the server only.
throw new AngelHttpException.Forbidden();
}
try {
- Validate.isKeyInMap("username", data);
- Validate.isKeyInMap("password", data);
- Validate.isEmail(data["email"]);
- data["password"] = hashPassword(data["password"]);
+ Validate.isKeyInMap('username', data);
+ Validate.isKeyInMap('password', data);
+ Validate.isEmail(data['email']);
+ data['password'] = hashPassword(data['password']);
} catch (e) {
throw new AngelHttpException.BadRequest(
- message: "User must have a username, e-mail address and password.");
+ message: 'User must have a username, e-mail address and password.');
}
return _inner.create(data, params);
diff --git a/pubspec.yaml b/pubspec.yaml
index 5f559df6..bfe71f3b 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -14,6 +14,7 @@ dependencies:
angel_mustache: ^1.0.0-dev
angel_proxy: ^1.0.0-dev
angel_static: ^1.1.0-dev
+ angel_test: ^1.0.0-dev
mailer: ^1.1.0+4
validate: ^1.5.2
dev_dependencies:
diff --git a/test/services/users.dart b/test/services/users.dart
deleted file mode 100644
index c09950f1..00000000
--- a/test/services/users.dart
+++ /dev/null
@@ -1,34 +0,0 @@
-import 'dart:io';
-import 'package:angel/angel.dart';
-import 'package:angel_framework/angel_framework.dart';
-import 'package:http/http.dart';
-import 'package:test/test.dart';
-
-main() async {
- group('services.users', () {
- Angel app;
- Client client = new Client();
- Map headers = {
- HttpHeaders.ACCEPT: ContentType.JSON.mimeType,
- HttpHeaders.CONTENT_TYPE: ContentType.JSON.mimeType
- };
- HttpServer server;
- String url;
-
- setUp(() async {
- Angel app = await createServer();
- server = await app.startServer(InternetAddress.LOOPBACK_IP_V4, 3000);
- url = "http://localhost:3000";
- });
-
- tearDown(() async {
- await server.close(force: true);
- client.close();
- });
-
- test('index users', () async {
- Response response = await client.get("$url/api/users");
- expect(response.statusCode, equals(HttpStatus.OK));
- });
- });
-}
diff --git a/test/services/users_test.dart b/test/services/users_test.dart
new file mode 100644
index 00000000..8cf7cdff
--- /dev/null
+++ b/test/services/users_test.dart
@@ -0,0 +1,27 @@
+import 'dart:io';
+import 'package:angel/angel.dart';
+import 'package:angel_framework/angel_framework.dart';
+import 'package:angel_test/angel_test.dart';
+import 'package:test/test.dart';
+
+main() async {
+ Angel app;
+ TestClient client;
+
+ setUp(() async {
+ app = await createServer();
+ client = await connectTo(app, saveSession: false);
+ });
+
+ tearDown(() async {
+ await client.close();
+ app = null;
+ });
+
+ test('index users', () async {
+ final response = await client.get('/api/users');
+
+ // By default, we locked this away from the Internet...
+ expect(response, hasStatus(HttpStatus.FORBIDDEN));
+ });
+}